Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extern C functions for ENGINE to use hardware private keys #1480

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions openssl-sys/src/engine.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
use libc::*;
use crate::{ENGINE, EVP_PKEY, SSL, stack_st_X509, stack_st_X509_NAME, X509};

extern "C" {
pub fn ENGINE_load_builtin_engines();
pub fn ENGINE_by_id(id: *const c_char) -> *mut ENGINE;

pub fn ENGINE_init(e: *mut ENGINE) -> c_int;
pub fn ENGINE_finish(e: *mut ENGINE) -> c_int;
pub fn ENGINE_free(e: *mut ENGINE) -> c_int;

pub fn ENGINE_ctrl_cmd(
e: *mut ENGINE,
cmd_name: *const c_char,
i: c_long,
p: *mut c_void,
f: extern "C" fn() -> (),
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_load_private_key(
e: *mut ENGINE,
key_id: *const c_char,
ui_method: *mut UI_METHOD,
callback_data: *mut c_void,
) -> *mut EVP_PKEY;
pub fn ENGINE_load_public_key(
e: *mut ENGINE,
key_id: *const c_char,
ui_method: *mut UI_METHOD,
callback_data: *mut c_void,
) -> *mut EVP_PKEY;
pub fn ENGINE_load_ssl_client_cert(
e: *mut ENGINE,
ssl: *mut SSL,
ca_dn: *mut stack_st_X509_NAME,
pcert: *mut *mut X509,
ppkey: *mut *mut EVP_PKEY,
pother: *mut *mut stack_st_X509,
ui_method: *mut UI_METHOD,
callback_data: *mut c_void,
) -> c_int;

pub fn UI_set_default_method(meth: *const UI_METHOD);
pub fn UI_get_default_method() -> *const UI_METHOD;
pub fn UI_get_method(ui: *mut UI) -> *const UI_METHOD;
pub fn UI_set_method(ui: *mut UI, meth: *const UI_METHOD) -> *const UI_METHOD;

pub fn UI_OpenSSL() -> *mut UI_METHOD;
pub fn UI_null() -> *const UI_METHOD;
}

type UI = c_int;
type UI_STRING = c_int;

pub enum UI_METHOD {}

// #[repr(C)]
// pub struct UI_METHOD {
// name: *const c_char,
// ui_open_session: extern "C" fn(ui: *mut UI) -> c_int,
// ui_write_string: extern "C" fn(ui: *mut UI, uis: *mut UI_STRING) -> c_int,
// ui_flush: extern "C" fn(ui: *mut UI) -> c_int,
// ui_read_string: extern "C" fn(ui: *mut UI, uis: *mut UI_STRING) -> c_int,
// ui_close_session: extern "C" fn(ui: *mut UI) -> c_int,
// ui_construct_prompt: extern "C" fn(
// ui: *mut UI,
// object_desc: *const c_char,
// object_name: *const c_char,
// ) -> *mut c_char,
// }

const UI_FLAG_REDOABLE: c_int = 0x0001;
const UI_FLAG_PRINT_ERRORS: c_int = 0x0100;

#[repr(C)]
pub enum UI_string_types {
UIT_NONE = 0,
UIT_PROMPT,
UIT_VERIFY,
UIT_BOOLEAN,
UIT_INFO,
UIT_ERROR,
}
2 changes: 2 additions & 0 deletions openssl-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ mod openssl {
pub use self::x509::*;
pub use self::x509_vfy::*;
pub use self::x509v3::*;
pub use self::engine::*;

#[macro_use]
mod macros;
Expand Down Expand Up @@ -96,6 +97,7 @@ mod openssl {
mod x509;
mod x509_vfy;
mod x509v3;
mod engine;

use std::sync::Once;
// explicitly initialize to work around https://github.com/openssl/openssl/issues/3505
Expand Down
Loading