Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
232 changes: 123 additions & 109 deletions Cargo.lock

Large diffs are not rendered by default.

27 changes: 2 additions & 25 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,41 +38,18 @@ incremental = false
opt-level = 0

[workspace.dependencies]
actix-rt = "2.10"
actix-server = { version = "2.5", default-features = false }
actix-web = { version = "4.9.0", default-features = false }
base64 = "0.21"
chrono = "0.4"
clap = { version = "4.5", default-features = false }
cloudproof = "3.0"
cosmian_kms_cli = { git = "https://www.github.com/Cosmian/kms", branch = "develop" }
cosmian_findex_cli = { git = "https://www.github.com/Cosmian/findex-server", branch = "develop" }
cosmian_config_utils = { git = "https://www.github.com/Cosmian/http_client_server", branch = "develop" }
cosmian_http_client = { git = "https://www.github.com/Cosmian/http_client_server", branch = "develop" }
cosmian_logger = { git = "https://www.github.com/Cosmian/http_client_server", branch = "develop" }
der = { version = "0.7", default-features = false }
env_logger = "0.11"
hex = { version = "0.4", default-features = false }
leb128 = "0.2.5"
native-tls = "0.2"
num_cpus = "1.13"
num-bigint-dig = { version = "0.8", default-features = false }
openssl = { version = "0.10", default-features = false }
pem = "3.0"
pyo3 = { version = "0.20", default-features = false }
reqwest = { version = "0.11", default-features = false }
rustls = "0.21"
serde = "1.0"
serde_json = "1.0"
sha3 = { version = "0.10", default-features = false }
strum = { version = "0.25", default-features = false }
thiserror = "1.0"
time = "0.3"
tokio = { version = "1.39", default-features = false }
tracing-subscriber = { version = "0.3", default-features = false }
tokio = { version = "1.42", default-features = false }
tracing = "0.1"
url = "2.5"
uuid = "1.10"
x509-cert = { version = "0.2.5", default-features = false }
uuid = "1.11"
x509-parser = "0.16"
zeroize = { version = "1.8", default-features = false }
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ docker run -p 9998:9998 --rm --name kms ghcr.io/cosmian/kms
```

> [!NOTE]:
> The KMS server can also be installed using these [instructions](https://docs.cosmian./key_management_system/installation).
> The KMS server can also be installed using these [instructions](https://docs.cosmian.com/key_management_system/single_server_mode/#quick-start).

In the same manner, you can run a Findex server (using Docker image) on `http://localhost:6668`:

Expand Down
10 changes: 5 additions & 5 deletions crate/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ cosmian_kms_cli = { workspace = true }
cosmian_findex_cli = { workspace = true }
cosmian_config_utils = { workspace = true }
cosmian_logger = { workspace = true }
csv = "1.3.0"
csv = "1.3.1"
hex = { workspace = true }
thiserror = { workspace = true }
serde = { workspace = true }
Expand All @@ -45,14 +45,14 @@ url = { workspace = true }
uuid = { workspace = true }

[dev-dependencies]
actix-rt = { workspace = true }
actix-server = { workspace = true }
actix-rt = "2.10"
actix-server = { version = "2.5", default-features = false }
assert_cmd = "2.0"
const-oid = { version = "0.9", features = ["db"] }
openssl = { workspace = true }
predicates = "3.1"
regex = { version = "1.10", default-features = false }
tempfile = "3.11"
regex = { version = "1.11", default-features = false }
tempfile = "3.14"
x509-parser = { workspace = true, features = ["verify"] }

# ------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion crate/cli/src/actions/delete_datasets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct DeleteDatasetAction {

impl DeleteDatasetAction {
#[allow(clippy::future_not_send, clippy::print_stdout)]
pub(crate) async fn run(&self, findex_rest_client: FindexRestClient) -> CosmianResult<()> {
pub(crate) async fn run(&self, findex_rest_client: &FindexRestClient) -> CosmianResult<()> {
let uuids = Uuids::from(self.uuid.clone());
findex_rest_client
.delete_entries(&self.index_id, &uuids)
Expand Down
2 changes: 1 addition & 1 deletion crate/cli/src/actions/encrypt_and_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ impl EncryptAndIndexAction {
#[allow(clippy::future_not_send, clippy::print_stdout)]
pub async fn run(
&self,
findex_rest_client: FindexRestClient,
findex_rest_client: &FindexRestClient,
kms_rest_client: &KmsClient,
) -> CosmianResult<()> {
let nonce = self
Expand Down
3 changes: 2 additions & 1 deletion crate/cli/src/actions/findex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ pub enum FindexActions {

impl FindexActions {
/// Combine Findex with KMS encryption
///
/// # Errors
/// Returns an error if the action fails
#[allow(clippy::future_not_send)]
pub async fn run(
&self,
findex_rest_client: FindexRestClient,
findex_rest_client: &mut FindexRestClient,
kms_rest_client: &KmsClient,
) -> CosmianResult<()> {
match self {
Expand Down
29 changes: 14 additions & 15 deletions crate/cli/src/actions/search_and_decrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,22 @@ impl SearchAndDecryptAction {
#[allow(clippy::future_not_send, clippy::print_stdout)]
pub(crate) async fn run(
&self,
findex_rest_client: FindexRestClient,
findex_rest_client: &FindexRestClient,
kms_rest_client: &KmsClient,
) -> CosmianResult<()> {
let results =
instantiate_findex(findex_rest_client.clone(), &self.findex_parameters.index_id)
.await?
.search(
&self.findex_parameters.user_key()?,
&self.findex_parameters.label(),
self.keyword
.clone()
.into_iter()
.map(|word| Keyword::from(word.as_bytes()))
.collect::<Keywords>(),
&|_| async move { Ok(false) },
)
.await?;
let results = instantiate_findex(findex_rest_client, &self.findex_parameters.index_id)
.await?
.search(
&self.findex_parameters.user_key()?,
&self.findex_parameters.label(),
self.keyword
.clone()
.into_iter()
.map(|word| Keyword::from(word.as_bytes()))
.collect::<Keywords>(),
&|_| async move { Ok(false) },
)
.await?;
trace!("Index search results: {results}");

let mut uuids = Vec::new();
Expand Down
87 changes: 48 additions & 39 deletions crate/cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::path::PathBuf;

use clap::{CommandFactory, Parser, Subcommand};
use cosmian_config_utils::ConfigUtils;
use cosmian_findex_cli::reexports::cosmian_findex_client::FindexRestClient;
use cosmian_findex_cli::{CoreFindexActions, reexports::cosmian_findex_client::FindexRestClient};
use cosmian_kms_cli::{KmsActions, reexport::cosmian_kms_client::KmsClient};
use cosmian_logger::log_init;
use tracing::{info, trace};
Expand All @@ -19,10 +19,10 @@ use crate::{
pub struct Cli {
/// Configuration file location
///
/// This is an alternative to the env variable `KMS_CLI_CONF`.
/// Takes precedence over `KMS_CLI_CONF` env variable.
#[arg(short, long)]
conf: Option<PathBuf>,
/// This is an alternative to the env variable `COSMIAN_CLI_CONF_PATH`.
/// Takes precedence over `COSMIAN_CLI_CONF_PATH` env variable.
#[arg(short, env = "COSMIAN_CLI_CONF_PATH", long)]
conf_path: Option<PathBuf>,

#[command(subcommand)]
pub command: CliCommands,
Expand All @@ -36,12 +36,12 @@ pub struct Cli {
/// `accept_invalid_certs` is useful if the CLI needs to connect to an HTTPS KMS server
/// running an invalid or insecure SSL certificate
#[arg(long)]
pub kms_accept_invalid_certs: Option<bool>,
pub kms_accept_invalid_certs: bool,

/// Output the KMS JSON KMIP request and response.
/// This is useful to understand JSON POST requests and responses
/// required to programmatically call the KMS on the `/kmip/2_1` endpoint
#[arg(long, default_value = "false")]
#[arg(long)]
pub kms_print_json: bool,

/// The URL of the Findex server
Expand All @@ -53,7 +53,7 @@ pub struct Cli {
/// `accept_invalid_certs` is useful if the CLI needs to connect to an HTTPS KMS server
/// running an invalid or insecure SSL certificate
#[arg(long)]
pub findex_accept_invalid_certs: Option<bool>,
pub findex_accept_invalid_certs: bool,
}

#[derive(Subcommand)]
Expand Down Expand Up @@ -84,65 +84,74 @@ pub enum CliCommands {
/// - The command-line arguments cannot be parsed.
/// - The configuration file cannot be located or loaded.
/// - Any of the subcommands fail during their execution.
#[allow(clippy::future_not_send)]
#[allow(clippy::future_not_send, clippy::cognitive_complexity)]
pub async fn cosmian_main() -> CosmianResult<()> {
log_init(None);
info!("Starting Cosmian CLI");
let cli = Cli::parse();

let conf_path = ClientConf::location(cli.conf)?;
let mut conf = ClientConf::from_toml(&conf_path)?;
let conf_path = ClientConf::location(cli.conf_path)?;
let mut config = ClientConf::from_toml(&conf_path)?;

// Override the configuration with the CLI arguments
let mut has_been_overridden = false;
// Handle KMS configuration
if let Some(url) = cli.kms_url.clone() {
conf.kms_config.http_config.server_url = url;
has_been_overridden = true;
config.kms_config.http_config.server_url = url;
}
if let Some(accept_invalid_certs) = cli.kms_accept_invalid_certs {
conf.kms_config.http_config.accept_invalid_certs = accept_invalid_certs;
has_been_overridden = true;
if cli.kms_accept_invalid_certs {
config.kms_config.http_config.accept_invalid_certs = true;
}
if let Some(url) = cli.findex_url.clone() {
if let Some(findex_conf) = conf.findex_config.as_mut() {
findex_conf.http_config.server_url = url;
has_been_overridden = true;
config.kms_config.print_json = Some(cli.kms_print_json);

// Handle Findex server configuration
if let Some(findex_config) = config.findex_config.as_mut() {
if let Some(url) = cli.findex_url.clone() {
findex_config.http_config.server_url = url;
}
}
if let Some(accept_invalid_certs) = cli.findex_accept_invalid_certs {
if let Some(findex_conf) = conf.findex_config.as_mut() {
findex_conf.http_config.accept_invalid_certs = accept_invalid_certs;
has_been_overridden = true;
if cli.findex_accept_invalid_certs {
findex_config.http_config.accept_invalid_certs = true;
}
}
conf.kms_config.print_json = Some(cli.kms_print_json);
if has_been_overridden {
conf.to_toml(&conf_path)?;
}

trace!("Configuration: {conf:?}");
trace!("Configuration: {config:?}");

// Instantiate the KMS and Findex clients
let kms_rest_client = KmsClient::new(conf.kms_config)?;
// Instantiate the KMS client
let mut kms_rest_client = KmsClient::new(config.kms_config.clone())?;

match cli.command {
match &cli.command {
CliCommands::Markdown(action) => {
let command = <Cli as CommandFactory>::command();
action.process(&command)?;
return Ok(())
}
CliCommands::Kms(kms_actions) => {
kms_actions.process(&kms_rest_client).await?;
kms_actions.process(&mut kms_rest_client).await?;
config.kms_config = kms_rest_client.config.clone();
}
CliCommands::FindexServer(findex_actions) => {
let findex_config = conf.findex_config.ok_or_else(|| {
let findex_config = config.findex_config.as_ref().ok_or_else(|| {
cli_error!("Findex server configuration is missing in the configuration file")
})?;
let findex_rest_client = FindexRestClient::new(findex_config)?;
let mut findex_rest_client = FindexRestClient::new(findex_config.clone())?;
findex_actions
.run(findex_rest_client, &kms_rest_client)
.run(&mut findex_rest_client, &kms_rest_client)
.await?;
config.findex_config = Some(findex_rest_client.config.clone());
}
}

// Save the configuration
match cli.command {
CliCommands::Kms(KmsActions::Login(_) | KmsActions::Logout(_)) => {
config.to_toml(&conf_path)?;
info!("Saving configuration to: {conf_path:?}");
}
CliCommands::FindexServer(FindexActions::Findex(
CoreFindexActions::Login(_) | CoreFindexActions::Logout(_),
)) => {
config.to_toml(&conf_path)?;
info!("Saving configuration to: {conf_path:?}");
}
_ => {}
}

Ok(())
Expand Down
1 change: 0 additions & 1 deletion crate/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
future_incompatible,
keyword_idents,
let_underscore,
// rust_2024_compatibility,
unreachable_pub,
unused,
clippy::all,
Expand Down
6 changes: 3 additions & 3 deletions crate/gui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ test = false
fips = ["cosmian_cli/fips"]

[dependencies]
clap = "4.4"
clap = "4.5"
cosmian_cli = { path = "../cli" }
klask = { git = "https://github.com/Cosmian/klask.git" }
tokio = { version = "1.34", features = ["full"] }
tokio = { workspace = true, features = ["full"] }

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3.5", features = ["winnt", "winuser"] }
winapi = { version = "0.3.9", features = ["winnt", "winuser"] }
Loading
Loading