From cba67cf98c37b49e2fa271981ac5bec30b842eb1 Mon Sep 17 00:00:00 2001 From: Brian Chrzanowski Date: Mon, 31 Jul 2023 10:08:49 -0400 Subject: [PATCH 01/17] wrote engine bindings --- openssl-sys/src/handwritten/engine.rs | 222 ++++++++++++++++++++++++++ openssl-sys/src/handwritten/mod.rs | 1 + 2 files changed, 223 insertions(+) create mode 100644 openssl-sys/src/handwritten/engine.rs diff --git a/openssl-sys/src/handwritten/engine.rs b/openssl-sys/src/handwritten/engine.rs new file mode 100644 index 0000000000..bc60550c7d --- /dev/null +++ b/openssl-sys/src/handwritten/engine.rs @@ -0,0 +1,222 @@ +use super::super::*; +use libc::*; + +pub enum ENGINE {} + +pub enum RSA_METHOD {} +pub enum DSA_METHOD {} +pub enum DH_METHOD {} +pub enum RAND_METHOD {} + +pub enum ENGINE_GEN_INT_FUNC_PTR {} +pub enum ENGINE_CIPHERS_PTR {} +pub enum ENGINE_DIGESTS_PTR {} +pub enum ENGINE_CMD_DEFN {} +pub enum ENGINE_CTRL_FUNC_PTR {} +pub enum ENGINE_LOAD_KEY_PTR {} +pub enum UI_METHOD {} + +extern "C" { + // NOTE some of these _may_ need to be mutable... + + pub fn ENGINE_get_first() -> *const ENGINE; + + pub fn ENGINE_get_last() -> *const ENGINE; + + pub fn ENGINE_get_next(e: *const ENGINE) -> *const ENGINE; + + pub fn ENGINE_get_prev(e: *const ENGINE) -> *const ENGINE; + + pub fn ENGINE_add(e: *const ENGINE) -> c_int; + + pub fn ENGINE_remove(e: *const ENGINE) -> c_int; + + pub fn ENGINE_by_id(id: *const c_char) -> *const ENGINE; + + pub fn ENGINE_init(e: *mut ENGINE) -> c_int; + + pub fn ENGINE_finish(e: *mut ENGINE) -> c_int; + + pub fn ENGINE_load_builtin_engines(); + + pub fn ENGINE_get_default_RSA() -> *const ENGINE; + pub fn ENGINE_get_default_DSA() -> *const ENGINE; + pub fn ENGINE_get_default_DH() -> *const ENGINE; + pub fn ENGINE_get_default_RAND() -> *const ENGINE; + pub fn ENGINE_get_cipher_engine(nid: c_int) -> *const ENGINE; + pub fn ENGINE_get_digest_engine(nid: c_int) -> *const ENGINE; + + pub fn ENGINE_set_default_RSA(e: *mut ENGINE) -> c_int; + pub fn ENGINE_set_default_DSA(e: *mut ENGINE) -> c_int; + pub fn ENGINE_set_default_DH(e: *mut ENGINE) -> c_int; + pub fn ENGINE_set_default_RAND(e: *mut ENGINE) -> c_int; + pub fn ENGINE_set_default_ciphers(e: *mut ENGINE) -> c_int; + pub fn ENGINE_set_default_digests(e: *mut ENGINE) -> c_int; + pub fn ENGINE_set_default_string(e: *mut ENGINE, list: *const c_char) -> c_int; + + pub fn ENGINE_set_default(e: *mut ENGINE, flags: c_uint) -> c_int; + + pub fn ENGINE_get_table_flags() -> c_uint; + pub fn ENGINE_set_table_flags(flags: c_uint); + + pub fn ENGINE_register_RSA(e: *mut ENGINE) -> c_int; + pub fn ENGINE_unregister_RSA(e: *mut ENGINE); + pub fn ENGINE_register_all_RSA(); + + pub fn ENGINE_register_DSA(e: *mut ENGINE) -> c_int; + pub fn ENGINE_unregister_DSA(e: *mut ENGINE); + pub fn ENGINE_register_all_DSA(); + + pub fn ENGINE_register_DH(e: *mut ENGINE) -> c_int; + pub fn ENGINE_unregister_DH(e: *mut ENGINE); + pub fn ENGINE_register_all_DH(); + + pub fn ENGINE_register_RAND(e: *mut ENGINE) -> c_int; + pub fn ENGINE_unregister_RAND(e: *mut ENGINE); + pub fn ENGINE_register_all_RAND(); + + pub fn ENGINE_register_ciphers(e: *mut ENGINE) -> c_int; + pub fn ENGINE_unregister_ciphers(e: *mut ENGINE); + pub fn ENGINE_register_all_ciphers(); + + pub fn ENGINE_register_digests(e: *mut ENGINE) -> c_int; + pub fn ENGINE_unregister_digests(e: *mut ENGINE); + pub fn ENGINE_register_all_digests(); + + pub fn ENGINE_register_complete(e: *mut ENGINE) -> c_int; + pub fn ENGINE_register_all_complete(e: *mut ENGINE) -> c_int; + + pub fn ENGINE_ctrl( + e: *mut ENGINE, + cmd: c_int, + i: c_long, + p: *const c_void, + freefunc: i32, + ) -> c_int; + + pub fn ENGINE_cmd_is_executable(e: *mut ENGINE, cmd: c_int) -> c_int; + + pub fn ENGINE_ctrl_cmd( + e: *mut ENGINE, + cmd_name: *const c_char, + i: c_long, + p: *const c_void, + freefunc: i32, + cmd_optional: c_int, + ) -> c_int; + + pub fn ENGINE_ctrl_cmd_string( + e: *mut ENGINE, + cmd_name: *const c_char, + arg: *const c_char, + cmd_optional: c_int, + ) -> c_int; + + pub fn ENGINE_new() -> *mut ENGINE; + + pub fn ENGINE_free(e: *mut ENGINE) -> c_int; + + pub fn ENGINE_up_ref(e: *mut ENGINE) -> c_int; + + pub fn ENGINE_set_id(e: *mut ENGINE, id: *const c_char) -> c_int; + + pub fn ENGINE_set_name(e: *mut ENGINE, name: *const c_char) -> c_int; + + pub fn ENGINE_set_RSA(e: *mut ENGINE, rsa_meth: *const RSA_METHOD) -> c_int; + + pub fn ENGINE_set_DSA(e: *mut ENGINE, DSA_meth: *const DSA_METHOD) -> c_int; + + pub fn ENGINE_set_DH(e: *mut ENGINE, DH_meth: *const DH_METHOD) -> c_int; + + pub fn ENGINE_set_RAND(e: *mut ENGINE, RAND_meth: *const RAND_METHOD) -> c_int; + + // TODO pass a different function pointer for these!!?!?!? + pub fn ENGINE_set_destroy_function( + e: *mut ENGINE, + destroy_f: *const ENGINE_GEN_INT_FUNC_PTR, + ) -> c_int; + + pub fn ENGINE_set_init_function( + e: *mut ENGINE, + init_f: *const ENGINE_GEN_INT_FUNC_PTR, + ) -> c_int; + + pub fn ENGINE_set_finish_function( + e: *mut ENGINE, + finish_f: *const ENGINE_GEN_INT_FUNC_PTR, + ) -> c_int; + + pub fn ENGINE_set_ctrl_function( + e: *mut ENGINE, + ctrl_f: *const ENGINE_GEN_INT_FUNC_PTR, + ) -> c_int; + + pub fn ENGINE_set_load_privkey_function( + e: *mut ENGINE, + loadpriv_f: *const ENGINE_GEN_INT_FUNC_PTR, + ) -> c_int; + + pub fn ENGINE_set_load_pubkey_function( + e: *mut ENGINE, + loadpub_f: *const ENGINE_GEN_INT_FUNC_PTR, + ) -> c_int; + + pub fn ENGINE_set_ciphers(e: *mut ENGINE, f: *const ENGINE_CIPHERS_PTR) -> c_int; + + pub fn ENGINE_set_digests(e: *mut ENGINE, f: *const ENGINE_DIGESTS_PTR) -> c_int; + + pub fn ENGINE_set_cmd_defns(e: *mut ENGINE, defns: *const ENGINE_CMD_DEFN) -> c_int; + + pub fn ENGINE_get_id(e: *const ENGINE) -> *mut c_char; + + pub fn ENGINE_get_name(e: *const ENGINE) -> *mut c_char; + + pub fn ENGINE_get_RSA(e: *const ENGINE) -> *const RSA_METHOD; + + pub fn ENGINE_get_DSA(e: *const ENGINE) -> *const DSA_METHOD; + + pub fn ENGINE_get_DH(e: *const ENGINE) -> *const DH_METHOD; + + pub fn ENGINE_get_RAND(e: *const ENGINE) -> *const RAND_METHOD; + + pub fn ENGINE_get_destroy_function(e: *const ENGINE) -> *const ENGINE_GEN_INT_FUNC_PTR; + + pub fn ENGINE_get_init_function(e: *const ENGINE) -> *const ENGINE_GEN_INT_FUNC_PTR; + + pub fn ENGINE_get_finish_function(e: *const ENGINE) -> *const ENGINE_GEN_INT_FUNC_PTR; + + pub fn ENGINE_get_ctrl_function(e: *const ENGINE) -> *const ENGINE_CTRL_FUNC_PTR; + + pub fn ENGINE_get_load_privkey_function(e: *const ENGINE) -> *const ENGINE_LOAD_KEY_PTR; + + pub fn ENGINE_get_load_pubkey_function(e: *const ENGINE) -> *const ENGINE_LOAD_KEY_PTR; + + pub fn ENGINE_get_ciphers(e: *const ENGINE) -> *const ENGINE_CIPHERS_PTR; + + pub fn ENGINE_get_digests(e: *const ENGINE) -> *const ENGINE_DIGESTS_PTR; + + pub fn ENGINE_get_cipher(e: *const ENGINE, nid: c_int) -> *const EVP_CIPHER; + + pub fn ENGINE_get_digest(e: *const ENGINE, nid: c_int) -> *const EVP_MD; + + pub fn ENGINE_get_flags(e: *const ENGINE) -> c_int; + + pub fn ENGINE_get_cmd_defns(e: *const ENGINE) -> *const ENGINE_CMD_DEFN; + + pub fn ENGINE_load_private_key( + e: *const ENGINE, + key_id: *const c_char, + ui_method: *const UI_METHOD, + callback_data: *const c_void, + ) -> *const EVP_PKEY; + + pub fn ENGINE_load_public_key( + e: *const ENGINE, + key_id: *const c_char, + ui_method: *const UI_METHOD, + callback_data: *const c_void, + ) -> *const EVP_PKEY; + + #[cfg(ossl110)] + pub fn ENGINE_cleanup(); +} diff --git a/openssl-sys/src/handwritten/mod.rs b/openssl-sys/src/handwritten/mod.rs index d3adfa5a13..57a02afc9c 100644 --- a/openssl-sys/src/handwritten/mod.rs +++ b/openssl-sys/src/handwritten/mod.rs @@ -45,6 +45,7 @@ mod crypto; mod dh; mod dsa; mod ec; +mod engine; mod err; mod evp; mod hmac; From 274535c525c6c2a92eb683552564b024171f13a5 Mon Sep 17 00:00:00 2001 From: Brian Chrzanowski Date: Mon, 31 Jul 2023 17:37:40 -0400 Subject: [PATCH 02/17] fixed bindings --- openssl-sys/src/handwritten/engine.rs | 118 ++++++++++++++------------ 1 file changed, 65 insertions(+), 53 deletions(-) diff --git a/openssl-sys/src/handwritten/engine.rs b/openssl-sys/src/handwritten/engine.rs index bc60550c7d..5c0ff69351 100644 --- a/openssl-sys/src/handwritten/engine.rs +++ b/openssl-sys/src/handwritten/engine.rs @@ -1,8 +1,6 @@ use super::super::*; use libc::*; -pub enum ENGINE {} - pub enum RSA_METHOD {} pub enum DSA_METHOD {} pub enum DH_METHOD {} @@ -16,22 +14,34 @@ pub enum ENGINE_CTRL_FUNC_PTR {} pub enum ENGINE_LOAD_KEY_PTR {} pub enum UI_METHOD {} -extern "C" { - // NOTE some of these _may_ need to be mutable... +pub const ENGINE_METHOD_RSA: u32 = 0x0001; +pub const ENGINE_METHOD_DSA: u32 = 0x0002; +pub const ENGINE_METHOD_DH: u32 = 0x0004; +pub const ENGINE_METHOD_RAND: u32 = 0x0008; +pub const ENGINE_METHOD_CIPHERS: u32 = 0x0040; +pub const ENGINE_METHOD_DIGESTS: u32 = 0x0080; +pub const ENGINE_METHOD_PKEY_METHS: u32 = 0x0200; +pub const ENGINE_METHOD_PKEY_ASN1_METHS: u32 = 0x0400; +pub const ENGINE_METHOD_EC: u32 = 0x0800; - pub fn ENGINE_get_first() -> *const ENGINE; +pub const ENGINE_METHOD_ALL: u32 = 0xffff; +pub const ENGINE_METHOD_NONE: u32 = 0xffff; + +#[cfg(ossl110)] +extern "C" { + pub fn ENGINE_get_first() -> *mut ENGINE; - pub fn ENGINE_get_last() -> *const ENGINE; + pub fn ENGINE_get_last() -> *mut ENGINE; - pub fn ENGINE_get_next(e: *const ENGINE) -> *const ENGINE; + pub fn ENGINE_get_next(e: *mut ENGINE) -> *mut ENGINE; - pub fn ENGINE_get_prev(e: *const ENGINE) -> *const ENGINE; + pub fn ENGINE_get_prev(e: *mut ENGINE) -> *mut ENGINE; - pub fn ENGINE_add(e: *const ENGINE) -> c_int; + pub fn ENGINE_add(e: *mut ENGINE) -> c_int; - pub fn ENGINE_remove(e: *const ENGINE) -> c_int; + pub fn ENGINE_remove(e: *mut ENGINE) -> c_int; - pub fn ENGINE_by_id(id: *const c_char) -> *const ENGINE; + pub fn ENGINE_by_id(id: *const c_char) -> *mut ENGINE; pub fn ENGINE_init(e: *mut ENGINE) -> c_int; @@ -39,12 +49,12 @@ extern "C" { pub fn ENGINE_load_builtin_engines(); - pub fn ENGINE_get_default_RSA() -> *const ENGINE; - pub fn ENGINE_get_default_DSA() -> *const ENGINE; - pub fn ENGINE_get_default_DH() -> *const ENGINE; - pub fn ENGINE_get_default_RAND() -> *const ENGINE; - pub fn ENGINE_get_cipher_engine(nid: c_int) -> *const ENGINE; - pub fn ENGINE_get_digest_engine(nid: c_int) -> *const ENGINE; + pub fn ENGINE_get_default_RSA() -> *mut ENGINE; + pub fn ENGINE_get_default_DSA() -> *mut ENGINE; + pub fn ENGINE_get_default_DH() -> *mut ENGINE; + pub fn ENGINE_get_default_RAND() -> *mut ENGINE; + pub fn ENGINE_get_cipher_engine(nid: c_int) -> *mut ENGINE; + pub fn ENGINE_get_digest_engine(nid: c_int) -> *mut ENGINE; pub fn ENGINE_set_default_RSA(e: *mut ENGINE) -> c_int; pub fn ENGINE_set_default_DSA(e: *mut ENGINE) -> c_int; @@ -84,14 +94,14 @@ extern "C" { pub fn ENGINE_register_all_digests(); pub fn ENGINE_register_complete(e: *mut ENGINE) -> c_int; - pub fn ENGINE_register_all_complete(e: *mut ENGINE) -> c_int; + pub fn ENGINE_register_all_complete() -> c_int; pub fn ENGINE_ctrl( e: *mut ENGINE, cmd: c_int, i: c_long, - p: *const c_void, - freefunc: i32, + p: *mut c_void, + f: extern "C" fn (), ) -> c_int; pub fn ENGINE_cmd_is_executable(e: *mut ENGINE, cmd: c_int) -> c_int; @@ -100,8 +110,8 @@ extern "C" { e: *mut ENGINE, cmd_name: *const c_char, i: c_long, - p: *const c_void, - freefunc: i32, + p: *mut c_void, + f: extern "C" fn (), cmd_optional: c_int, ) -> c_int; @@ -130,46 +140,45 @@ extern "C" { pub fn ENGINE_set_RAND(e: *mut ENGINE, RAND_meth: *const RAND_METHOD) -> c_int; - // TODO pass a different function pointer for these!!?!?!? pub fn ENGINE_set_destroy_function( e: *mut ENGINE, - destroy_f: *const ENGINE_GEN_INT_FUNC_PTR, + destroy_f: extern "C" fn (*mut ENGINE) -> c_int, ) -> c_int; pub fn ENGINE_set_init_function( e: *mut ENGINE, - init_f: *const ENGINE_GEN_INT_FUNC_PTR, + init_f: extern "C" fn (*mut ENGINE) -> c_int, ) -> c_int; pub fn ENGINE_set_finish_function( e: *mut ENGINE, - finish_f: *const ENGINE_GEN_INT_FUNC_PTR, + finish_f: extern "C" fn (*mut ENGINE) -> c_int, ) -> c_int; pub fn ENGINE_set_ctrl_function( e: *mut ENGINE, - ctrl_f: *const ENGINE_GEN_INT_FUNC_PTR, + ctrl_f: extern "C" fn (*mut ENGINE, c_int, c_long, *mut c_void, extern "C" fn ()) -> c_int, ) -> c_int; pub fn ENGINE_set_load_privkey_function( e: *mut ENGINE, - loadpriv_f: *const ENGINE_GEN_INT_FUNC_PTR, + loadpriv_f: extern "C" fn (*mut ENGINE, *const c_char, *mut UI_METHOD, *mut c_void) -> *mut EVP_PKEY, ) -> c_int; pub fn ENGINE_set_load_pubkey_function( e: *mut ENGINE, - loadpub_f: *const ENGINE_GEN_INT_FUNC_PTR, + loadpub_f: unsafe extern "C" fn (*mut ENGINE, *const c_char, *mut UI_METHOD, *mut c_void) -> *mut EVP_PKEY, ) -> c_int; - pub fn ENGINE_set_ciphers(e: *mut ENGINE, f: *const ENGINE_CIPHERS_PTR) -> c_int; + pub fn ENGINE_set_ciphers(e: *mut ENGINE, f: ENGINE_CIPHERS_PTR) -> c_int; - pub fn ENGINE_set_digests(e: *mut ENGINE, f: *const ENGINE_DIGESTS_PTR) -> c_int; + pub fn ENGINE_set_digests(e: *mut ENGINE, f: ENGINE_DIGESTS_PTR) -> c_int; pub fn ENGINE_set_cmd_defns(e: *mut ENGINE, defns: *const ENGINE_CMD_DEFN) -> c_int; - pub fn ENGINE_get_id(e: *const ENGINE) -> *mut c_char; + pub fn ENGINE_get_id(e: *const ENGINE) -> *const c_char; - pub fn ENGINE_get_name(e: *const ENGINE) -> *mut c_char; + pub fn ENGINE_get_name(e: *const ENGINE) -> *const c_char; pub fn ENGINE_get_RSA(e: *const ENGINE) -> *const RSA_METHOD; @@ -179,44 +188,47 @@ extern "C" { pub fn ENGINE_get_RAND(e: *const ENGINE) -> *const RAND_METHOD; - pub fn ENGINE_get_destroy_function(e: *const ENGINE) -> *const ENGINE_GEN_INT_FUNC_PTR; + pub fn ENGINE_get_destroy_function(e: *const ENGINE) -> ENGINE_GEN_INT_FUNC_PTR; - pub fn ENGINE_get_init_function(e: *const ENGINE) -> *const ENGINE_GEN_INT_FUNC_PTR; + pub fn ENGINE_get_init_function(e: *const ENGINE) -> ENGINE_GEN_INT_FUNC_PTR; - pub fn ENGINE_get_finish_function(e: *const ENGINE) -> *const ENGINE_GEN_INT_FUNC_PTR; + pub fn ENGINE_get_finish_function(e: *const ENGINE) -> ENGINE_GEN_INT_FUNC_PTR; - pub fn ENGINE_get_ctrl_function(e: *const ENGINE) -> *const ENGINE_CTRL_FUNC_PTR; + pub fn ENGINE_get_ctrl_function(e: *const ENGINE) -> ENGINE_CTRL_FUNC_PTR; - pub fn ENGINE_get_load_privkey_function(e: *const ENGINE) -> *const ENGINE_LOAD_KEY_PTR; + pub fn ENGINE_get_load_privkey_function(e: *const ENGINE) -> ENGINE_LOAD_KEY_PTR; - pub fn ENGINE_get_load_pubkey_function(e: *const ENGINE) -> *const ENGINE_LOAD_KEY_PTR; + pub fn ENGINE_get_load_pubkey_function(e: *const ENGINE) -> ENGINE_LOAD_KEY_PTR; - pub fn ENGINE_get_ciphers(e: *const ENGINE) -> *const ENGINE_CIPHERS_PTR; + pub fn ENGINE_get_ciphers(e: *const ENGINE) -> ENGINE_CIPHERS_PTR; - pub fn ENGINE_get_digests(e: *const ENGINE) -> *const ENGINE_DIGESTS_PTR; + pub fn ENGINE_get_digests(e: *const ENGINE) -> ENGINE_DIGESTS_PTR; - pub fn ENGINE_get_cipher(e: *const ENGINE, nid: c_int) -> *const EVP_CIPHER; + pub fn ENGINE_get_cipher(e: *mut ENGINE, nid: c_int) -> *const EVP_CIPHER; - pub fn ENGINE_get_digest(e: *const ENGINE, nid: c_int) -> *const EVP_MD; + pub fn ENGINE_get_digest(e: *mut ENGINE, nid: c_int) -> *const EVP_MD; pub fn ENGINE_get_flags(e: *const ENGINE) -> c_int; pub fn ENGINE_get_cmd_defns(e: *const ENGINE) -> *const ENGINE_CMD_DEFN; pub fn ENGINE_load_private_key( - e: *const ENGINE, + e: *mut ENGINE, key_id: *const c_char, - ui_method: *const UI_METHOD, - callback_data: *const c_void, - ) -> *const EVP_PKEY; + ui_method: *mut UI_METHOD, + callback_data: *mut c_void, + ) -> *mut EVP_PKEY; pub fn ENGINE_load_public_key( - e: *const ENGINE, + e: *mut ENGINE, key_id: *const c_char, - ui_method: *const UI_METHOD, - callback_data: *const c_void, - ) -> *const EVP_PKEY; + ui_method: *mut UI_METHOD, + callback_data: *mut c_void, + ) -> *mut EVP_PKEY; - #[cfg(ossl110)] - pub fn ENGINE_cleanup(); } + +// extern "C" { +// #[cfg(not(any(ossl100)))] +// pub fn ENGINE_cleanup(); +// } From 7b5dd5c3f2c37e6d0472403d3f1e379295866196 Mon Sep 17 00:00:00 2001 From: Brian Chrzanowski Date: Mon, 31 Jul 2023 17:37:55 -0400 Subject: [PATCH 03/17] exported engine bindings for openssl 1.1.* --- openssl-sys/src/handwritten/mod.rs | 2 ++ systest/build.rs | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/openssl-sys/src/handwritten/mod.rs b/openssl-sys/src/handwritten/mod.rs index 57a02afc9c..d5ba8858d2 100644 --- a/openssl-sys/src/handwritten/mod.rs +++ b/openssl-sys/src/handwritten/mod.rs @@ -9,6 +9,7 @@ pub use self::crypto::*; pub use self::dh::*; pub use self::dsa::*; pub use self::ec::*; +pub use self::engine::*; pub use self::err::*; pub use self::evp::*; pub use self::hmac::*; @@ -45,6 +46,7 @@ mod crypto; mod dh; mod dsa; mod ec; +#[cfg(all(ossl110))] mod engine; mod err; mod evp; diff --git a/systest/build.rs b/systest/build.rs index 53407eafad..f4cc9dedfe 100644 --- a/systest/build.rs +++ b/systest/build.rs @@ -79,6 +79,10 @@ fn main() { cfg.header("openssl/kdf.h"); } + if 0x10100000 <= version && version < 0x30000000 { + cfg.header("openssl/engine.h"); + } + if version >= 0x30000000 { cfg.header("openssl/provider.h"); } From aa5749a84fd2d2cc12440aecb4b33762857e1d39 Mon Sep 17 00:00:00 2001 From: Brian Chrzanowski Date: Tue, 1 Aug 2023 17:53:02 -0400 Subject: [PATCH 04/17] wrote much of the Rust engine interface - subject to change --- openssl/src/engine.rs | 768 ++++++++++++++++++++++++++++++++++++++++++ openssl/src/lib.rs | 1 + 2 files changed, 769 insertions(+) create mode 100644 openssl/src/engine.rs diff --git a/openssl/src/engine.rs b/openssl/src/engine.rs new file mode 100644 index 0000000000..352d83e150 --- /dev/null +++ b/openssl/src/engine.rs @@ -0,0 +1,768 @@ +use crate::error::ErrorStack; +use crate::pkey::{HasPrivate, HasPublic, PKeyRef}; +use crate::pkey_ctx::PkeyCtxRef; +use crate::{cvt, cvt_n, cvt_p}; +use cfg_if::cfg_if; +use foreign_types::{ForeignType, ForeignTypeRef}; +use openssl_macros::corresponds; +use std::convert::TryFrom; +use std::ptr; +use std::ffi::{CString, c_int, c_uint, c_void}; +use libc::{strlen}; + +struct Engine(*mut ffi::ENGINE); + +impl Engine { + /// Creates a new Engine. + #[corresponds(ENGINE_new)] + #[inline] + pub fn new() -> Result { + ffi::init(); + unsafe { + let ptr = cvt_p(ffi::ENGINE_new())?; + Ok(Engine::from_ptr(ptr)) + } + } + + pub fn as_ptr(&self) -> *mut ffi::ENGINE { + self.0 + } + + pub fn from_ptr(ptr: *mut ffi::ENGINE) -> Engine { + Engine(ptr) + } + + /// Returns the "first" ENGINE type available. + #[corresponds(ENGINE_get_first)] + #[inline] + pub fn get_first() -> Result { + ffi::init(); + unsafe { + let ptr = cvt_p(ffi::ENGINE_get_first())?; + Ok(Engine::from_ptr(ptr)) + } + } + + /// Returns the "last" ENGINE type available. + #[corresponds(ENGINE_get_last)] + #[inline] + pub fn get_last() -> Result { + ffi::init(); + unsafe { + let ptr = cvt_p(ffi::ENGINE_get_last())?; + Ok(Engine::from_ptr(ptr)) + } + } + + /// Returns the "next" ENGINE type available, after the passed in ENGINE. + #[corresponds(ENGINE_get_next)] + #[inline] + pub fn get_next(e: Engine) -> Result { + unsafe { + let ptr = cvt_p(ffi::ENGINE_get_next(e.as_ptr()))?; + Ok(Engine::from_ptr(ptr)) + } + } + + /// Returns the "previous" ENGINE type available, before the passed in ENGINE. + #[corresponds(ENGINE_get_prev)] + #[inline] + pub fn get_prev(e: Engine) -> Result { + unsafe { + let ptr = cvt_p(ffi::ENGINE_get_prev(e.as_ptr()))?; + Ok(Engine::from_ptr(ptr)) + } + } + + /// Adds the engine to OpenSSL's internal engine list. + #[corresponds(ENGINE_add)] + #[inline] + pub fn add(e: Engine) -> Result<(), ErrorStack> { + unsafe { + cvt(ffi::ENGINE_add(e.as_ptr()))?; + } + Ok(()) + } + + /// Removes the engine from OpenSSL's internal engine list. + #[corresponds(ENGINE_remove)] + #[inline] + pub fn remove(e: Engine) -> Result<(), ErrorStack> { + unsafe { + cvt(ffi::ENGINE_remove(e.as_ptr()))?; + } + Ok(()) + } + + /// Returns an engine with the passed in `id`. + #[corresponds(ENGINE_by_id)] + #[inline] + pub fn by_id(id: &str) -> Result { + let id = CString::new(id).unwrap(); + unsafe { + let ptr = cvt_p(ffi::ENGINE_by_id(id.as_ptr()))?; + Ok(Engine::from_ptr(ptr)) + } + } + + /// Remove all references to the passed in engine. + #[corresponds(ENGINE_finish)] + #[inline] + pub fn finish(e: Engine) -> Result<(), ErrorStack> { + unsafe { + cvt(ffi::ENGINE_finish(e.as_ptr()))?; + } + Ok(()) + } + + /// Loads the builtin engines. + #[corresponds(ENGINE_load_builtin_engines)] + #[inline] + pub fn load_builtin_engines() { + unsafe { + ffi::ENGINE_load_builtin_engines(); + } + } + + /// Returns the default engine for the "RSA" algorithm. + #[corresponds(ENGINE_get_default_RSA)] + #[inline] + pub fn get_default_rsa() -> Result { + unsafe { + let ptr = cvt_p(ffi::ENGINE_get_default_RSA())?; + Ok(Engine::from_ptr(ptr)) + } + } + + /// Returns the default engine for the "DSA" algorithm. + #[corresponds(ENGINE_get_default_DSA)] + #[inline] + pub fn get_default_dsa() -> Result { + unsafe { + let ptr = cvt_p(ffi::ENGINE_get_default_DSA())?; + Ok(Engine::from_ptr(ptr)) + } + } + + /// Returns the default engine for the "DH" algorithm. + #[corresponds(ENGINE_get_default_DH)] + #[inline] + pub fn get_default_dh() -> Result { + unsafe { + let ptr = cvt_p(ffi::ENGINE_get_default_DH())?; + Ok(Engine::from_ptr(ptr)) + } + } + + /// Returns the default engine for the "RAND" algorithm. + #[corresponds(ENGINE_get_default_RAND)] + #[inline] + pub fn get_default_rand() -> Result { + unsafe { + let ptr = cvt_p(ffi::ENGINE_get_default_RAND())?; + Ok(Engine::from_ptr(ptr)) + } + } + + /// Returns the default cipher engine. + #[corresponds(ENGINE_get_default_cipher_engine)] + #[inline] + pub fn get_cipher_engine(nid: i32) -> Result { + unsafe { + let ptr = cvt_p(ffi::ENGINE_get_cipher_engine(c_int::from(nid)))?; + Ok(Engine::from_ptr(ptr)) + } + } + + /// Returns the default digest engine. + #[corresponds(ENGINE_get_digest_engine)] + #[inline] + pub fn get_digest_engine(nid: i32) -> Result { + unsafe { + let ptr = cvt_p(ffi::ENGINE_get_digest_engine(c_int::from(nid)))?; + Ok(Engine::from_ptr(ptr)) + } + } + + /// Sets the default RSA engine. + #[corresponds(ENGINE_set_default_RSA)] + #[inline] + pub fn set_default_rsa(e: Engine) -> Result<(), ErrorStack> { + unsafe { + cvt(ffi::ENGINE_set_default_RSA(e.as_ptr()))?; + } + Ok(()) + } + + /// Sets the default DSA engine. + #[corresponds(ENGINE_set_default_DSA)] + #[inline] + pub fn set_default_dsa(e: Engine) -> Result<(), ErrorStack> { + unsafe { + cvt(ffi::ENGINE_set_default_DSA(e.as_ptr()))?; + } + Ok(()) + } + + /// Sets the default DH engine. + #[corresponds(ENGINE_set_default_DH)] + #[inline] + pub fn set_default_dh(e: Engine) -> Result<(), ErrorStack> { + unsafe { + cvt(ffi::ENGINE_set_default_DH(e.as_ptr()))?; + } + Ok(()) + } + + /// Sets the default RAND engine. + #[corresponds(ENGINE_set_default_RAND)] + #[inline] + pub fn set_default_rand(e: Engine) -> Result<(), ErrorStack> { + unsafe { + cvt(ffi::ENGINE_set_default_RAND(e.as_ptr()))?; + } + Ok(()) + } + + /// Sets the default ciphers engine. + #[corresponds(ENGINE_set_default_ciphers)] + #[inline] + pub fn set_default_ciphers(e: Engine) -> Result<(), ErrorStack> { + unsafe { + cvt(ffi::ENGINE_set_default_ciphers(e.as_ptr()))?; + } + Ok(()) + } + + /// Sets the default digests engine. + #[corresponds(ENGINE_set_default_digests)] + #[inline] + pub fn set_default_digests(e: Engine) -> Result<(), ErrorStack> { + unsafe { + cvt(ffi::ENGINE_set_default_digests(e.as_ptr()))?; + } + Ok(()) + } + + /// Sets the default string for the engine. + #[corresponds(ENGINE_set_default_string)] + #[inline] + pub fn set_default_string(e: Engine, list: &str) -> Result<(), ErrorStack> { + let list = CString::new(list).unwrap(); + unsafe { + cvt(ffi::ENGINE_set_default_string(e.as_ptr(), list.as_ptr()))?; + } + Ok(()) + } + + /// Sets the default engine. + #[corresponds(ENGINE_set_default)] + #[inline] + pub fn set_default(e: Engine, flags: u32) -> Result<(), ErrorStack> { + unsafe { + cvt(ffi::ENGINE_set_default(e.as_ptr(), c_uint::from(flags)))?; + } + Ok(()) + } + + /// Returns the (global?) engine table flags. + #[corresponds(ENGINE_get_table_flags)] + #[inline] + pub fn get_table_flags() -> u32 { + unsafe { + let rc = ffi::ENGINE_get_table_flags(); + return u32::from(rc); + } + } + + /// Sets the (global?) engine table flags. + #[corresponds(ENGINE_set_table_flags)] + #[inline] + pub fn set_table_flags(flags: u32) { + unsafe { + ffi::ENGINE_set_table_flags(c_uint::from(flags)); + } + } + + /// Registers the input engine as the RSA engine. + #[corresponds(ENGINE_register_RSA)] + #[inline] + pub fn register_rsa(e: Engine) -> Result<(), ErrorStack> { + unsafe { + cvt(ffi::ENGINE_register_RSA(e.as_ptr()))?; + } + Ok(()) + } + + /// Unregisters the input engine as the RSA engine. + #[corresponds(ENGINE_unregister_RSA)] + #[inline] + pub fn unregister_rsa(e: Engine) { + unsafe { + ffi::ENGINE_unregister_RSA(e.as_ptr()); + } + } + + /// Registers all of the engines as RSA. + #[corresponds(ENGINE_register_all_RSA)] + #[inline] + pub fn register_all_rsa(e: Engine) { + unsafe { + ffi::ENGINE_register_all_RSA(); + } + } + + /// Registers the input engine as the DSA engine. + #[corresponds(ENGINE_register_DSA)] + #[inline] + pub fn register_dsa(e: Engine) -> Result<(), ErrorStack> { + unsafe { + cvt(ffi::ENGINE_register_DSA(e.as_ptr()))?; + } + Ok(()) + } + + /// Unregisters the input engine as the DSA engine. + #[corresponds(ENGINE_unregister_DSA)] + #[inline] + pub fn unregister_dsa(e: Engine) { + unsafe { + ffi::ENGINE_unregister_DSA(e.as_ptr()); + } + } + + /// Registers all of the engines as DSA. + #[corresponds(ENGINE_unregister_DSA)] + #[inline] + pub fn register_all_dsa() { + unsafe { + ffi::ENGINE_register_all_DSA(); + } + } + + /// Registers the input engine as the DH engine. + #[corresponds(ENGINE_register_DH)] + #[inline] + pub fn register_dh(e: Engine) -> Result<(), ErrorStack> { + unsafe { + cvt(ffi::ENGINE_register_DH(e.as_ptr()))?; + } + Ok(()) + } + + /// Unregisters the input engine as the DH engine. + #[corresponds(ENGINE_unregister_DH)] + #[inline] + pub fn unregister_dh(e: Engine) { + unsafe { + ffi::ENGINE_unregister_DH(e.as_ptr()); + } + } + + /// Registers all of the engines as DH. + #[corresponds(ENGINE_unregister_DH)] + #[inline] + pub fn register_all_dh() { + unsafe { + ffi::ENGINE_register_all_DH(); + } + } + + /// Registers the input engine as the RAND engine. + #[corresponds(ENGINE_register_RAND)] + #[inline] + pub fn register_rand(e: Engine) -> Result<(), ErrorStack> { + unsafe { + cvt(ffi::ENGINE_register_RAND(e.as_ptr()))?; + } + Ok(()) + } + + /// Unregisters the input engine as the RAND engine. + #[corresponds(ENGINE_unregister_RAND)] + #[inline] + pub fn unregister_rand(e: Engine) { + unsafe { + ffi::ENGINE_unregister_RAND(e.as_ptr()); + } + } + + /// Registers all of the engines as RAND. + #[corresponds(ENGINE_unregister_RAND)] + #[inline] + pub fn register_all_rand() { + unsafe { + ffi::ENGINE_register_all_RAND(); + } + } + + /// Registers ciphers from the input engine. + #[corresponds(ENGINE_register_ciphers)] + #[inline] + pub fn register_ciphers(e: Engine) -> Result<(), ErrorStack> { + unsafe { + cvt(ffi::ENGINE_register_ciphers(e.as_ptr()))?; + } + Ok(()) + } + + /// Unregisters the ciphers from the input engine. + #[corresponds(ENGINE_unregister_ciphers)] + #[inline] + pub fn unregister_ciphers(e: Engine) { + unsafe { + ffi::ENGINE_unregister_ciphers(e.as_ptr()); + } + } + + /// Registers all ciphers from the input engine. + #[corresponds(ENGINE_unregister_ciphers)] + #[inline] + pub fn register_all_ciphers() { + unsafe { + ffi::ENGINE_register_all_ciphers(); + } + } + + /// Registers digests from the input engine. + #[corresponds(ENGINE_register_digests)] + #[inline] + pub fn register_digests(e: Engine) -> Result<(), ErrorStack> { + unsafe { + cvt(ffi::ENGINE_register_digests(e.as_ptr()))?; + } + Ok(()) + } + + /// Unregisters the digests from the input engine. + #[corresponds(ENGINE_unregister_digests)] + #[inline] + pub fn unregister_digests(e: Engine) { + unsafe { + ffi::ENGINE_unregister_digests(e.as_ptr()); + } + } + + /// Registers all digests from the input engine. + #[corresponds(ENGINE_unregister_digests)] + #[inline] + pub fn register_all_digests() { + unsafe { + ffi::ENGINE_register_all_digests(); + } + } + + pub fn register_complete(e: Engine) -> Result<(), ErrorStack> { + unsafe { + cvt(ffi::ENGINE_register_complete(e.as_ptr()))?; + } + Ok(()) + } + + pub fn register_all_complete() -> Result<(), ErrorStack> { + unsafe { + cvt(ffi::ENGINE_register_all_complete())?; + } + Ok(()) + } + + pub fn ctrl(e: Engine, cmd: i32, i: i64, p: *mut c_void, f: extern "C" fn ()) -> Result<(), ErrorStack> { + todo!(); + } + + pub fn cmd_is_executable(e: Engine, cmd: i32) -> Result<(), ErrorStack> { + unsafe { + cvt(ffi::ENGINE_cmd_is_executable(e.as_ptr(), c_int::from(cmd)))?; + } + Ok(()) + } + + pub fn ctrl_cmd(e: Engine, cmd: &str, arg: &str, param: i32) -> Result<(), ErrorStack> { + todo!(); + } + + pub fn ctrl_cmd_string(e: Engine, cmd: &str, arg: &str, optional: i32) -> Result<(), ErrorStack> { + todo!(); + } + + pub fn up_ref(e: Engine) -> Result<(), ErrorStack> { + unsafe { + cvt(ffi::ENGINE_up_ref(e.as_ptr()))?; + } + Ok(()) + } + + /// Sets the ID on the engine. + #[corresponds(ENGINE_set_id)] + #[inline] + pub fn set_id(e: Engine, id: &str) -> Result<(), ErrorStack> { + let id = CString::new(id).unwrap(); + unsafe { + cvt(ffi::ENGINE_set_id(e.as_ptr(), id.as_ptr()))?; + } + Ok(()) + } + + /// Sets the name on the engine. + #[corresponds(ENGINE_set_name)] + #[inline] + pub fn set_name(e: Engine, name: &str) -> Result<(), ErrorStack> { + let name = CString::new(name).unwrap(); + unsafe { + cvt(ffi::ENGINE_set_name(e.as_ptr(), name.as_ptr()))?; + } + Ok(()) + } + + /// Sets the RSA method on the engine. + #[corresponds(ENGINE_set_RSA)] + #[inline] + pub fn set_rsa(e: Engine) -> Result<(), ErrorStack> { + todo!(); + } + + /// Sets the DSA method on the engine. + #[corresponds(ENGINE_set_DSA)] + #[inline] + pub fn set_dsa(e: Engine) -> Result<(), ErrorStack> { + todo!(); + } + + /// Sets the DH method on the engine. + #[corresponds(ENGINE_set_DH)] + #[inline] + pub fn set_dh(e: Engine) -> Result<(), ErrorStack> { + todo!(); + } + + /// Sets the RAND method on the engine. + #[corresponds(ENGINE_set_RAND)] + #[inline] + pub fn set_rand(e: Engine) -> Result<(), ErrorStack> { + todo!(); + } + + /// Sets the destroy function on the engine. + #[corresponds(ENGINE_set_destroy_function)] + #[inline] + pub fn set_destroy_function(e: Engine) -> Result<(), ErrorStack> { + todo!(); + } + + /// Sets the init function on the engine. + #[corresponds(ENGINE_set_init_function)] + #[inline] + pub fn set_init_function (e: Engine) -> Result<(), ErrorStack> { + todo!(); + } + + /// Sets the finish function on the engine. + #[corresponds(ENGINE_set_finish_function)] + #[inline] + pub fn set_finish_function (e: Engine) -> Result<(), ErrorStack> { + todo!(); + } + + /// Sets the ctrl function on the engine. + #[corresponds(ENGINE_set_ctrl_function)] + #[inline] + pub fn set_ctrl_function (e: Engine) -> Result<(), ErrorStack> { + todo!(); + } + + /// Sets the `load_privkey` function on the engine. + #[corresponds(ENGINE_set_load_privkey_function)] + #[inline] + pub fn set_load_privkey_function (e: Engine) -> Result<(), ErrorStack> { + todo!(); + } + + /// Sets the `load_pubkey` function on the engine. + #[corresponds(ENGINE_set_load_pubkey_function)] + #[inline] + pub fn set_load_pubkey_function (e: Engine) -> Result<(), ErrorStack> { + todo!(); + } + + /// Sets the ciphers pointer on the engine. + #[corresponds(ENGINE_set_ciphers)] + #[inline] + pub fn set_ciphers(e: Engine) -> Result<(), ErrorStack> { + todo!(); + } + + /// Sets the digests pointer on the engine. + #[corresponds(ENGINE_set_digests)] + #[inline] + pub fn set_digests(e: Engine) -> Result<(), ErrorStack> { + todo!(); + } + + /// Sets command definitions on the engine. + #[corresponds(ENGINE_set_cmd_defns)] + #[inline] + pub fn set_cmd_defns(e: Engine) -> Result<(), ErrorStack> { + todo!(); + } + + /// Returns the engine's ID. + #[corresponds(ENGINE_get_id)] + #[inline] + pub fn get_id(e: Engine) -> Result { + unsafe { + let ptr = ffi::ENGINE_get_id(e.as_ptr()); + let slice = std::slice::from_raw_parts(ptr as *const u8, strlen(ptr) + 1 as usize); + Ok(std::str::from_utf8_unchecked(slice).to_string()) + } + } + + /// Returns the engine's name. + #[corresponds(ENGINE_get_name)] + #[inline] + pub fn get_name(e: Engine) -> Result { + unsafe { + let ptr = ffi::ENGINE_get_name(e.as_ptr()); + let slice = std::slice::from_raw_parts(ptr as *const u8, strlen(ptr) + 1 as usize); + Ok(std::str::from_utf8_unchecked(slice).to_string()) + } + } + + /// Returns the engine's currently set RSA method. + #[corresponds(ENGINE_get_RSA)] + #[inline] + pub fn get_rsa(e: Engine) -> Result<(), ErrorStack> { + todo!(); + } + + /// Returns the engine's currently set DSA method. + #[corresponds(ENGINE_get_DSA)] + #[inline] + pub fn get_dsa(e: Engine) -> Result<(), ErrorStack> { + todo!(); + } + + /// Returns the engine's currently set DH method. + #[corresponds(ENGINE_get_DH)] + #[inline] + pub fn get_dh(e: Engine) -> Result<(), ErrorStack> { + todo!(); + } + + /// Returns the engine's currently set RAND method. + #[corresponds(ENGINE_get_RAND)] + #[inline] + pub fn get_rand(e: Engine) -> Result<(), ErrorStack> { + todo!(); + } + + /// Returns the engine's currently set destroy function. + #[corresponds(ENGINE_get_destroy_function)] + #[inline] + pub fn get_destroy_function(e: Engine) -> Result<(), ErrorStack> { + todo!(); + } + + /// Returns the engine's currently set init function. + #[corresponds(ENGINE_get_init_function)] + #[inline] + pub fn get_init_function(e: Engine) -> Result<(), ErrorStack> { + todo!(); + } + + /// Returns the engine's currently set finish function. + #[corresponds(ENGINE_get_finish_function)] + #[inline] + pub fn get_finish_function(e: Engine) -> Result<(), ErrorStack> { + todo!(); + } + + /// Returns the engine's currently set ctrl function. + #[corresponds(ENGINE_get_ctrl_function)] + #[inline] + pub fn get_ctrl_function(e: Engine) -> Result<(), ErrorStack> { + todo!(); + } + + /// Returns the engine's currently set `load_privkey_function` function. + #[corresponds(ENGINE_get_load_privkey_function)] + #[inline] + pub fn get_load_privkey_function(e: Engine) -> Result<(), ErrorStack> { + todo!(); + } + + /// Returns the engine's currently set `load_pubkey_function` function. + #[corresponds(ENGINE_get_load_pubkey_function)] + #[inline] + pub fn get_load_pubkey_function(e: Engine) -> Result<(), ErrorStack> { + todo!(); + } + + /// Returns the engine's currently set ciphers. + #[corresponds(ENGINE_get_ciphers)] + #[inline] + pub fn get_ciphers(e: Engine) -> Result<(), ErrorStack> { + todo!(); + } + + /// Returns the engine's current set digests. + #[corresponds(ENGINE_get_digests)] + #[inline] + pub fn get_digests(e: Engine) -> Result<(), ErrorStack> { + todo!(); + } + + /// Returns the cipher for the passed `nid` value. + #[corresponds(ENGINE_get_cipher)] + #[inline] + pub fn get_cipher(e: Engine, nid: i32) -> Result<(), ErrorStack> { + todo!(); + } + + /// Returns the digest for the passed `nid` value. + #[corresponds(ENGINE_get_digest)] + #[inline] + pub fn get_digest(e: Engine, nid: i32) -> Result<(), ErrorStack> { + todo!(); + } + + /// Returns the engine's flags. + #[corresponds(ENGINE_get_flags)] + #[inline] + pub fn get_flags(e: Engine) -> i32 { + // TODO should these flags be a different type? + unsafe { + ffi::ENGINE_get_flags(e.as_ptr()) + } + } + + /// Returns the command definitions. + #[corresponds(ENGINE_get_cmd_defns)] + #[inline] + pub fn get_cmd_defns(e: Engine) -> Result<(), ErrorStack> { + todo!(); + } + + /// Load a private key into the engine. + #[corresponds(ENGINE_load_private_key)] + #[inline] + pub fn load_private_key(e: Engine) -> Result<(), ErrorStack> { + todo!(); + } + + /// Load a public key into the engine. + #[corresponds(ENGINE_load_public_key)] + #[inline] + pub fn load_public_key(e: Engine) -> Result<(), ErrorStack> { + todo!(); + } + +} + +impl Drop for Engine { + #[inline] + fn drop(&mut self) { + unsafe { + ffi::ENGINE_free(self.as_ptr()); + } + } +} diff --git a/openssl/src/lib.rs b/openssl/src/lib.rs index fe29d02293..64d921b386 100644 --- a/openssl/src/lib.rs +++ b/openssl/src/lib.rs @@ -149,6 +149,7 @@ pub mod dsa; pub mod ec; pub mod ecdsa; pub mod encrypt; +pub mod engine; #[cfg(not(boringssl))] pub mod envelope; pub mod error; From 5711c0fb6293f21a9ae0ae6e2c9833328f4d15b4 Mon Sep 17 00:00:00 2001 From: Brian Chrzanowski Date: Tue, 1 Aug 2023 18:52:38 -0400 Subject: [PATCH 05/17] began swapping from functions to methods - added an iterating test --- openssl/src/engine.rs | 97 +++++++++++++++++++++++++++++++++---------- 1 file changed, 75 insertions(+), 22 deletions(-) diff --git a/openssl/src/engine.rs b/openssl/src/engine.rs index 352d83e150..8376f4f6d7 100644 --- a/openssl/src/engine.rs +++ b/openssl/src/engine.rs @@ -57,9 +57,9 @@ impl Engine { /// Returns the "next" ENGINE type available, after the passed in ENGINE. #[corresponds(ENGINE_get_next)] #[inline] - pub fn get_next(e: Engine) -> Result { + pub fn get_next(&mut self) -> Result { unsafe { - let ptr = cvt_p(ffi::ENGINE_get_next(e.as_ptr()))?; + let ptr = cvt_p(ffi::ENGINE_get_next(self.as_ptr()))?; Ok(Engine::from_ptr(ptr)) } } @@ -67,9 +67,9 @@ impl Engine { /// Returns the "previous" ENGINE type available, before the passed in ENGINE. #[corresponds(ENGINE_get_prev)] #[inline] - pub fn get_prev(e: Engine) -> Result { + pub fn get_prev(&mut self) -> Result { unsafe { - let ptr = cvt_p(ffi::ENGINE_get_prev(e.as_ptr()))?; + let ptr = cvt_p(ffi::ENGINE_get_prev(self.as_ptr()))?; Ok(Engine::from_ptr(ptr)) } } @@ -77,9 +77,9 @@ impl Engine { /// Adds the engine to OpenSSL's internal engine list. #[corresponds(ENGINE_add)] #[inline] - pub fn add(e: Engine) -> Result<(), ErrorStack> { + pub fn add(&mut self) -> Result<(), ErrorStack> { unsafe { - cvt(ffi::ENGINE_add(e.as_ptr()))?; + cvt(ffi::ENGINE_add(self.as_ptr()))?; } Ok(()) } @@ -87,9 +87,9 @@ impl Engine { /// Removes the engine from OpenSSL's internal engine list. #[corresponds(ENGINE_remove)] #[inline] - pub fn remove(e: Engine) -> Result<(), ErrorStack> { + pub fn remove(&mut self) -> Result<(), ErrorStack> { unsafe { - cvt(ffi::ENGINE_remove(e.as_ptr()))?; + cvt(ffi::ENGINE_remove(self.as_ptr()))?; } Ok(()) } @@ -108,9 +108,9 @@ impl Engine { /// Remove all references to the passed in engine. #[corresponds(ENGINE_finish)] #[inline] - pub fn finish(e: Engine) -> Result<(), ErrorStack> { + pub fn finish(&mut self) -> Result<(), ErrorStack> { unsafe { - cvt(ffi::ENGINE_finish(e.as_ptr()))?; + cvt(ffi::ENGINE_finish(self.as_ptr()))?; } Ok(()) } @@ -495,10 +495,10 @@ impl Engine { /// Sets the ID on the engine. #[corresponds(ENGINE_set_id)] #[inline] - pub fn set_id(e: Engine, id: &str) -> Result<(), ErrorStack> { + pub fn set_id(&mut self, id: &str) -> Result<(), ErrorStack> { let id = CString::new(id).unwrap(); unsafe { - cvt(ffi::ENGINE_set_id(e.as_ptr(), id.as_ptr()))?; + cvt(ffi::ENGINE_set_id(self.as_ptr(), id.as_ptr()))?; } Ok(()) } @@ -506,10 +506,10 @@ impl Engine { /// Sets the name on the engine. #[corresponds(ENGINE_set_name)] #[inline] - pub fn set_name(e: Engine, name: &str) -> Result<(), ErrorStack> { + pub fn set_name(&mut self, name: &str) -> Result<(), ErrorStack> { let name = CString::new(name).unwrap(); unsafe { - cvt(ffi::ENGINE_set_name(e.as_ptr(), name.as_ptr()))?; + cvt(ffi::ENGINE_set_name(self.as_ptr(), name.as_ptr()))?; } Ok(()) } @@ -608,22 +608,34 @@ impl Engine { /// Returns the engine's ID. #[corresponds(ENGINE_get_id)] #[inline] - pub fn get_id(e: Engine) -> Result { + pub fn get_id(&mut self) -> Result { unsafe { - let ptr = ffi::ENGINE_get_id(e.as_ptr()); - let slice = std::slice::from_raw_parts(ptr as *const u8, strlen(ptr) + 1 as usize); - Ok(std::str::from_utf8_unchecked(slice).to_string()) + let ptr = ffi::ENGINE_get_id(self.as_ptr()); + if ptr.is_null() { + return Err(ErrorStack::get()); + } + + let slice = std::slice::from_raw_parts(ptr as *const u8, strlen(ptr) as usize); + let s = std::str::from_utf8_unchecked(slice).to_string(); + + Ok(s) } } /// Returns the engine's name. #[corresponds(ENGINE_get_name)] #[inline] - pub fn get_name(e: Engine) -> Result { + pub fn get_name(&mut self) -> Result { unsafe { - let ptr = ffi::ENGINE_get_name(e.as_ptr()); - let slice = std::slice::from_raw_parts(ptr as *const u8, strlen(ptr) + 1 as usize); - Ok(std::str::from_utf8_unchecked(slice).to_string()) + let ptr = ffi::ENGINE_get_name(self.as_ptr()); + if ptr.is_null() { + return Err(ErrorStack::get()); + } + + let slice = std::slice::from_raw_parts(ptr as *const u8, strlen(ptr) as usize); + let s = std::str::from_utf8_unchecked(slice).to_string(); + + Ok(s) } } @@ -766,3 +778,44 @@ impl Drop for Engine { } } } + +mod test { + use super::*; + + // #[test] + fn test_basic_engine_creation() { + let mut engine = Engine::new().unwrap(); + + let name = String::from("engine_name"); + let id = String::from("engine_id"); + + // there should not be errors on setting id or name + assert!(!engine.set_id(&id).is_err()); + assert!(!engine.set_name(&name).is_err()); + + assert_eq!(id, engine.get_id().unwrap().as_str()); + assert_eq!(name, engine.get_name().unwrap().as_str()); + } + + #[test] + fn iterate_through_engines() { + let mut engine = Engine::get_first().unwrap(); + + let mut has_engines = true; + let mut engine_cnt = 1; + + println!("Engines:"); + + while has_engines { + println!(" {}, name={}, id={}", + engine_cnt, engine.get_name().unwrap(), engine.get_id().unwrap() + ); + match engine.get_next() { + Ok(e) => engine = e, + Err(m) => has_engines = false + } + + engine_cnt += 1; + } + } +} From 695082a8cae6fc1b39402696e34940079ad85a35 Mon Sep 17 00:00:00 2001 From: Brian Chrzanowski Date: Tue, 1 Aug 2023 19:11:32 -0400 Subject: [PATCH 06/17] clippy fixes --- systest/build.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/systest/build.rs b/systest/build.rs index f4cc9dedfe..d02c2a205b 100644 --- a/systest/build.rs +++ b/systest/build.rs @@ -79,7 +79,8 @@ fn main() { cfg.header("openssl/kdf.h"); } - if 0x10100000 <= version && version < 0x30000000 { + + if (0x10100000..0x30000000).contains(&version) { cfg.header("openssl/engine.h"); } From 4d148baac5d70d1d218f82fe1d942521e41fb463 Mon Sep 17 00:00:00 2001 From: Brian Chrzanowski Date: Wed, 2 Aug 2023 11:01:33 -0400 Subject: [PATCH 07/17] fmt fix --- openssl-sys/src/handwritten/engine.rs | 26 +++++++++++----- openssl/src/engine.rs | 43 +++++++++++++++++---------- systest/build.rs | 1 - 3 files changed, 45 insertions(+), 25 deletions(-) diff --git a/openssl-sys/src/handwritten/engine.rs b/openssl-sys/src/handwritten/engine.rs index 5c0ff69351..c5aafce683 100644 --- a/openssl-sys/src/handwritten/engine.rs +++ b/openssl-sys/src/handwritten/engine.rs @@ -101,7 +101,7 @@ extern "C" { cmd: c_int, i: c_long, p: *mut c_void, - f: extern "C" fn (), + f: extern "C" fn(), ) -> c_int; pub fn ENGINE_cmd_is_executable(e: *mut ENGINE, cmd: c_int) -> c_int; @@ -111,7 +111,7 @@ extern "C" { cmd_name: *const c_char, i: c_long, p: *mut c_void, - f: extern "C" fn (), + f: extern "C" fn(), cmd_optional: c_int, ) -> c_int; @@ -142,32 +142,42 @@ extern "C" { pub fn ENGINE_set_destroy_function( e: *mut ENGINE, - destroy_f: extern "C" fn (*mut ENGINE) -> c_int, + destroy_f: extern "C" fn(*mut ENGINE) -> c_int, ) -> c_int; pub fn ENGINE_set_init_function( e: *mut ENGINE, - init_f: extern "C" fn (*mut ENGINE) -> c_int, + init_f: extern "C" fn(*mut ENGINE) -> c_int, ) -> c_int; pub fn ENGINE_set_finish_function( e: *mut ENGINE, - finish_f: extern "C" fn (*mut ENGINE) -> c_int, + finish_f: extern "C" fn(*mut ENGINE) -> c_int, ) -> c_int; pub fn ENGINE_set_ctrl_function( e: *mut ENGINE, - ctrl_f: extern "C" fn (*mut ENGINE, c_int, c_long, *mut c_void, extern "C" fn ()) -> c_int, + ctrl_f: extern "C" fn(*mut ENGINE, c_int, c_long, *mut c_void, extern "C" fn()) -> c_int, ) -> c_int; pub fn ENGINE_set_load_privkey_function( e: *mut ENGINE, - loadpriv_f: extern "C" fn (*mut ENGINE, *const c_char, *mut UI_METHOD, *mut c_void) -> *mut EVP_PKEY, + loadpriv_f: extern "C" fn( + *mut ENGINE, + *const c_char, + *mut UI_METHOD, + *mut c_void, + ) -> *mut EVP_PKEY, ) -> c_int; pub fn ENGINE_set_load_pubkey_function( e: *mut ENGINE, - loadpub_f: unsafe extern "C" fn (*mut ENGINE, *const c_char, *mut UI_METHOD, *mut c_void) -> *mut EVP_PKEY, + loadpub_f: unsafe extern "C" fn( + *mut ENGINE, + *const c_char, + *mut UI_METHOD, + *mut c_void, + ) -> *mut EVP_PKEY, ) -> c_int; pub fn ENGINE_set_ciphers(e: *mut ENGINE, f: ENGINE_CIPHERS_PTR) -> c_int; diff --git a/openssl/src/engine.rs b/openssl/src/engine.rs index 8376f4f6d7..d162c171d1 100644 --- a/openssl/src/engine.rs +++ b/openssl/src/engine.rs @@ -4,11 +4,11 @@ use crate::pkey_ctx::PkeyCtxRef; use crate::{cvt, cvt_n, cvt_p}; use cfg_if::cfg_if; use foreign_types::{ForeignType, ForeignTypeRef}; +use libc::strlen; use openssl_macros::corresponds; use std::convert::TryFrom; +use std::ffi::{c_int, c_uint, c_void, CString}; use std::ptr; -use std::ffi::{CString, c_int, c_uint, c_void}; -use libc::{strlen}; struct Engine(*mut ffi::ENGINE); @@ -466,7 +466,13 @@ impl Engine { Ok(()) } - pub fn ctrl(e: Engine, cmd: i32, i: i64, p: *mut c_void, f: extern "C" fn ()) -> Result<(), ErrorStack> { + pub fn ctrl( + e: Engine, + cmd: i32, + i: i64, + p: *mut c_void, + f: extern "C" fn(), + ) -> Result<(), ErrorStack> { todo!(); } @@ -481,7 +487,12 @@ impl Engine { todo!(); } - pub fn ctrl_cmd_string(e: Engine, cmd: &str, arg: &str, optional: i32) -> Result<(), ErrorStack> { + pub fn ctrl_cmd_string( + e: Engine, + cmd: &str, + arg: &str, + optional: i32, + ) -> Result<(), ErrorStack> { todo!(); } @@ -552,35 +563,35 @@ impl Engine { /// Sets the init function on the engine. #[corresponds(ENGINE_set_init_function)] #[inline] - pub fn set_init_function (e: Engine) -> Result<(), ErrorStack> { + pub fn set_init_function(e: Engine) -> Result<(), ErrorStack> { todo!(); } /// Sets the finish function on the engine. #[corresponds(ENGINE_set_finish_function)] #[inline] - pub fn set_finish_function (e: Engine) -> Result<(), ErrorStack> { + pub fn set_finish_function(e: Engine) -> Result<(), ErrorStack> { todo!(); } /// Sets the ctrl function on the engine. #[corresponds(ENGINE_set_ctrl_function)] #[inline] - pub fn set_ctrl_function (e: Engine) -> Result<(), ErrorStack> { + pub fn set_ctrl_function(e: Engine) -> Result<(), ErrorStack> { todo!(); } /// Sets the `load_privkey` function on the engine. #[corresponds(ENGINE_set_load_privkey_function)] #[inline] - pub fn set_load_privkey_function (e: Engine) -> Result<(), ErrorStack> { + pub fn set_load_privkey_function(e: Engine) -> Result<(), ErrorStack> { todo!(); } /// Sets the `load_pubkey` function on the engine. #[corresponds(ENGINE_set_load_pubkey_function)] #[inline] - pub fn set_load_pubkey_function (e: Engine) -> Result<(), ErrorStack> { + pub fn set_load_pubkey_function(e: Engine) -> Result<(), ErrorStack> { todo!(); } @@ -742,9 +753,7 @@ impl Engine { #[inline] pub fn get_flags(e: Engine) -> i32 { // TODO should these flags be a different type? - unsafe { - ffi::ENGINE_get_flags(e.as_ptr()) - } + unsafe { ffi::ENGINE_get_flags(e.as_ptr()) } } /// Returns the command definitions. @@ -767,7 +776,6 @@ impl Engine { pub fn load_public_key(e: Engine) -> Result<(), ErrorStack> { todo!(); } - } impl Drop for Engine { @@ -807,12 +815,15 @@ mod test { println!("Engines:"); while has_engines { - println!(" {}, name={}, id={}", - engine_cnt, engine.get_name().unwrap(), engine.get_id().unwrap() + println!( + " {}, name={}, id={}", + engine_cnt, + engine.get_name().unwrap(), + engine.get_id().unwrap() ); match engine.get_next() { Ok(e) => engine = e, - Err(m) => has_engines = false + Err(m) => has_engines = false, } engine_cnt += 1; diff --git a/systest/build.rs b/systest/build.rs index d02c2a205b..2d606cb9bf 100644 --- a/systest/build.rs +++ b/systest/build.rs @@ -79,7 +79,6 @@ fn main() { cfg.header("openssl/kdf.h"); } - if (0x10100000..0x30000000).contains(&version) { cfg.header("openssl/engine.h"); } From 2319781e09c24bca045fc473a1dd9c2e1707cf24 Mon Sep 17 00:00:00 2001 From: Brian Chrzanowski Date: Wed, 2 Aug 2023 11:05:27 -0400 Subject: [PATCH 08/17] removed unneeded usings and made methods methods --- openssl-sys/src/handwritten/mod.rs | 2 +- openssl/src/engine.rs | 166 ++++++++++++++--------------- 2 files changed, 83 insertions(+), 85 deletions(-) diff --git a/openssl-sys/src/handwritten/mod.rs b/openssl-sys/src/handwritten/mod.rs index d5ba8858d2..1dd8c2a32c 100644 --- a/openssl-sys/src/handwritten/mod.rs +++ b/openssl-sys/src/handwritten/mod.rs @@ -46,7 +46,7 @@ mod crypto; mod dh; mod dsa; mod ec; -#[cfg(all(ossl110))] +#[cfg(ossl110)] mod engine; mod err; mod evp; diff --git a/openssl/src/engine.rs b/openssl/src/engine.rs index d162c171d1..6afdf4bfc7 100644 --- a/openssl/src/engine.rs +++ b/openssl/src/engine.rs @@ -1,6 +1,4 @@ use crate::error::ErrorStack; -use crate::pkey::{HasPrivate, HasPublic, PKeyRef}; -use crate::pkey_ctx::PkeyCtxRef; use crate::{cvt, cvt_n, cvt_p}; use cfg_if::cfg_if; use foreign_types::{ForeignType, ForeignTypeRef}; @@ -187,9 +185,9 @@ impl Engine { /// Sets the default RSA engine. #[corresponds(ENGINE_set_default_RSA)] #[inline] - pub fn set_default_rsa(e: Engine) -> Result<(), ErrorStack> { + pub fn set_default_rsa(&mut self) -> Result<(), ErrorStack> { unsafe { - cvt(ffi::ENGINE_set_default_RSA(e.as_ptr()))?; + cvt(ffi::ENGINE_set_default_RSA(self.as_ptr()))?; } Ok(()) } @@ -197,9 +195,9 @@ impl Engine { /// Sets the default DSA engine. #[corresponds(ENGINE_set_default_DSA)] #[inline] - pub fn set_default_dsa(e: Engine) -> Result<(), ErrorStack> { + pub fn set_default_dsa(&mut self) -> Result<(), ErrorStack> { unsafe { - cvt(ffi::ENGINE_set_default_DSA(e.as_ptr()))?; + cvt(ffi::ENGINE_set_default_DSA(self.as_ptr()))?; } Ok(()) } @@ -207,9 +205,9 @@ impl Engine { /// Sets the default DH engine. #[corresponds(ENGINE_set_default_DH)] #[inline] - pub fn set_default_dh(e: Engine) -> Result<(), ErrorStack> { + pub fn set_default_dh(&mut self) -> Result<(), ErrorStack> { unsafe { - cvt(ffi::ENGINE_set_default_DH(e.as_ptr()))?; + cvt(ffi::ENGINE_set_default_DH(self.as_ptr()))?; } Ok(()) } @@ -217,9 +215,9 @@ impl Engine { /// Sets the default RAND engine. #[corresponds(ENGINE_set_default_RAND)] #[inline] - pub fn set_default_rand(e: Engine) -> Result<(), ErrorStack> { + pub fn set_default_rand(&mut self) -> Result<(), ErrorStack> { unsafe { - cvt(ffi::ENGINE_set_default_RAND(e.as_ptr()))?; + cvt(ffi::ENGINE_set_default_RAND(self.as_ptr()))?; } Ok(()) } @@ -227,9 +225,9 @@ impl Engine { /// Sets the default ciphers engine. #[corresponds(ENGINE_set_default_ciphers)] #[inline] - pub fn set_default_ciphers(e: Engine) -> Result<(), ErrorStack> { + pub fn set_default_ciphers(&mut self) -> Result<(), ErrorStack> { unsafe { - cvt(ffi::ENGINE_set_default_ciphers(e.as_ptr()))?; + cvt(ffi::ENGINE_set_default_ciphers(self.as_ptr()))?; } Ok(()) } @@ -237,9 +235,9 @@ impl Engine { /// Sets the default digests engine. #[corresponds(ENGINE_set_default_digests)] #[inline] - pub fn set_default_digests(e: Engine) -> Result<(), ErrorStack> { + pub fn set_default_digests(&mut self) -> Result<(), ErrorStack> { unsafe { - cvt(ffi::ENGINE_set_default_digests(e.as_ptr()))?; + cvt(ffi::ENGINE_set_default_digests(self.as_ptr()))?; } Ok(()) } @@ -247,10 +245,10 @@ impl Engine { /// Sets the default string for the engine. #[corresponds(ENGINE_set_default_string)] #[inline] - pub fn set_default_string(e: Engine, list: &str) -> Result<(), ErrorStack> { + pub fn set_default_string(&mut self, list: &str) -> Result<(), ErrorStack> { let list = CString::new(list).unwrap(); unsafe { - cvt(ffi::ENGINE_set_default_string(e.as_ptr(), list.as_ptr()))?; + cvt(ffi::ENGINE_set_default_string(self.as_ptr(), list.as_ptr()))?; } Ok(()) } @@ -258,9 +256,9 @@ impl Engine { /// Sets the default engine. #[corresponds(ENGINE_set_default)] #[inline] - pub fn set_default(e: Engine, flags: u32) -> Result<(), ErrorStack> { + pub fn set_default(&mut self, flags: u32) -> Result<(), ErrorStack> { unsafe { - cvt(ffi::ENGINE_set_default(e.as_ptr(), c_uint::from(flags)))?; + cvt(ffi::ENGINE_set_default(self.as_ptr(), c_uint::from(flags)))?; } Ok(()) } @@ -287,9 +285,9 @@ impl Engine { /// Registers the input engine as the RSA engine. #[corresponds(ENGINE_register_RSA)] #[inline] - pub fn register_rsa(e: Engine) -> Result<(), ErrorStack> { + pub fn register_rsa(&mut self) -> Result<(), ErrorStack> { unsafe { - cvt(ffi::ENGINE_register_RSA(e.as_ptr()))?; + cvt(ffi::ENGINE_register_RSA(self.as_ptr()))?; } Ok(()) } @@ -297,16 +295,16 @@ impl Engine { /// Unregisters the input engine as the RSA engine. #[corresponds(ENGINE_unregister_RSA)] #[inline] - pub fn unregister_rsa(e: Engine) { + pub fn unregister_rsa(&mut self) { unsafe { - ffi::ENGINE_unregister_RSA(e.as_ptr()); + ffi::ENGINE_unregister_RSA(self.as_ptr()); } } /// Registers all of the engines as RSA. #[corresponds(ENGINE_register_all_RSA)] #[inline] - pub fn register_all_rsa(e: Engine) { + pub fn register_all_rsa(&mut self) { unsafe { ffi::ENGINE_register_all_RSA(); } @@ -315,9 +313,9 @@ impl Engine { /// Registers the input engine as the DSA engine. #[corresponds(ENGINE_register_DSA)] #[inline] - pub fn register_dsa(e: Engine) -> Result<(), ErrorStack> { + pub fn register_dsa(&mut self) -> Result<(), ErrorStack> { unsafe { - cvt(ffi::ENGINE_register_DSA(e.as_ptr()))?; + cvt(ffi::ENGINE_register_DSA(self.as_ptr()))?; } Ok(()) } @@ -325,9 +323,9 @@ impl Engine { /// Unregisters the input engine as the DSA engine. #[corresponds(ENGINE_unregister_DSA)] #[inline] - pub fn unregister_dsa(e: Engine) { + pub fn unregister_dsa(&mut self) { unsafe { - ffi::ENGINE_unregister_DSA(e.as_ptr()); + ffi::ENGINE_unregister_DSA(self.as_ptr()); } } @@ -343,9 +341,9 @@ impl Engine { /// Registers the input engine as the DH engine. #[corresponds(ENGINE_register_DH)] #[inline] - pub fn register_dh(e: Engine) -> Result<(), ErrorStack> { + pub fn register_dh(&mut self) -> Result<(), ErrorStack> { unsafe { - cvt(ffi::ENGINE_register_DH(e.as_ptr()))?; + cvt(ffi::ENGINE_register_DH(self.as_ptr()))?; } Ok(()) } @@ -353,9 +351,9 @@ impl Engine { /// Unregisters the input engine as the DH engine. #[corresponds(ENGINE_unregister_DH)] #[inline] - pub fn unregister_dh(e: Engine) { + pub fn unregister_dh(&mut self) { unsafe { - ffi::ENGINE_unregister_DH(e.as_ptr()); + ffi::ENGINE_unregister_DH(self.as_ptr()); } } @@ -371,9 +369,9 @@ impl Engine { /// Registers the input engine as the RAND engine. #[corresponds(ENGINE_register_RAND)] #[inline] - pub fn register_rand(e: Engine) -> Result<(), ErrorStack> { + pub fn register_rand(&mut self) -> Result<(), ErrorStack> { unsafe { - cvt(ffi::ENGINE_register_RAND(e.as_ptr()))?; + cvt(ffi::ENGINE_register_RAND(self.as_ptr()))?; } Ok(()) } @@ -381,9 +379,9 @@ impl Engine { /// Unregisters the input engine as the RAND engine. #[corresponds(ENGINE_unregister_RAND)] #[inline] - pub fn unregister_rand(e: Engine) { + pub fn unregister_rand(&mut self) { unsafe { - ffi::ENGINE_unregister_RAND(e.as_ptr()); + ffi::ENGINE_unregister_RAND(self.as_ptr()); } } @@ -399,9 +397,9 @@ impl Engine { /// Registers ciphers from the input engine. #[corresponds(ENGINE_register_ciphers)] #[inline] - pub fn register_ciphers(e: Engine) -> Result<(), ErrorStack> { + pub fn register_ciphers(&mut self) -> Result<(), ErrorStack> { unsafe { - cvt(ffi::ENGINE_register_ciphers(e.as_ptr()))?; + cvt(ffi::ENGINE_register_ciphers(self.as_ptr()))?; } Ok(()) } @@ -409,9 +407,9 @@ impl Engine { /// Unregisters the ciphers from the input engine. #[corresponds(ENGINE_unregister_ciphers)] #[inline] - pub fn unregister_ciphers(e: Engine) { + pub fn unregister_ciphers(&mut self) { unsafe { - ffi::ENGINE_unregister_ciphers(e.as_ptr()); + ffi::ENGINE_unregister_ciphers(self.as_ptr()); } } @@ -427,9 +425,9 @@ impl Engine { /// Registers digests from the input engine. #[corresponds(ENGINE_register_digests)] #[inline] - pub fn register_digests(e: Engine) -> Result<(), ErrorStack> { + pub fn register_digests(&mut self) -> Result<(), ErrorStack> { unsafe { - cvt(ffi::ENGINE_register_digests(e.as_ptr()))?; + cvt(ffi::ENGINE_register_digests(self.as_ptr()))?; } Ok(()) } @@ -437,9 +435,9 @@ impl Engine { /// Unregisters the digests from the input engine. #[corresponds(ENGINE_unregister_digests)] #[inline] - pub fn unregister_digests(e: Engine) { + pub fn unregister_digests(&mut self) { unsafe { - ffi::ENGINE_unregister_digests(e.as_ptr()); + ffi::ENGINE_unregister_digests(self.as_ptr()); } } @@ -452,9 +450,9 @@ impl Engine { } } - pub fn register_complete(e: Engine) -> Result<(), ErrorStack> { + pub fn register_complete(&mut self) -> Result<(), ErrorStack> { unsafe { - cvt(ffi::ENGINE_register_complete(e.as_ptr()))?; + cvt(ffi::ENGINE_register_complete(self.as_ptr()))?; } Ok(()) } @@ -467,7 +465,7 @@ impl Engine { } pub fn ctrl( - e: Engine, + &mut self, cmd: i32, i: i64, p: *mut c_void, @@ -476,19 +474,19 @@ impl Engine { todo!(); } - pub fn cmd_is_executable(e: Engine, cmd: i32) -> Result<(), ErrorStack> { + pub fn cmd_is_executable(&mut self, cmd: i32) -> Result<(), ErrorStack> { unsafe { - cvt(ffi::ENGINE_cmd_is_executable(e.as_ptr(), c_int::from(cmd)))?; + cvt(ffi::ENGINE_cmd_is_executable(self.as_ptr(), c_int::from(cmd)))?; } Ok(()) } - pub fn ctrl_cmd(e: Engine, cmd: &str, arg: &str, param: i32) -> Result<(), ErrorStack> { + pub fn ctrl_cmd(&mut self, cmd: &str, arg: &str, param: i32) -> Result<(), ErrorStack> { todo!(); } pub fn ctrl_cmd_string( - e: Engine, + &mut self, cmd: &str, arg: &str, optional: i32, @@ -496,9 +494,9 @@ impl Engine { todo!(); } - pub fn up_ref(e: Engine) -> Result<(), ErrorStack> { + pub fn up_ref(&mut self) -> Result<(), ErrorStack> { unsafe { - cvt(ffi::ENGINE_up_ref(e.as_ptr()))?; + cvt(ffi::ENGINE_up_ref(self.as_ptr()))?; } Ok(()) } @@ -528,91 +526,91 @@ impl Engine { /// Sets the RSA method on the engine. #[corresponds(ENGINE_set_RSA)] #[inline] - pub fn set_rsa(e: Engine) -> Result<(), ErrorStack> { + pub fn set_rsa(&mut self) -> Result<(), ErrorStack> { todo!(); } /// Sets the DSA method on the engine. #[corresponds(ENGINE_set_DSA)] #[inline] - pub fn set_dsa(e: Engine) -> Result<(), ErrorStack> { + pub fn set_dsa(&mut self) -> Result<(), ErrorStack> { todo!(); } /// Sets the DH method on the engine. #[corresponds(ENGINE_set_DH)] #[inline] - pub fn set_dh(e: Engine) -> Result<(), ErrorStack> { + pub fn set_dh(&mut self) -> Result<(), ErrorStack> { todo!(); } /// Sets the RAND method on the engine. #[corresponds(ENGINE_set_RAND)] #[inline] - pub fn set_rand(e: Engine) -> Result<(), ErrorStack> { + pub fn set_rand(&mut self) -> Result<(), ErrorStack> { todo!(); } /// Sets the destroy function on the engine. #[corresponds(ENGINE_set_destroy_function)] #[inline] - pub fn set_destroy_function(e: Engine) -> Result<(), ErrorStack> { + pub fn set_destroy_function(&mut self) -> Result<(), ErrorStack> { todo!(); } /// Sets the init function on the engine. #[corresponds(ENGINE_set_init_function)] #[inline] - pub fn set_init_function(e: Engine) -> Result<(), ErrorStack> { + pub fn set_init_function(&mut self) -> Result<(), ErrorStack> { todo!(); } /// Sets the finish function on the engine. #[corresponds(ENGINE_set_finish_function)] #[inline] - pub fn set_finish_function(e: Engine) -> Result<(), ErrorStack> { + pub fn set_finish_function(&mut self) -> Result<(), ErrorStack> { todo!(); } /// Sets the ctrl function on the engine. #[corresponds(ENGINE_set_ctrl_function)] #[inline] - pub fn set_ctrl_function(e: Engine) -> Result<(), ErrorStack> { + pub fn set_ctrl_function(&mut self) -> Result<(), ErrorStack> { todo!(); } /// Sets the `load_privkey` function on the engine. #[corresponds(ENGINE_set_load_privkey_function)] #[inline] - pub fn set_load_privkey_function(e: Engine) -> Result<(), ErrorStack> { + pub fn set_load_privkey_function(&mut self) -> Result<(), ErrorStack> { todo!(); } /// Sets the `load_pubkey` function on the engine. #[corresponds(ENGINE_set_load_pubkey_function)] #[inline] - pub fn set_load_pubkey_function(e: Engine) -> Result<(), ErrorStack> { + pub fn set_load_pubkey_function(&mut self) -> Result<(), ErrorStack> { todo!(); } /// Sets the ciphers pointer on the engine. #[corresponds(ENGINE_set_ciphers)] #[inline] - pub fn set_ciphers(e: Engine) -> Result<(), ErrorStack> { + pub fn set_ciphers(&mut self) -> Result<(), ErrorStack> { todo!(); } /// Sets the digests pointer on the engine. #[corresponds(ENGINE_set_digests)] #[inline] - pub fn set_digests(e: Engine) -> Result<(), ErrorStack> { + pub fn set_digests(&mut self) -> Result<(), ErrorStack> { todo!(); } /// Sets command definitions on the engine. #[corresponds(ENGINE_set_cmd_defns)] #[inline] - pub fn set_cmd_defns(e: Engine) -> Result<(), ErrorStack> { + pub fn set_cmd_defns(&mut self) -> Result<(), ErrorStack> { todo!(); } @@ -653,127 +651,127 @@ impl Engine { /// Returns the engine's currently set RSA method. #[corresponds(ENGINE_get_RSA)] #[inline] - pub fn get_rsa(e: Engine) -> Result<(), ErrorStack> { + pub fn get_rsa(&mut self) -> Result<(), ErrorStack> { todo!(); } /// Returns the engine's currently set DSA method. #[corresponds(ENGINE_get_DSA)] #[inline] - pub fn get_dsa(e: Engine) -> Result<(), ErrorStack> { + pub fn get_dsa(&mut self) -> Result<(), ErrorStack> { todo!(); } /// Returns the engine's currently set DH method. #[corresponds(ENGINE_get_DH)] #[inline] - pub fn get_dh(e: Engine) -> Result<(), ErrorStack> { + pub fn get_dh(&mut self) -> Result<(), ErrorStack> { todo!(); } /// Returns the engine's currently set RAND method. #[corresponds(ENGINE_get_RAND)] #[inline] - pub fn get_rand(e: Engine) -> Result<(), ErrorStack> { + pub fn get_rand(&mut self) -> Result<(), ErrorStack> { todo!(); } /// Returns the engine's currently set destroy function. #[corresponds(ENGINE_get_destroy_function)] #[inline] - pub fn get_destroy_function(e: Engine) -> Result<(), ErrorStack> { + pub fn get_destroy_function(&mut self) -> Result<(), ErrorStack> { todo!(); } /// Returns the engine's currently set init function. #[corresponds(ENGINE_get_init_function)] #[inline] - pub fn get_init_function(e: Engine) -> Result<(), ErrorStack> { + pub fn get_init_function(&mut self) -> Result<(), ErrorStack> { todo!(); } /// Returns the engine's currently set finish function. #[corresponds(ENGINE_get_finish_function)] #[inline] - pub fn get_finish_function(e: Engine) -> Result<(), ErrorStack> { + pub fn get_finish_function(&mut self) -> Result<(), ErrorStack> { todo!(); } /// Returns the engine's currently set ctrl function. #[corresponds(ENGINE_get_ctrl_function)] #[inline] - pub fn get_ctrl_function(e: Engine) -> Result<(), ErrorStack> { + pub fn get_ctrl_function(&mut self) -> Result<(), ErrorStack> { todo!(); } /// Returns the engine's currently set `load_privkey_function` function. #[corresponds(ENGINE_get_load_privkey_function)] #[inline] - pub fn get_load_privkey_function(e: Engine) -> Result<(), ErrorStack> { + pub fn get_load_privkey_function(&mut self) -> Result<(), ErrorStack> { todo!(); } /// Returns the engine's currently set `load_pubkey_function` function. #[corresponds(ENGINE_get_load_pubkey_function)] #[inline] - pub fn get_load_pubkey_function(e: Engine) -> Result<(), ErrorStack> { + pub fn get_load_pubkey_function(&mut self) -> Result<(), ErrorStack> { todo!(); } /// Returns the engine's currently set ciphers. #[corresponds(ENGINE_get_ciphers)] #[inline] - pub fn get_ciphers(e: Engine) -> Result<(), ErrorStack> { + pub fn get_ciphers(&mut self) -> Result<(), ErrorStack> { todo!(); } /// Returns the engine's current set digests. #[corresponds(ENGINE_get_digests)] #[inline] - pub fn get_digests(e: Engine) -> Result<(), ErrorStack> { + pub fn get_digests(&mut self) -> Result<(), ErrorStack> { todo!(); } /// Returns the cipher for the passed `nid` value. #[corresponds(ENGINE_get_cipher)] #[inline] - pub fn get_cipher(e: Engine, nid: i32) -> Result<(), ErrorStack> { + pub fn get_cipher(&mut self, nid: i32) -> Result<(), ErrorStack> { todo!(); } /// Returns the digest for the passed `nid` value. #[corresponds(ENGINE_get_digest)] #[inline] - pub fn get_digest(e: Engine, nid: i32) -> Result<(), ErrorStack> { + pub fn get_digest(&mut self, nid: i32) -> Result<(), ErrorStack> { todo!(); } /// Returns the engine's flags. #[corresponds(ENGINE_get_flags)] #[inline] - pub fn get_flags(e: Engine) -> i32 { + pub fn get_flags(&mut self) -> i32 { // TODO should these flags be a different type? - unsafe { ffi::ENGINE_get_flags(e.as_ptr()) } + unsafe { ffi::ENGINE_get_flags(self.as_ptr()) } } /// Returns the command definitions. #[corresponds(ENGINE_get_cmd_defns)] #[inline] - pub fn get_cmd_defns(e: Engine) -> Result<(), ErrorStack> { + pub fn get_cmd_defns(&mut self) -> Result<(), ErrorStack> { todo!(); } /// Load a private key into the engine. #[corresponds(ENGINE_load_private_key)] #[inline] - pub fn load_private_key(e: Engine) -> Result<(), ErrorStack> { + pub fn load_private_key(&mut self) -> Result<(), ErrorStack> { todo!(); } /// Load a public key into the engine. #[corresponds(ENGINE_load_public_key)] #[inline] - pub fn load_public_key(e: Engine) -> Result<(), ErrorStack> { + pub fn load_public_key(&mut self) -> Result<(), ErrorStack> { todo!(); } } From a829e36ef7cd2aef4ca87c3dfdc3fa3ff161db63 Mon Sep 17 00:00:00 2001 From: Brian Chrzanowski Date: Wed, 2 Aug 2023 11:12:44 -0400 Subject: [PATCH 09/17] more ci fixes --- openssl/src/engine.rs | 1 - openssl/src/lib.rs | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/openssl/src/engine.rs b/openssl/src/engine.rs index 6afdf4bfc7..8549dfcbea 100644 --- a/openssl/src/engine.rs +++ b/openssl/src/engine.rs @@ -1,7 +1,6 @@ use crate::error::ErrorStack; use crate::{cvt, cvt_n, cvt_p}; use cfg_if::cfg_if; -use foreign_types::{ForeignType, ForeignTypeRef}; use libc::strlen; use openssl_macros::corresponds; use std::convert::TryFrom; diff --git a/openssl/src/lib.rs b/openssl/src/lib.rs index 64d921b386..47d73dad6c 100644 --- a/openssl/src/lib.rs +++ b/openssl/src/lib.rs @@ -149,6 +149,7 @@ pub mod dsa; pub mod ec; pub mod ecdsa; pub mod encrypt; +#[cfg(all(not(boringssl), not(libressl), all(ossl110)))] pub mod engine; #[cfg(not(boringssl))] pub mod envelope; From f52d94a0a7a25017b63f92435862b1427dfa4a45 Mon Sep 17 00:00:00 2001 From: Brian Chrzanowski Date: Wed, 2 Aug 2023 11:20:29 -0400 Subject: [PATCH 10/17] fixed clippy issues except for unused funcs --- openssl/src/engine.rs | 50 ++++++++++++++++++++----------------------- openssl/src/lib.rs | 2 +- 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/openssl/src/engine.rs b/openssl/src/engine.rs index 8549dfcbea..090d7b73bc 100644 --- a/openssl/src/engine.rs +++ b/openssl/src/engine.rs @@ -1,11 +1,8 @@ use crate::error::ErrorStack; -use crate::{cvt, cvt_n, cvt_p}; -use cfg_if::cfg_if; +use crate::{cvt, cvt_p}; use libc::strlen; use openssl_macros::corresponds; -use std::convert::TryFrom; -use std::ffi::{c_int, c_uint, c_void, CString}; -use std::ptr; +use std::ffi::{c_void, CString}; struct Engine(*mut ffi::ENGINE); @@ -166,7 +163,7 @@ impl Engine { #[inline] pub fn get_cipher_engine(nid: i32) -> Result { unsafe { - let ptr = cvt_p(ffi::ENGINE_get_cipher_engine(c_int::from(nid)))?; + let ptr = cvt_p(ffi::ENGINE_get_cipher_engine(nid))?; Ok(Engine::from_ptr(ptr)) } } @@ -176,7 +173,7 @@ impl Engine { #[inline] pub fn get_digest_engine(nid: i32) -> Result { unsafe { - let ptr = cvt_p(ffi::ENGINE_get_digest_engine(c_int::from(nid)))?; + let ptr = cvt_p(ffi::ENGINE_get_digest_engine(nid))?; Ok(Engine::from_ptr(ptr)) } } @@ -257,7 +254,7 @@ impl Engine { #[inline] pub fn set_default(&mut self, flags: u32) -> Result<(), ErrorStack> { unsafe { - cvt(ffi::ENGINE_set_default(self.as_ptr(), c_uint::from(flags)))?; + cvt(ffi::ENGINE_set_default(self.as_ptr(), flags))?; } Ok(()) } @@ -267,8 +264,7 @@ impl Engine { #[inline] pub fn get_table_flags() -> u32 { unsafe { - let rc = ffi::ENGINE_get_table_flags(); - return u32::from(rc); + ffi::ENGINE_get_table_flags() } } @@ -277,7 +273,7 @@ impl Engine { #[inline] pub fn set_table_flags(flags: u32) { unsafe { - ffi::ENGINE_set_table_flags(c_uint::from(flags)); + ffi::ENGINE_set_table_flags(flags); } } @@ -465,30 +461,30 @@ impl Engine { pub fn ctrl( &mut self, - cmd: i32, - i: i64, - p: *mut c_void, - f: extern "C" fn(), + _cmd: i32, + _i: i64, + _p: *mut c_void, + _f: extern "C" fn(), ) -> Result<(), ErrorStack> { todo!(); } pub fn cmd_is_executable(&mut self, cmd: i32) -> Result<(), ErrorStack> { unsafe { - cvt(ffi::ENGINE_cmd_is_executable(self.as_ptr(), c_int::from(cmd)))?; + cvt(ffi::ENGINE_cmd_is_executable(self.as_ptr(), cmd))?; } Ok(()) } - pub fn ctrl_cmd(&mut self, cmd: &str, arg: &str, param: i32) -> Result<(), ErrorStack> { + pub fn ctrl_cmd(&mut self, _cmd: &str, _arg: &str, _param: i32) -> Result<(), ErrorStack> { todo!(); } pub fn ctrl_cmd_string( &mut self, - cmd: &str, - arg: &str, - optional: i32, + _cmd: &str, + _arg: &str, + _optional: i32, ) -> Result<(), ErrorStack> { todo!(); } @@ -623,7 +619,7 @@ impl Engine { return Err(ErrorStack::get()); } - let slice = std::slice::from_raw_parts(ptr as *const u8, strlen(ptr) as usize); + let slice = std::slice::from_raw_parts(ptr as *const u8, strlen(ptr)); let s = std::str::from_utf8_unchecked(slice).to_string(); Ok(s) @@ -640,7 +636,7 @@ impl Engine { return Err(ErrorStack::get()); } - let slice = std::slice::from_raw_parts(ptr as *const u8, strlen(ptr) as usize); + let slice = std::slice::from_raw_parts(ptr as *const u8, strlen(ptr)); let s = std::str::from_utf8_unchecked(slice).to_string(); Ok(s) @@ -734,14 +730,14 @@ impl Engine { /// Returns the cipher for the passed `nid` value. #[corresponds(ENGINE_get_cipher)] #[inline] - pub fn get_cipher(&mut self, nid: i32) -> Result<(), ErrorStack> { + pub fn get_cipher(&mut self, _nid: i32) -> Result<(), ErrorStack> { todo!(); } /// Returns the digest for the passed `nid` value. #[corresponds(ENGINE_get_digest)] #[inline] - pub fn get_digest(&mut self, nid: i32) -> Result<(), ErrorStack> { + pub fn get_digest(&mut self, _nid: i32) -> Result<(), ErrorStack> { todo!(); } @@ -795,8 +791,8 @@ mod test { let id = String::from("engine_id"); // there should not be errors on setting id or name - assert!(!engine.set_id(&id).is_err()); - assert!(!engine.set_name(&name).is_err()); + assert!(engine.set_id(&id).is_ok()); + assert!(engine.set_name(&name).is_ok()); assert_eq!(id, engine.get_id().unwrap().as_str()); assert_eq!(name, engine.get_name().unwrap().as_str()); @@ -820,7 +816,7 @@ mod test { ); match engine.get_next() { Ok(e) => engine = e, - Err(m) => has_engines = false, + Err(_) => has_engines = false, } engine_cnt += 1; diff --git a/openssl/src/lib.rs b/openssl/src/lib.rs index 47d73dad6c..d38958c0dd 100644 --- a/openssl/src/lib.rs +++ b/openssl/src/lib.rs @@ -149,7 +149,7 @@ pub mod dsa; pub mod ec; pub mod ecdsa; pub mod encrypt; -#[cfg(all(not(boringssl), not(libressl), all(ossl110)))] +#[cfg(all(not(boringssl), not(libressl), ossl110))] pub mod engine; #[cfg(not(boringssl))] pub mod envelope; From 95d2e8914da6f77d1bc606578531496508ec6890 Mon Sep 17 00:00:00 2001 From: Brian Chrzanowski Date: Wed, 2 Aug 2023 11:23:47 -0400 Subject: [PATCH 11/17] finished populating corresponds and inline macros --- openssl/src/engine.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/openssl/src/engine.rs b/openssl/src/engine.rs index 090d7b73bc..0957b08d8f 100644 --- a/openssl/src/engine.rs +++ b/openssl/src/engine.rs @@ -445,6 +445,8 @@ impl Engine { } } + #[corresponds(ENGINE_register_complete)] + #[inline] pub fn register_complete(&mut self) -> Result<(), ErrorStack> { unsafe { cvt(ffi::ENGINE_register_complete(self.as_ptr()))?; @@ -452,6 +454,8 @@ impl Engine { Ok(()) } + #[corresponds(ENGINE_register_all_complete)] + #[inline] pub fn register_all_complete() -> Result<(), ErrorStack> { unsafe { cvt(ffi::ENGINE_register_all_complete())?; @@ -459,6 +463,8 @@ impl Engine { Ok(()) } + #[corresponds(ENGINE_ctrl)] + #[inline] pub fn ctrl( &mut self, _cmd: i32, @@ -469,6 +475,8 @@ impl Engine { todo!(); } + #[corresponds(ENGINE_cmd_is_executable)] + #[inline] pub fn cmd_is_executable(&mut self, cmd: i32) -> Result<(), ErrorStack> { unsafe { cvt(ffi::ENGINE_cmd_is_executable(self.as_ptr(), cmd))?; @@ -476,10 +484,14 @@ impl Engine { Ok(()) } + #[corresponds(ENGINE_ctrl_cmd)] + #[inline] pub fn ctrl_cmd(&mut self, _cmd: &str, _arg: &str, _param: i32) -> Result<(), ErrorStack> { todo!(); } + #[corresponds(ENGINE_ctrl_cmd_string)] + #[inline] pub fn ctrl_cmd_string( &mut self, _cmd: &str, @@ -489,6 +501,8 @@ impl Engine { todo!(); } + #[corresponds(ENGINE_up_ref)] + #[inline] pub fn up_ref(&mut self) -> Result<(), ErrorStack> { unsafe { cvt(ffi::ENGINE_up_ref(self.as_ptr()))?; From 7b373e27200a307ecf698d98e0371748c281eea1 Mon Sep 17 00:00:00 2001 From: Brian Chrzanowski Date: Wed, 2 Aug 2023 12:34:58 -0400 Subject: [PATCH 12/17] restrict engine exports to ossl110 --- openssl-sys/src/handwritten/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/openssl-sys/src/handwritten/mod.rs b/openssl-sys/src/handwritten/mod.rs index 1dd8c2a32c..746cfb5983 100644 --- a/openssl-sys/src/handwritten/mod.rs +++ b/openssl-sys/src/handwritten/mod.rs @@ -9,6 +9,7 @@ pub use self::crypto::*; pub use self::dh::*; pub use self::dsa::*; pub use self::ec::*; +#[cfg(ossl110)] pub use self::engine::*; pub use self::err::*; pub use self::evp::*; From 3724009f7bc0f97998bd184270839ba5acf64d1d Mon Sep 17 00:00:00 2001 From: Brian Chrzanowski Date: Sat, 6 Apr 2024 00:59:13 -0400 Subject: [PATCH 13/17] fixed cfg macros --- openssl-sys/src/handwritten/engine.rs | 10 +++++----- openssl/src/lib.rs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/openssl-sys/src/handwritten/engine.rs b/openssl-sys/src/handwritten/engine.rs index c5aafce683..5227a8ab30 100644 --- a/openssl-sys/src/handwritten/engine.rs +++ b/openssl-sys/src/handwritten/engine.rs @@ -27,7 +27,7 @@ pub const ENGINE_METHOD_EC: u32 = 0x0800; pub const ENGINE_METHOD_ALL: u32 = 0xffff; pub const ENGINE_METHOD_NONE: u32 = 0xffff; -#[cfg(ossl110)] +#[cfg(all(ossl110, not(ossl300)))] extern "C" { pub fn ENGINE_get_first() -> *mut ENGINE; @@ -238,7 +238,7 @@ extern "C" { } -// extern "C" { -// #[cfg(not(any(ossl100)))] -// pub fn ENGINE_cleanup(); -// } +extern "C" { + #[cfg(any(ossl100))] + pub fn ENGINE_cleanup(); +} diff --git a/openssl/src/lib.rs b/openssl/src/lib.rs index be2fee199d..ad001d3d52 100644 --- a/openssl/src/lib.rs +++ b/openssl/src/lib.rs @@ -154,7 +154,7 @@ pub mod dsa; pub mod ec; pub mod ecdsa; pub mod encrypt; -#[cfg(all(not(boringssl), not(libressl), ossl110))] +#[cfg(all(ossl110, not(ossl300)))] pub mod engine; #[cfg(not(boringssl))] pub mod envelope; From cb331e978c27628d84403d43ac58ebf76915f7f5 Mon Sep 17 00:00:00 2001 From: Brian Chrzanowski Date: Sat, 6 Apr 2024 01:38:29 -0400 Subject: [PATCH 14/17] removed redefined _METHOD enums --- openssl-sys/src/handwritten/engine.rs | 7 +------ openssl-sys/src/handwritten/types.rs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/openssl-sys/src/handwritten/engine.rs b/openssl-sys/src/handwritten/engine.rs index 5227a8ab30..47f51a9fa0 100644 --- a/openssl-sys/src/handwritten/engine.rs +++ b/openssl-sys/src/handwritten/engine.rs @@ -1,11 +1,6 @@ use super::super::*; use libc::*; -pub enum RSA_METHOD {} -pub enum DSA_METHOD {} -pub enum DH_METHOD {} -pub enum RAND_METHOD {} - pub enum ENGINE_GEN_INT_FUNC_PTR {} pub enum ENGINE_CIPHERS_PTR {} pub enum ENGINE_DIGESTS_PTR {} @@ -239,6 +234,6 @@ extern "C" { } extern "C" { - #[cfg(any(ossl100))] + #[cfg(ossl100)] pub fn ENGINE_cleanup(); } diff --git a/openssl-sys/src/handwritten/types.rs b/openssl-sys/src/handwritten/types.rs index 57c8113aa4..f98763539a 100644 --- a/openssl-sys/src/handwritten/types.rs +++ b/openssl-sys/src/handwritten/types.rs @@ -172,6 +172,23 @@ cfg_if! { } pub enum DH_METHOD {} +cfg_if! { + if #[cfg(any(ossl110, libressl280))] { + pub enum RAND {} + } else { + #[repr(C)] + pub struct RAND { + pub seed: fn (buf: *const c_void, num: c_int) -> c_int, + pub bytes: fn (buf: *mut c_uchar, num: c_int) -> c_int, + pub cleanup: fn () -> c_int, + pub add: fn (buf: *const c_void, num: c_int, entropy: f64) -> c_int, + pub pseudorand: fn (buf: *const c_uchar, num: c_int) -> c_int, + pub status: fn () -> c_int, + } + } +} +pub enum RAND_METHOD {} + cfg_if! { if #[cfg(any(ossl110, libressl280))] { pub enum DSA {} From 3032a9c2baeda70983b61290af819e8fe087247e Mon Sep 17 00:00:00 2001 From: Brian Chrzanowski Date: Sat, 6 Apr 2024 01:39:27 -0400 Subject: [PATCH 15/17] cargo fmt --- openssl/src/engine.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/openssl/src/engine.rs b/openssl/src/engine.rs index 0957b08d8f..4576a90d6b 100644 --- a/openssl/src/engine.rs +++ b/openssl/src/engine.rs @@ -263,9 +263,7 @@ impl Engine { #[corresponds(ENGINE_get_table_flags)] #[inline] pub fn get_table_flags() -> u32 { - unsafe { - ffi::ENGINE_get_table_flags() - } + unsafe { ffi::ENGINE_get_table_flags() } } /// Sets the (global?) engine table flags. From 4c1f81131e8c9a68548786b74d85b62e58d4d3e9 Mon Sep 17 00:00:00 2001 From: Brian Chrzanowski Date: Sat, 6 Apr 2024 01:53:51 -0400 Subject: [PATCH 16/17] ensured the engine functions would be accessible in all versions of openssl --- openssl-sys/src/handwritten/engine.rs | 5 +---- systest/build.rs | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/openssl-sys/src/handwritten/engine.rs b/openssl-sys/src/handwritten/engine.rs index 47f51a9fa0..2ed4da6f84 100644 --- a/openssl-sys/src/handwritten/engine.rs +++ b/openssl-sys/src/handwritten/engine.rs @@ -22,7 +22,7 @@ pub const ENGINE_METHOD_EC: u32 = 0x0800; pub const ENGINE_METHOD_ALL: u32 = 0xffff; pub const ENGINE_METHOD_NONE: u32 = 0xffff; -#[cfg(all(ossl110, not(ossl300)))] +#[cfg(ossl110)] extern "C" { pub fn ENGINE_get_first() -> *mut ENGINE; @@ -231,9 +231,6 @@ extern "C" { callback_data: *mut c_void, ) -> *mut EVP_PKEY; -} - -extern "C" { #[cfg(ossl100)] pub fn ENGINE_cleanup(); } diff --git a/systest/build.rs b/systest/build.rs index b5c3ccefab..1a65236187 100644 --- a/systest/build.rs +++ b/systest/build.rs @@ -82,7 +82,7 @@ fn main() { cfg.header("openssl/kdf.h"); } - if (0x10100000..0x30000000).contains(&version) { + if version >= 0x10000000 { cfg.header("openssl/engine.h"); } From 6e3dbd48a57a9a36dccf158848a331735d2539fb Mon Sep 17 00:00:00 2001 From: Brian Chrzanowski Date: Sat, 6 Apr 2024 02:07:48 -0400 Subject: [PATCH 17/17] removed the engine test for now - needs discussion on how to test --- openssl-sys/src/handwritten/engine.rs | 2 +- openssl/src/engine.rs | 86 +++++++++++++-------------- 2 files changed, 44 insertions(+), 44 deletions(-) diff --git a/openssl-sys/src/handwritten/engine.rs b/openssl-sys/src/handwritten/engine.rs index 2ed4da6f84..bf728cab08 100644 --- a/openssl-sys/src/handwritten/engine.rs +++ b/openssl-sys/src/handwritten/engine.rs @@ -20,7 +20,7 @@ pub const ENGINE_METHOD_PKEY_ASN1_METHS: u32 = 0x0400; pub const ENGINE_METHOD_EC: u32 = 0x0800; pub const ENGINE_METHOD_ALL: u32 = 0xffff; -pub const ENGINE_METHOD_NONE: u32 = 0xffff; +pub const ENGINE_METHOD_NONE: u32 = 0x0000; #[cfg(ossl110)] extern "C" { diff --git a/openssl/src/engine.rs b/openssl/src/engine.rs index 4576a90d6b..749f976fcb 100644 --- a/openssl/src/engine.rs +++ b/openssl/src/engine.rs @@ -792,46 +792,46 @@ impl Drop for Engine { } } -mod test { - use super::*; - - // #[test] - fn test_basic_engine_creation() { - let mut engine = Engine::new().unwrap(); - - let name = String::from("engine_name"); - let id = String::from("engine_id"); - - // there should not be errors on setting id or name - assert!(engine.set_id(&id).is_ok()); - assert!(engine.set_name(&name).is_ok()); - - assert_eq!(id, engine.get_id().unwrap().as_str()); - assert_eq!(name, engine.get_name().unwrap().as_str()); - } - - #[test] - fn iterate_through_engines() { - let mut engine = Engine::get_first().unwrap(); - - let mut has_engines = true; - let mut engine_cnt = 1; - - println!("Engines:"); - - while has_engines { - println!( - " {}, name={}, id={}", - engine_cnt, - engine.get_name().unwrap(), - engine.get_id().unwrap() - ); - match engine.get_next() { - Ok(e) => engine = e, - Err(_) => has_engines = false, - } - - engine_cnt += 1; - } - } -} +// mod test { +// use super::*; +// +// // #[test] +// fn test_basic_engine_creation() { +// let mut engine = Engine::new().unwrap(); +// +// let name = String::from("engine_name"); +// let id = String::from("engine_id"); +// +// // there should not be errors on setting id or name +// assert!(engine.set_id(&id).is_ok()); +// assert!(engine.set_name(&name).is_ok()); +// +// assert_eq!(id, engine.get_id().unwrap().as_str()); +// assert_eq!(name, engine.get_name().unwrap().as_str()); +// } +// +// #[test] +// fn iterate_through_engines() { +// let mut engine = Engine::get_first().unwrap(); +// +// let mut has_engines = true; +// let mut engine_cnt = 1; +// +// println!("Engines:"); +// +// while has_engines { +// println!( +// " {}, name={}, id={}", +// engine_cnt, +// engine.get_name().unwrap(), +// engine.get_id().unwrap() +// ); +// match engine.get_next() { +// Ok(e) => engine = e, +// Err(_) => has_engines = false, +// } +// +// engine_cnt += 1; +// } +// } +// }