Skip to content

Commit

Permalink
keymgmt: Add Key Objects import types
Browse files Browse the repository at this point in the history
Implement:

1. OSSL_FUNC_KEYMGMT_IMPORT_TYPES

for key objects as indicated by
https://www.openssl.org/docs/man3.0/man7/provider-keymgmt.html

Signed-off-by: Tomás González <[email protected]>
  • Loading branch information
tgonzalezorlandoarm committed Mar 11, 2024
1 parent 4e75a16 commit eacc74f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
37 changes: 34 additions & 3 deletions parsec-openssl-provider/src/keymgmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

use crate::openssl_binding::{
OSSL_ALGORITHM, OSSL_DISPATCH, OSSL_FUNC_KEYMGMT_FREE, OSSL_FUNC_KEYMGMT_IMPORT,
OSSL_FUNC_KEYMGMT_NEW, OSSL_FUNC_KEYMGMT_SETTABLE_PARAMS, OSSL_FUNC_KEYMGMT_SET_PARAMS,
OSSL_KEYMGMT_SELECT_OTHER_PARAMETERS, OSSL_PARAM, OSSL_PARAM_UTF8_PTR,
OSSL_FUNC_KEYMGMT_IMPORT_TYPES, OSSL_FUNC_KEYMGMT_NEW, OSSL_FUNC_KEYMGMT_SETTABLE_PARAMS,
OSSL_FUNC_KEYMGMT_SET_PARAMS, OSSL_KEYMGMT_SELECT_OTHER_PARAMETERS, OSSL_PARAM,
OSSL_PARAM_UTF8_PTR,
};
use crate::ParsecProviderContext;
use parsec_openssl2::types::VOID_PTR;
Expand Down Expand Up @@ -111,25 +112,55 @@ pub unsafe extern "C" fn parsec_provider_kmgmt_import(
1
}

/*
should return an array of descriptor OSSL_PARAM for data indicated by selection, for parameters that
OSSL_FUNC_keymgmt_import() can handle
*/
pub unsafe extern "C" fn parsec_provider_kmgmt_import_types(
selection: std::os::raw::c_int,
) -> *const OSSL_PARAM {
if selection & OSSL_KEYMGMT_SELECT_OTHER_PARAMETERS as std::os::raw::c_int != 0 {
static ONCE_INIT: std::sync::Once = std::sync::Once::new();
static mut IMPORT_TYPES_TABLE: [OSSL_PARAM; 1] = [parsec_openssl2::ossl_param!(); 1];

ONCE_INIT.call_once(|| {
IMPORT_TYPES_TABLE = [ossl_param!(PARSEC_PROVIDER_KEY_NAME, OSSL_PARAM_UTF8_PTR)];
});

IMPORT_TYPES_TABLE.as_ptr()
} else {
std::ptr::null_mut()
}
}

pub type KeyMgmtNewPtr = unsafe extern "C" fn(VOID_PTR) -> VOID_PTR;
pub type KeyMgmtFreePtr = unsafe extern "C" fn(VOID_PTR);
pub type KeyMgmtImportPtr =
unsafe extern "C" fn(VOID_PTR, std::os::raw::c_int, *mut OSSL_PARAM) -> std::os::raw::c_int;
pub type KeyMgmtImportTypesPtr = unsafe extern "C" fn(std::os::raw::c_int) -> *const OSSL_PARAM;
pub type KeyMgmtSetParamsPtr =
unsafe extern "C" fn(VOID_PTR, *mut OSSL_PARAM) -> std::os::raw::c_int;
pub type KeyMgmtSettableParamsPtr = unsafe extern "C" fn(VOID_PTR) -> *const OSSL_PARAM;

const OSSL_FUNC_KEYMGMT_NEW_PTR: KeyMgmtNewPtr = parsec_provider_kmgmt_new;
const OSSL_FUNC_KEYMGMT_FREE_PTR: KeyMgmtFreePtr = parsec_provider_kmgmt_free;
const OSSL_FUNC_KEYMGMT_IMPORT_PTR: KeyMgmtImportPtr = parsec_provider_kmgmt_import;
const OSSL_FUNC_KEYMGMT_IMPORT_TYPES_PTR: KeyMgmtImportTypesPtr =
parsec_provider_kmgmt_import_types;
const OSSL_FUNC_KEYMGMT_SET_PARAMS_PTR: KeyMgmtSetParamsPtr = parsec_provider_kmgmt_set_params;
const OSSL_FUNC_KEYMGMT_SETTABLE_PARAMS_PTR: KeyMgmtSettableParamsPtr =
parsec_provider_kmgmt_settable_params;

const PARSEC_PROVIDER_RSA_KEYMGMT_IMPL: [OSSL_DISPATCH; 5] = [
const PARSEC_PROVIDER_RSA_KEYMGMT_IMPL: [OSSL_DISPATCH; 6] = [
unsafe { ossl_dispatch!(OSSL_FUNC_KEYMGMT_NEW, OSSL_FUNC_KEYMGMT_NEW_PTR) },
unsafe { ossl_dispatch!(OSSL_FUNC_KEYMGMT_FREE, OSSL_FUNC_KEYMGMT_FREE_PTR) },
unsafe { ossl_dispatch!(OSSL_FUNC_KEYMGMT_IMPORT, OSSL_FUNC_KEYMGMT_IMPORT_PTR) },
unsafe {
ossl_dispatch!(
OSSL_FUNC_KEYMGMT_IMPORT_TYPES,
OSSL_FUNC_KEYMGMT_IMPORT_TYPES_PTR
)
},
unsafe {
ossl_dispatch!(
OSSL_FUNC_KEYMGMT_SET_PARAMS,
Expand Down
1 change: 1 addition & 0 deletions parsec-openssl-sys2/src/c/openssl.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

/* Import and export functions, with discovery */
#define OSSL_FUNC_KEYMGMT_IMPORT 40
#define OSSL_FUNC_KEYMGMT_IMPORT_TYPES 41
#define OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS 12
#define OSSL_FUNC_KEYMGMT_SET_PARAMS 13
#define OSSL_FUNC_KEYMGMT_SETTABLE_PARAMS 14
Expand Down

0 comments on commit eacc74f

Please sign in to comment.