* attempt at vendoring openssl for josekit * update readme * Try without vendored for josekit in client * more doc for windows * ci: Run binaries in clean env also in debug mode (#215) * ci: run binaries in clean env. also in debug mode * ci: increase size of tmp files * ci: test ckms without openssl * ci: test ckms without openssl * ci: fix windows build * ci: only build server just after openssl build * fix(ckms): remove println on CreateKeyPairAction * added pkcs11 provider * refactored export and import into the client * refactored encodings to client * unused deps * move logging init to pkcs11 * key data objects * batching exports * batch operations beta * refactoing of tests * fixed tests * fixed test server * code beta * switching to the git version of native-pkcs11 * cargo fmt * pyo3 fix * license reference fix * rlib fix * native-pkcs11 feature fix * native-pkcs11 feature fix * rlib fix * test data fixes * feature import fix * native pkcs11 custom-function-list feature * Documentation * documentation fixes * documentation improvements * zero-trust doc * build instructions * more windows fixes * rebae on branch 105-removal-of-openssl-in-the-cli * refacto almost done * clippy fixes * update FUNC_LIST * fixed version of native-pkcs11 * documentation * cargo fmt * cargo fmt * fixed tests server imports * fixed import * review fixes * docs: fix dead links * fix: remove useless deps of test_server * fix: disable doc test for new subcrates * fix: cargo audit * fix: test_server build * doc fix * github build pkcs11 lib * artifacts fix * fix: artifacts in debug * fix: artifacts in debug - windows * fix: artifacts in debug - windows - not for pkcs11 * linux build doc * fix: pkcs11 windows build --------- Co-authored-by: ThibsG <thibsg@pm.me> Co-authored-by: Manuthor <32013169+Manuthor@users.noreply.github.com> Co-authored-by: Manuthor <manu.coste@gmail.com>
105 lines
3 KiB
Rust
105 lines
3 KiB
Rust
use std::process::Command;
|
|
|
|
use assert_cmd::prelude::*;
|
|
use cosmian_kms_client::KMS_CLI_CONF_ENV;
|
|
use kms_test_server::{start_default_test_kms_server, ONCE};
|
|
|
|
use super::SUB_COMMAND;
|
|
use crate::{
|
|
error::CliError,
|
|
tests::{
|
|
utils::{
|
|
extract_uids::{extract_private_key, extract_public_key},
|
|
recover_cmd_logs,
|
|
},
|
|
PROG_NAME,
|
|
},
|
|
};
|
|
|
|
pub fn create_cc_master_key_pair(
|
|
cli_conf_path: &str,
|
|
policy_option: &str,
|
|
file: &str,
|
|
tags: &[&str],
|
|
) -> Result<(String, String), CliError> {
|
|
let mut cmd = Command::cargo_bin(PROG_NAME)?;
|
|
cmd.env(KMS_CLI_CONF_ENV, cli_conf_path);
|
|
cmd.env("RUST_LOG", "cosmian_kms_cli=info");
|
|
let mut args = vec!["keys", "create-master-key-pair", policy_option, file];
|
|
// add tags
|
|
for tag in tags {
|
|
args.push("--tag");
|
|
args.push(tag);
|
|
}
|
|
cmd.arg(SUB_COMMAND).args(args);
|
|
|
|
let output = recover_cmd_logs(&mut cmd);
|
|
if output.status.success() {
|
|
let master_keys_output = std::str::from_utf8(&output.stdout)?;
|
|
assert!(master_keys_output.contains("Private key unique identifier:"));
|
|
assert!(master_keys_output.contains("Public key unique identifier :"));
|
|
let master_private_key_id = extract_private_key(master_keys_output)
|
|
.ok_or_else(|| {
|
|
CliError::Default("failed extracting the master private key".to_owned())
|
|
})?
|
|
.to_owned();
|
|
let master_public_key_id = extract_public_key(master_keys_output)
|
|
.ok_or_else(|| CliError::Default("failed extracting the master public key".to_owned()))?
|
|
.to_owned();
|
|
return Ok((master_private_key_id, master_public_key_id))
|
|
}
|
|
|
|
Err(CliError::Default(
|
|
std::str::from_utf8(&output.stderr)?.to_owned(),
|
|
))
|
|
}
|
|
|
|
#[tokio::test]
|
|
pub async fn test_create_master_key_pair() -> Result<(), CliError> {
|
|
// from specs
|
|
let ctx = ONCE.get_or_try_init(start_default_test_kms_server).await?;
|
|
create_cc_master_key_pair(
|
|
&ctx.owner_client_conf_path,
|
|
"--policy-specifications",
|
|
"test_data/policy_specifications.json",
|
|
&[],
|
|
)?;
|
|
//from binary
|
|
create_cc_master_key_pair(
|
|
&ctx.owner_client_conf_path,
|
|
"--policy-binary",
|
|
"test_data/policy.bin",
|
|
&[],
|
|
)?;
|
|
Ok(())
|
|
}
|
|
|
|
#[tokio::test]
|
|
pub async fn test_create_master_key_pair_error() -> Result<(), CliError> {
|
|
let ctx = ONCE.get_or_try_init(start_default_test_kms_server).await?;
|
|
|
|
let err = create_cc_master_key_pair(
|
|
&ctx.owner_client_conf_path,
|
|
"--policy-specifications",
|
|
"test_data/notfound.json",
|
|
&[],
|
|
)
|
|
.err()
|
|
.unwrap();
|
|
assert!(err.to_string().contains("ERROR: could not open the file"));
|
|
|
|
let err = create_cc_master_key_pair(
|
|
&ctx.owner_client_conf_path,
|
|
"--policy-binary",
|
|
"test_data/policy.bad",
|
|
&[],
|
|
)
|
|
.err()
|
|
.unwrap();
|
|
assert!(
|
|
err.to_string()
|
|
.contains("ERROR: policy binary is malformed")
|
|
);
|
|
|
|
Ok(())
|
|
}
|