Skip to content

Commit 64e7c58

Browse files
committed
kmgmt: Add gettable and get params
Signed-off-by: Gowtham Suresh Kumar <[email protected]>
1 parent 42255fd commit 64e7c58

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

parsec-openssl-provider/src/keymgmt/mod.rs

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,59 @@ pub unsafe extern "C" fn parsec_provider_kmgmt_settable_params(
100100
KEYMGMT_TABLE.as_ptr()
101101
}
102102

103+
/*
104+
should return a constant array of descriptor OSSL_PARAM, for parameters that OSSL_FUNC_keymgmt_get_params() can handle
105+
*/
106+
pub unsafe extern "C" fn parsec_provider_kmgmt_gettable_params(
107+
_provctx: VOID_PTR,
108+
) -> *const OSSL_PARAM {
109+
static ONCE_INIT: std::sync::Once = std::sync::Once::new();
110+
static mut KEYMGMT_GETTABLE_TABLE: [OSSL_PARAM; 4] = [ossl_param!(); 4];
111+
112+
ONCE_INIT.call_once(|| {
113+
KEYMGMT_GETTABLE_TABLE = [
114+
ossl_param!(OSSL_PKEY_PARAM_BITS, OSSL_PARAM_INTEGER),
115+
ossl_param!(OSSL_PKEY_PARAM_SECURITY_BITS, OSSL_PARAM_INTEGER),
116+
ossl_param!(OSSL_PKEY_PARAM_MAX_SIZE, OSSL_PARAM_INTEGER),
117+
ossl_param!(),
118+
];
119+
});
120+
KEYMGMT_GETTABLE_TABLE.as_ptr()
121+
}
122+
123+
/*
124+
should extract information data associated with the given keydata
125+
*/
126+
pub unsafe extern "C" fn parsec_provider_kmgmt_get_params(
127+
keydata: VOID_PTR,
128+
params: *mut OSSL_PARAM,
129+
) -> std::os::raw::c_int {
130+
let result = super::r#catch(Some(|| super::Error::PROVIDER_KEYMGMT_GET_PARAMS), || {
131+
if keydata.is_null() || params.is_null() {
132+
Err("Null pointer received as parameter".into())
133+
} else {
134+
Arc::increment_strong_count(keydata as *const RwLock<ParsecProviderKeyObject>);
135+
let key_data = Arc::from_raw(keydata as *const RwLock<ParsecProviderKeyObject>);
136+
let reader_key_data = key_data.read().unwrap();
137+
138+
if let Some(public_key) = reader_key_data.get_rsa_key() {
139+
let modulus = public_key.modulus.as_unsigned_bytes_be();
140+
141+
locate_and_set_int_param(OSSL_PKEY_PARAM_BITS, modulus.len() * 8, params)?;
142+
locate_and_set_int_param(OSSL_PKEY_PARAM_SECURITY_BITS, 112, params)?;
143+
locate_and_set_int_param(OSSL_PKEY_PARAM_MAX_SIZE, modulus.len(), params)?;
144+
}
145+
146+
Ok(OPENSSL_SUCCESS)
147+
}
148+
});
149+
150+
match result {
151+
Ok(result) => result,
152+
Err(()) => OPENSSL_ERROR,
153+
}
154+
}
155+
103156
// should update information data associated with the given keydata
104157
pub unsafe extern "C" fn parsec_provider_kmgmt_set_params(
105158
keydata: VOID_PTR,
@@ -384,7 +437,11 @@ pub type KeyMgmtImportPtr =
384437
pub type KeyMgmtImportTypesPtr = unsafe extern "C" fn(std::os::raw::c_int) -> *const OSSL_PARAM;
385438
pub type KeyMgmtSetParamsPtr =
386439
unsafe extern "C" fn(VOID_PTR, *mut OSSL_PARAM) -> std::os::raw::c_int;
440+
pub type KeyMgmtGetParamsPtr =
441+
unsafe extern "C" fn(VOID_PTR, *mut OSSL_PARAM) -> std::os::raw::c_int;
387442
pub type KeyMgmtSettableParamsPtr = unsafe extern "C" fn(VOID_PTR) -> *const OSSL_PARAM;
443+
pub type KeyMgmtGettableParamsPtr = unsafe extern "C" fn(VOID_PTR) -> *const OSSL_PARAM;
444+
388445
pub type KeyMgmtMatchPtr =
389446
unsafe extern "C" fn(VOID_PTR, VOID_PTR, std::os::raw::c_int) -> std::os::raw::c_int;
390447

@@ -396,11 +453,15 @@ const OSSL_FUNC_KEYMGMT_IMPORT_PTR: KeyMgmtImportPtr = parsec_provider_kmgmt_imp
396453
const OSSL_FUNC_KEYMGMT_IMPORT_TYPES_PTR: KeyMgmtImportTypesPtr =
397454
parsec_provider_kmgmt_import_types;
398455
const OSSL_FUNC_KEYMGMT_SET_PARAMS_PTR: KeyMgmtSetParamsPtr = parsec_provider_kmgmt_set_params;
456+
const OSSL_FUNC_KEYMGMT_GET_PARAMS_PTR: KeyMgmtGetParamsPtr = parsec_provider_kmgmt_get_params;
399457
const OSSL_FUNC_KEYMGMT_SETTABLE_PARAMS_PTR: KeyMgmtSettableParamsPtr =
400458
parsec_provider_kmgmt_settable_params;
459+
const OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS_PTR: KeyMgmtGettableParamsPtr =
460+
parsec_provider_kmgmt_gettable_params;
461+
401462
const OSSL_FUNC_KEYMGMT_MATCH_PTR: KeyMgmtMatchPtr = parsec_provider_kmgmt_match;
402463

403-
const PARSEC_PROVIDER_KEYMGMT_IMPL: [OSSL_DISPATCH; 10] = [
464+
const PARSEC_PROVIDER_KEYMGMT_IMPL: [OSSL_DISPATCH; 13] = [
404465
unsafe { ossl_dispatch!(OSSL_FUNC_KEYMGMT_DUP, OSSL_FUNC_KEYMGMT_DUP_PTR) },
405466
unsafe { ossl_dispatch!(OSSL_FUNC_KEYMGMT_NEW, OSSL_FUNC_KEYMGMT_NEW_PTR) },
406467
unsafe { ossl_dispatch!(OSSL_FUNC_KEYMGMT_FREE, OSSL_FUNC_KEYMGMT_FREE_PTR) },
@@ -430,6 +491,18 @@ const PARSEC_PROVIDER_KEYMGMT_IMPL: [OSSL_DISPATCH; 10] = [
430491
OSSL_FUNC_KEYMGMT_SETTABLE_PARAMS_PTR
431492
)
432493
},
494+
unsafe {
495+
ossl_dispatch!(
496+
OSSL_FUNC_KEYMGMT_GET_PARAMS,
497+
OSSL_FUNC_KEYMGMT_GET_PARAMS_PTR
498+
)
499+
},
500+
unsafe {
501+
ossl_dispatch!(
502+
OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS,
503+
OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS_PTR
504+
)
505+
},
433506
unsafe { ossl_dispatch!(OSSL_FUNC_KEYMGMT_MATCH, OSSL_FUNC_KEYMGMT_MATCH_PTR) },
434507
ossl_dispatch!(),
435508
];

parsec-openssl-provider/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ openssl_errors::openssl_errors! {
115115
PROVIDER_KEYMGMT_IMPORT("parsec_provider_kmgmt_import");
116116
PROVIDER_KEYMGMT_MATCH("parsec_provider_kmgmt_match");
117117
PROVIDER_KEYMGMT_SET_PARAMS("parsec_provider_kmgmt_set_params");
118+
PROVIDER_KEYMGMT_GET_PARAMS("parsec_provider_kmgmt_get_params");
118119
PROVIDER_KEYMGMT_VALIDATE("parsec_provider_kmgmt_validate");
119120
PROVIDER_QUERY("parsec_provider_query");
120121
PROVIDER_SIGNATURE_SIGN("parsec_provider_signature_sign");

0 commit comments

Comments
 (0)