From 9c13e8e4ac6ab0707682c4722e33701a4d307892 Mon Sep 17 00:00:00 2001 From: Joseph Birr-Pixton Date: Wed, 10 Apr 2024 16:58:11 +0100 Subject: [PATCH] Implement `SSL_use_PrivateKey` & `SSL_use_certificate` --- rustls-libssl/MATRIX.md | 4 ++-- rustls-libssl/build.rs | 2 ++ rustls-libssl/src/entry.rs | 43 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/rustls-libssl/MATRIX.md b/rustls-libssl/MATRIX.md index 4e4288e..6d9dbf8 100644 --- a/rustls-libssl/MATRIX.md +++ b/rustls-libssl/MATRIX.md @@ -485,14 +485,14 @@ | `SSL_test_functions` [^unit_test] | | | | | `SSL_trace` [^ssl_trace] | | | | | `SSL_up_ref` | | | :white_check_mark: | -| `SSL_use_PrivateKey` | | :white_check_mark: | | +| `SSL_use_PrivateKey` | | :white_check_mark: | :white_check_mark: | | `SSL_use_PrivateKey_ASN1` | | | | | `SSL_use_PrivateKey_file` | | | | | `SSL_use_RSAPrivateKey` [^deprecatedin_3_0] | | | | | `SSL_use_RSAPrivateKey_ASN1` [^deprecatedin_3_0] | | | | | `SSL_use_RSAPrivateKey_file` [^deprecatedin_3_0] | | | | | `SSL_use_cert_and_key` | | | | -| `SSL_use_certificate` | | :white_check_mark: | | +| `SSL_use_certificate` | | :white_check_mark: | :white_check_mark: | | `SSL_use_certificate_ASN1` | | | | | `SSL_use_certificate_chain_file` | | | | | `SSL_use_certificate_file` | | | | diff --git a/rustls-libssl/build.rs b/rustls-libssl/build.rs index 9aa5635..905d4e5 100644 --- a/rustls-libssl/build.rs +++ b/rustls-libssl/build.rs @@ -151,6 +151,8 @@ const ENTRYPOINTS: &[&str] = &[ "SSL_set_SSL_CTX", "SSL_shutdown", "SSL_up_ref", + "SSL_use_certificate", + "SSL_use_PrivateKey", "SSL_want", "SSL_write", "TLS_client_method", diff --git a/rustls-libssl/src/entry.rs b/rustls-libssl/src/entry.rs index 0f640cd..14214ae 100644 --- a/rustls-libssl/src/entry.rs +++ b/rustls-libssl/src/entry.rs @@ -1114,6 +1114,49 @@ entry! { } } +entry! { + pub fn _SSL_use_certificate(ssl: *mut SSL, x: *mut X509) -> c_int { + let ssl = try_clone_arc!(ssl); + + if x.is_null() { + return Error::null_pointer().raise().into(); + } + + let x509 = OwnedX509::new_incref(x); + let ee = CertificateDer::from(x509.der_bytes()); + + match ssl + .lock() + .map_err(|_| Error::cannot_lock()) + .map(|mut ssl| ssl.stage_certificate_end(ee)) + { + Err(e) => e.raise().into(), + Ok(()) => C_INT_SUCCESS, + } + } +} + +entry! { + pub fn _SSL_use_PrivateKey(ssl: *mut SSL, pkey: *mut EVP_PKEY) -> c_int { + let ssl = try_clone_arc!(ssl); + + if pkey.is_null() { + return Error::null_pointer().raise().into(); + } + + let pkey = EvpPkey::new_incref(pkey); + + match ssl + .lock() + .map_err(|_| Error::cannot_lock()) + .and_then(|mut ssl| ssl.commit_private_key(pkey)) + { + Err(e) => e.raise().into(), + Ok(()) => C_INT_SUCCESS, + } + } +} + impl Castable for SSL { type Ownership = OwnershipArc; type RustType = Mutex;