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, so that it gets redirected
to the Parsec Service.

Signed-off-by: Tomás González <[email protected]>
  • Loading branch information
tgonzalezorlandoarm committed Feb 15, 2024
1 parent 754c249 commit f5a8bf6
Show file tree
Hide file tree
Showing 3 changed files with 28 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"
29 changes: 24 additions & 5 deletions parsec-openssl-provider/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
// 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::*;
pub use parsec_openssl2::*;

mod provider;
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 ctx_success = {
PARSEC_PROVIDER_CTX.lock().unwrap()
};
if ctx_success.is_err() {
log::error!("[Provider Context Error]: {:?}", ctx_success);
return Err(Openssl2Error::SysReturnedNull {
inner: ErrorStack::get(),
});
}

let ptr: *const Mutex<ClientResult<BasicClient>> = &*PARSEC_PROVIDER_CTX;
*provctx = ptr as VOID_PTR;
Ok(())
}

Expand Down
1 change: 1 addition & 0 deletions parsec-openssl2/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

pub use openssl::error::ErrorStack;
use openssl2::{openssl_returns_1, openssl_returns_nonnull};
pub use openssl_sys::*;
pub use parsec_openssl_sys2::*;
Expand Down

0 comments on commit f5a8bf6

Please sign in to comment.