Skip to content

Commit

Permalink
Add check to use same key for TA force reinit
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenvh1 committed Jan 31, 2025
1 parent 364199b commit c9f54a8
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions src/cli/ta/signer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Managing the Trust Anchor Signer.
use std::sync::Arc;
use openssl::error::ErrorStack;
use rpki::ca::idexchange;
use rpki::uri;
use crate::ta;
Expand Down Expand Up @@ -132,14 +133,43 @@ impl TrustAnchorSignerManager {
&self,
info: SignerInitInfo,
) -> Result<Success, SignerClientError> {
if self.store.has(&self.ta_handle)? {
if let Ok(cert) = self.store.get_latest(&self.ta_handle) {
if !info.force {
return Err(SignerClientError::other(
"Trust Anchor Signer was already initialised.",
));
} else if let Err(e) = self.store.drop(&self.ta_handle) {
}
if let Some(priv_key) = &info.private_key_pem {
let res = || -> Result<(Vec<u8>, Vec<u8>), ErrorStack> {
let priv_key = openssl::pkey::PKey::private_key_from_pem(
priv_key.as_bytes()
)?;
let signer_info = cert.get_signer_info();
let pub_key = signer_info.ta_cert_details.cert().csr_info().key();
let k1 = priv_key.public_key_to_der()?;
let k2 = pub_key.to_info_bytes().to_vec();
return Ok((k1, k2));

Check failure on line 151 in src/cli/ta/signer.rs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, stable, --features all)

unneeded `return` statement
}();
if let Ok((k1, k2)) = res {
if k1 != k2 {
return Err(SignerClientError::other(
"You are not using the same private key."
));
}
} else if let Err(e) = res {
return Err(SignerClientError::other(
e.to_string()
));
}

if let Err(e) = self.store.drop(&self.ta_handle) {
return Err(SignerClientError::other(
e.to_string(),
));
}
} else {
return Err(SignerClientError::other(
e.to_string(),
"Private key must be provided when force reinitialising."
));
}
}
Expand Down

0 comments on commit c9f54a8

Please sign in to comment.