Skip to content

Commit

Permalink
chore: merge with release 4.8.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuthor committed Oct 31, 2023
2 parents ba947bc + 429590e commit e48ab02
Show file tree
Hide file tree
Showing 34 changed files with 136 additions and 94 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to this project will be documented in this file.

## [4.8.2] - 2023-10-31

### Bug Fixes

- Save certs as DER instead of PEM for KMIP compliance

## [4.8.1] - 2023-10-12

### Bug Fixes
Expand Down
55 changes: 34 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion crate/cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cosmian_kms_cli"
version = "4.8.1"
version = "4.8.2"
edition = "2021"
license-file = "../../LICENSE.md"
description = "CLI used to manage the Cosmian KMS."
Expand All @@ -23,6 +23,7 @@ cosmian_kms_utils = { path = "../utils" }
cosmian_logger = { path = "../logger" }
hex = { workspace = true }
openssl = { workspace = true }
pem = "3.0"
rand = "0.8"
ratls = { workspace = true }
reqwest = { workspace = true }
Expand Down
11 changes: 7 additions & 4 deletions crate/cli/src/actions/certificates/export_certificate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ impl ExportCertificateAction {
)
.await?;

// DER-encoded certificate bytes
let certificate_bytes = match &object {
Object::Certificate {
certificate_value, ..
Expand All @@ -127,8 +128,10 @@ impl ExportCertificateAction {
write_kmip_object_to_file(&object, &self.certificate_file)?;
}
CertificateExportFormat::PEM => {
// convert DER certificate to PEM certificate
let pem = pem::Pem::new("CERTIFICATE", certificate_bytes).to_string();
// save it to a file
write_bytes_to_file(&certificate_bytes, &self.certificate_file)?;
write_bytes_to_file(pem.as_bytes(), &self.certificate_file)?;
}
CertificateExportFormat::PKCS12 => {
let password = self.pkcs12_password.clone().ok_or(CliError::Cryptographic(
Expand Down Expand Up @@ -216,10 +219,10 @@ async fn create_pkcs12(

// Create PKCS12 using Rust-OpenSSL
let pkey = PKey::private_key_from_pem(private_key_as_pem.as_bytes())?;
let cert = X509::from_pem(certificate_bytes)?;
let cert = X509::from_der(certificate_bytes)?;
let mut cas = Stack::<X509>::new()?;
for ca_issuer_name in cert.issuer_name().entries() {
let pem = locate_ca_cert(
let der = locate_ca_cert(
client_connector,
ca_issuer_name.data().as_utf8()?.as_ref(),
&Attributes {
Expand All @@ -228,7 +231,7 @@ async fn create_pkcs12(
},
)
.await?;
let cert = X509::from_pem(&pem)?;
let cert = X509::from_der(&der)?;
cas.push(cert)?;
}

Expand Down
7 changes: 0 additions & 7 deletions crate/cli/src/actions/certificates/import_certificate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ pub enum CertificateInputFormat {
/// - a certificate chain as a PEM-stack
/// - the Mozilla Common CA Database (CCADB). Automate the Mozilla database fetch.
///
/// The certificate can be in:
/// - KMIP JSON TTLV format
/// - PEM format
///
///
/// The private/public keys format is PEM format.
///
/// When no certificate unique id is specified, a random UUID v4 is generated.
///
/// Tags can later be used to retrieve the certificate. Tags are optional.
Expand Down
3 changes: 1 addition & 2 deletions crate/cli/src/actions/certificates/locate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ pub(crate) async fn locate_ca_cert(
} => certificate_value,
_ => {
cli_bail!(
"The object {} is not a certificate but a {}",
&cert_uid,
"The object {cert_uid} is not a certificate but a {}",
get_response.object.object_type()
);
}
Expand Down
5 changes: 4 additions & 1 deletion crate/cli/src/tests/certificates/certify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ pub async fn test_certify() -> Result<(), CliError> {
assert_eq!(ids.len(), 3 * (hierarchical_depth + 2));

// Export certificate as PKCS12
debug!("\n\n\ntest_certify: export");
debug!("\n\n\ntest_certify: export PKCS12");
let export_filename = tmp_path.join("output.p12").to_str().unwrap().to_owned();
export(
&ctx.owner_cli_conf_path,
Expand All @@ -229,10 +229,12 @@ pub async fn test_certify() -> Result<(), CliError> {
None,
false,
)?;

// Read the bytes of the file and check them with openssl
let certificate_bytes = get_file_as_byte_vec(&export_filename);
check_certificate(&certificate_bytes, "secret");

debug!("\n\n\ntest_certify: export PEM");
// Export certificate as PEM only
let export_filename = tmp_path.join("cert.pem").to_str().unwrap().to_owned();
export(
Expand All @@ -249,6 +251,7 @@ pub async fn test_certify() -> Result<(), CliError> {
let certificate_str = std::str::from_utf8(&certificate_bytes).unwrap();
println!("Certificate PEM: {certificate_str}");

debug!("\n\n\ntest_certify: export RAW KMIP TTLV");
// Export certificate as RAW KMIP TTLV
let export_filename = tmp_path.join("ttlv.json").to_str().unwrap().to_owned();
export(
Expand Down
2 changes: 1 addition & 1 deletion crate/client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cosmian_kms_client"
version = "4.8.1"
version = "4.8.2"
authors = ["Bruno Grieder <[email protected]>"]
edition = "2021"
license-file = "../../LICENSE.md"
Expand Down
2 changes: 1 addition & 1 deletion crate/kmip/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cosmian_kmip"
version = "4.8.1"
version = "4.8.2"
edition = "2021"
license-file = "../../LICENSE.md"

Expand Down
3 changes: 2 additions & 1 deletion crate/kmip/src/kmip/kmip_objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ pub enum Object {
#[serde(rename_all = "PascalCase")]
Certificate {
certificate_type: CertificateType,
/// A Managed Cryptographic Object that is a digital certificate. It is a DER-encoded X.509 public key certificate.
/// A Managed Cryptographic Object that is a digital certificate.
/// It is a DER-encoded X.509 public key certificate.
certificate_value: Vec<u8>,
},
#[serde(rename_all = "PascalCase")]
Expand Down
2 changes: 1 addition & 1 deletion crate/logger/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cosmian_logger"
version = "4.8.1"
version = "4.8.2"
authors = ["Emmanuel Coste <[email protected]>"]
edition = "2021"
license-file = "../../LICENSE.md"
Expand Down
10 changes: 6 additions & 4 deletions crate/pyo3/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cosmian_kms_python"
version = "4.8.1"
version = "4.8.2"
authors = ["Hugo Rosenkranz-Costa <[email protected]>"]
edition = "2021"
license-file = "../../LICENSE.md"
Expand All @@ -14,16 +14,18 @@ cloudproof = { workspace = true }
cosmian_kmip = { path = "../kmip" }
cosmian_kms_client = { path = "../client" }
cosmian_kms_utils = { path = "../utils" }
pyo3 = { version = "0.18", features = [
openssl = { workspace = true }
pyo3 = { version = "0.19", features = [
"extension-module",
"abi3",
"abi3-py37",
"generate-import-lib",
] }
pyo3-asyncio = { version = "0.18", features = ["tokio-runtime"] }
pyo3-asyncio = { version = "0.19", features = ["tokio-runtime"] }
rustls = { workspace = true }
serde_json = { workspace = true }

# Added with build.rs to fix build issues on MacOS
# see https://github.com/PyO3/pyo3/issues/1857
[build-dependencies]
pyo3-build-config = "0.18"
pyo3-build-config = "0.19"
Loading

0 comments on commit e48ab02

Please sign in to comment.