Skip to content

Commit 08a8327

Browse files
keymgmt: Implement Key Object Duplication
Implement: 1. OSSL_FUNC_KEYMGMT_DUP for key objects as indicated by https://www.openssl.org/docs/man3.0/man7/provider-keymgmt.html Signed-off-by: Tomás González <tomasagustin.gonzalezorlando@arm.com>
1 parent 707c01e commit 08a8327

File tree

1 file changed

+39
-6
lines changed
  • parsec-openssl-provider/src/keymgmt

1 file changed

+39
-6
lines changed

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

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
use crate::openssl_bindings::{
5-
OSSL_ALGORITHM, OSSL_DISPATCH, OSSL_FUNC_KEYMGMT_FREE, OSSL_FUNC_KEYMGMT_HAS,
6-
OSSL_FUNC_KEYMGMT_IMPORT, OSSL_FUNC_KEYMGMT_IMPORT_TYPES, OSSL_FUNC_KEYMGMT_MATCH,
7-
OSSL_FUNC_KEYMGMT_NEW, OSSL_FUNC_KEYMGMT_SETTABLE_PARAMS, OSSL_FUNC_KEYMGMT_SET_PARAMS,
8-
OSSL_FUNC_KEYMGMT_VALIDATE, OSSL_KEYMGMT_SELECT_OTHER_PARAMETERS, OSSL_PARAM,
9-
OSSL_PARAM_UTF8_PTR,
5+
OSSL_ALGORITHM, OSSL_DISPATCH, OSSL_FUNC_KEYMGMT_DUP, OSSL_FUNC_KEYMGMT_FREE,
6+
OSSL_FUNC_KEYMGMT_HAS, OSSL_FUNC_KEYMGMT_IMPORT, OSSL_FUNC_KEYMGMT_IMPORT_TYPES,
7+
OSSL_FUNC_KEYMGMT_MATCH, OSSL_FUNC_KEYMGMT_NEW, OSSL_FUNC_KEYMGMT_SETTABLE_PARAMS,
8+
OSSL_FUNC_KEYMGMT_SET_PARAMS, OSSL_FUNC_KEYMGMT_VALIDATE, OSSL_KEYMGMT_SELECT_OTHER_PARAMETERS,
9+
OSSL_PARAM, OSSL_PARAM_UTF8_PTR,
1010
};
1111
use crate::{
1212
ParsecProviderContext, PARSEC_PROVIDER_DESCRIPTION_RSA, PARSEC_PROVIDER_DFLT_PROPERTIES,
@@ -21,6 +21,16 @@ struct ParsecProviderKeyObject {
2121
key_name: Mutex<Option<String>>,
2222
}
2323

24+
impl Clone for ParsecProviderKeyObject {
25+
fn clone(&self) -> Self {
26+
let key_name = self.key_name.lock().unwrap();
27+
ParsecProviderKeyObject {
28+
provctx: self.provctx.clone(),
29+
key_name: Mutex::new(key_name.clone()),
30+
}
31+
}
32+
}
33+
2434
fn kmgmt_keyobj_new(provctx: Arc<ParsecProviderContext>) -> Arc<ParsecProviderKeyObject> {
2535
Arc::new(ParsecProviderKeyObject {
2636
provctx: provctx.clone(),
@@ -275,6 +285,27 @@ pub unsafe extern "C" fn parsec_provider_kmgmt_match(
275285
}
276286
}
277287

288+
/*
289+
should duplicate data subsets indicated by selection or the whole key data keydata_from and create a new provider side
290+
key object with the data.
291+
*/
292+
pub unsafe extern "C" fn parsec_provider_keymgmt_dup(
293+
keydata_from: VOID_PTR,
294+
selection: std::os::raw::c_int,
295+
) -> VOID_PTR {
296+
if selection & OSSL_KEYMGMT_SELECT_OTHER_PARAMETERS as std::os::raw::c_int != 0 {
297+
let keydata_from_ptr = keydata_from as *const ParsecProviderKeyObject;
298+
Arc::increment_strong_count(keydata_from_ptr);
299+
let arc_keydata_from = Arc::from_raw(keydata_from_ptr);
300+
301+
let duplicate: ParsecProviderKeyObject = (*arc_keydata_from).clone();
302+
Arc::into_raw(Arc::new(duplicate)) as VOID_PTR
303+
} else {
304+
std::ptr::null_mut()
305+
}
306+
}
307+
308+
pub type KeyMgmtDupPtr = unsafe extern "C" fn(VOID_PTR, std::os::raw::c_int) -> VOID_PTR;
278309
pub type KeyMgmtNewPtr = unsafe extern "C" fn(VOID_PTR) -> VOID_PTR;
279310
pub type KeyMgmtFreePtr = unsafe extern "C" fn(VOID_PTR);
280311
pub type KeyMgmtHasPtr = unsafe extern "C" fn(VOID_PTR, std::os::raw::c_int) -> std::os::raw::c_int;
@@ -289,6 +320,7 @@ pub type KeyMgmtValidatePtr =
289320
pub type KeyMgmtMatchPtr =
290321
unsafe extern "C" fn(VOID_PTR, VOID_PTR, std::os::raw::c_int) -> std::os::raw::c_int;
291322

323+
const OSSL_FUNC_KEYMGMT_DUP_PTR: KeyMgmtDupPtr = parsec_provider_keymgmt_dup;
292324
const OSSL_FUNC_KEYMGMT_NEW_PTR: KeyMgmtNewPtr = parsec_provider_kmgmt_new;
293325
const OSSL_FUNC_KEYMGMT_FREE_PTR: KeyMgmtFreePtr = parsec_provider_kmgmt_free;
294326
const OSSL_FUNC_KEYMGMT_HAS_PTR: KeyMgmtHasPtr = parsec_provider_kmgmt_has;
@@ -301,7 +333,8 @@ const OSSL_FUNC_KEYMGMT_SETTABLE_PARAMS_PTR: KeyMgmtSettableParamsPtr =
301333
const OSSL_FUNC_KEYMGMT_VALIDATE_PTR: KeyMgmtValidatePtr = parsec_provider_kmgmt_validate;
302334
const OSSL_FUNC_KEYMGMT_MATCH_PTR: KeyMgmtMatchPtr = parsec_provider_kmgmt_match;
303335

304-
const PARSEC_PROVIDER_RSA_KEYMGMT_IMPL: [OSSL_DISPATCH; 10] = [
336+
const PARSEC_PROVIDER_RSA_KEYMGMT_IMPL: [OSSL_DISPATCH; 11] = [
337+
unsafe { ossl_dispatch!(OSSL_FUNC_KEYMGMT_DUP, OSSL_FUNC_KEYMGMT_DUP_PTR) },
305338
unsafe { ossl_dispatch!(OSSL_FUNC_KEYMGMT_NEW, OSSL_FUNC_KEYMGMT_NEW_PTR) },
306339
unsafe { ossl_dispatch!(OSSL_FUNC_KEYMGMT_FREE, OSSL_FUNC_KEYMGMT_FREE_PTR) },
307340
unsafe { ossl_dispatch!(OSSL_FUNC_KEYMGMT_HAS, OSSL_FUNC_KEYMGMT_HAS_PTR) },

0 commit comments

Comments
 (0)