Skip to content

Commit

Permalink
Add Parsec Basic Client
Browse files Browse the repository at this point in the history
Make the Parsec Provider context have a reference to an instance of
a Parsec Basic Client. This client will be used for any operation
requests coming from the Parsec Provider.

Signed-off-by: Tomás González <[email protected]>
  • Loading branch information
tgonzalezorlandoarm committed Feb 14, 2024
1 parent 754c249 commit a87adb6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
4 changes: 3 additions & 1 deletion parsec-openssl-provider/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ categories = ["cryptography", "hardware-support"]
edition = "2021"

[dependencies]
lazy_static = "1.4.0"
log = "0.4"
parsec-client = { git = "https://github.com/parallaxsecond/parsec-client-rust", tag="0.16.0" }
parsec-openssl2 = { path = "../parsec-openssl2" }
openssl-errors = "0.2.0"
log = "0.4"
30 changes: 25 additions & 5 deletions parsec-openssl-provider/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2023 Contributors to the Parsec project.
// SPDX-License-Identifier: Apache-2.0
use std::mem;
use std::sync::Mutex;

pub use parsec_openssl2::*;
pub use openssl_errors::*;
Expand All @@ -11,9 +12,17 @@ use provider::*;
mod catch;
use catch::r#catch;

// The init function populates the dispatch table and returns a NULL pointer
// to the provider context. This needs to be changed when key management and
// crypto support is added to the provider.
use parsec_client::error::Result as ClientResult;
use parsec_client::BasicClient;

const PROJECT_NAME: &str = env!("CARGO_PKG_NAME");

lazy_static::lazy_static! {
static ref PARSEC_PROVIDER_CTX: Mutex<ClientResult<BasicClient>> = Mutex::new(BasicClient::new(Some(PROJECT_NAME.to_string())));
}

// The init function populates the dispatch table and returns a void pointer
// to the provider context (which contains the parsec basic client).
pub unsafe fn parsec_provider_provider_init(
_handle: *const OSSL_CORE_HANDLE,
_in_: *const OSSL_DISPATCH,
Expand Down Expand Up @@ -49,8 +58,18 @@ pub unsafe fn parsec_provider_provider_init(
});

*out = DISPATCH_TABLE.as_ptr();
*provctx = std::ptr::null_mut();

{
let _ = r#catch(Some(|| Error::PROVIDER_INIT), || {
if (*PARSEC_PROVIDER_CTX.lock().unwrap()).is_err() {
Err(Openssl2Error::SysReturnedNull {
inner: ErrorStack::get(),
})?;
}
Ok(OPENSSL_SUCCESS)
});
}
let ptr: *const Mutex<ClientResult<BasicClient>> = &*PARSEC_PROVIDER_CTX;
*provctx = ptr as VOID_PTR;
Ok(())
}

Expand All @@ -61,6 +80,7 @@ openssl_errors! {
PROVIDER_GETTABLE_PARAMS("parsec_provider_gettable_params");
PROVIDER_GET_PARAMS("parsec_provider_get_params");
PROVIDER_QUERY("parsec_provider_query");
PROVIDER_INIT("parsec_provider_init");
}

reasons {
Expand Down
1 change: 1 addition & 0 deletions parsec-openssl2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use openssl2::{openssl_returns_1, openssl_returns_nonnull};
pub use openssl_sys::*;
pub use parsec_openssl_sys2::*;
pub use openssl::error::ErrorStack;

mod types;
pub use types::*;
Expand Down

0 comments on commit a87adb6

Please sign in to comment.