Skip to content

Commit

Permalink
add functions to use key from an engine
Browse files Browse the repository at this point in the history
  • Loading branch information
TheEnbyperor committed May 28, 2021
1 parent 7742686 commit 15ef5e0
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
6 changes: 6 additions & 0 deletions openssl-sys/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,9 @@ extern "C" {

pub fn CRYPTO_memcmp(a: *const c_void, b: *const c_void, len: size_t) -> c_int;
}

#[repr(C)]
pub struct CRYPTO_EX_DATA {
sk: *mut c_void,
dummy: c_int
}
62 changes: 62 additions & 0 deletions openssl-sys/src/engine.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use libc::*;
use *;

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 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 c_void, ui_method: *mut UI_METHOD, callback_data: *mut c_void
) -> c_int;
}

#[repr(C)]
pub struct UI_METHOD {
name: *const c_char,
ui_open_session: extern fn(ui: *mut UI) -> c_int,
ui_write_string: extern fn(ui: *mut UI, uis: *mut UI_STRING) -> c_int,
ui_flush: extern fn(ui: *mut UI) -> c_int,
ui_read_string: extern fn(ui: *mut UI, uis: *mut UI_STRING) -> c_int,
ui_close_session: extern fn(ui: *mut UI) -> c_int,
ui_construct_prompt: extern 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 struct UI {
meth: *const UI_METHOD,
strings: *mut c_void,
user_data: *mut c_void,
ex_data: CRYPTO_EX_DATA,
flags: c_int,
}

#[repr(C)]
pub struct UI_STRING {
string_type: UI_string_types,
out_string: *const c_char,
input_flags: c_int,
result_buf: *mut c_char,
}

#[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 @@ -29,6 +29,7 @@ pub use dtls1::*;
pub use ec::*;
pub use err::*;
pub use evp::*;
pub use engine::*;
pub use hmac::*;
pub use obj_mac::*;
pub use object::*;
Expand Down Expand Up @@ -66,6 +67,7 @@ mod dtls1;
mod ec;
mod err;
mod evp;
mod engine;
mod hmac;
mod obj_mac;
mod object;
Expand Down
2 changes: 2 additions & 0 deletions openssl-sys/src/ssl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,8 @@ extern "C" {
#[cfg(not(libressl))]
pub fn SSL_CTX_add_client_CA(ctx: *mut SSL_CTX, cacert: *mut X509) -> c_int;

pub fn SSL_CTX_set_client_cert_cb(ctx: *mut SSL_CTX, client_cert_cb: extern fn(ssl: *mut SSL, x509: *mut*mut X509, pkey: *mut*mut EVP_PKEY));

pub fn SSL_CTX_set_default_verify_paths(ctx: *mut SSL_CTX) -> c_int;
pub fn SSL_CTX_load_verify_locations(
ctx: *mut SSL_CTX,
Expand Down

0 comments on commit 15ef5e0

Please sign in to comment.