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 15, 2024
1 parent 754c249 commit 9a542f1
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 9 deletions.
21 changes: 19 additions & 2 deletions ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,25 @@

set -ex

wait_for_service() {
while [ -z "$(pgrep parsec)" ]; do
sleep 1
done

sleep 5

# Check that Parsec successfully started and is running
pgrep parsec >/dev/null
}

pushd /tmp/parsec
./target/debug/parsec -c /tmp/parsec-openssl-provider/tests/configs/test_config.toml &
popd

wait_for_service

# Build parsec provider shared library
pushd parsec-openssl-provider-shared/ &&
pushd parsec-openssl-provider-shared
cargo build
popd

Expand All @@ -29,4 +46,4 @@ if [[ $test_string == $provider_load_result ]]; then
fi

echo "Loaded Provider has unexpected parameters!!!!"
exit 1
exit 1
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: 24 additions & 6 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,17 @@ pub unsafe fn parsec_provider_provider_init(
});

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

{
let err = PARSEC_PROVIDER_CTX.lock().unwrap();
if err.is_err() {
println!("{:?}", err);
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
22 changes: 22 additions & 0 deletions tests/configs/test_config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[core_settings]
allow_root = true
log_level = "error"
log_timestamp = true
log_error_details = true

[listener]
listener_type = "DomainSocket"
timeout = 200 # in milliseconds
socket_path = "/tmp/parsec.sock"

[authenticator]
auth_type = "UnixPeerCredentials"

[[key_manager]]
name = "on-disk-manager"
manager_type = "OnDisk"
store_path = "mappings"

[[provider]]
provider_type = "MbedCrypto"
key_info_manager = "on-disk-manager"
4 changes: 4 additions & 0 deletions tests/docker_image/parsec-openssl-provider-test.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ ENV PATH="/root/.cargo/bin:/opt/rust/bin:${PATH}"

# For running tests Parsec is configured with the socket in /tmp/
ENV PARSEC_SERVICE_ENDPOINT="unix:/tmp/parsec.sock"

RUN git clone https://github.com/parallaxsecond/parsec.git --branch 1.3.0 \
&& cd parsec \
&& cargo build --features "mbed-crypto-provider"

0 comments on commit 9a542f1

Please sign in to comment.