[vault] Signing: the signing body member (release and test key sets, scope, sign-only API, append-only audit log); custos-sign draws from SysRng; the wasm build links getrandom 0.2 to the browser CSPRNG
This commit is contained in:
@@ -84,9 +84,11 @@ pub fn generate(alg: Algorithm, comment: &str) -> Result<KeyPair, KeyError> {
|
||||
/// An OpenSSH key keeps its own comment unless it has none.
|
||||
pub fn import(text: &str, comment: &str) -> Result<KeyPair, KeyError> {
|
||||
// Pasted or read from a Windows file: CRLF line ends.
|
||||
let text = text.replace("
|
||||
let text = text.replace(
|
||||
"
|
||||
", "
|
||||
");
|
||||
",
|
||||
);
|
||||
let text = text.trim();
|
||||
let has = |label: &str| text.contains(&format!("-----BEGIN {label}-----"));
|
||||
if has("ENCRYPTED PRIVATE KEY") || text.contains("Proc-Type: 4,ENCRYPTED") {
|
||||
@@ -99,7 +101,9 @@ pub fn import(text: &str, comment: &str) -> Result<KeyPair, KeyError> {
|
||||
}
|
||||
let comment = if key.comment().is_empty() { comment.to_owned() } else { key.comment().to_owned() };
|
||||
return match key.key_data() {
|
||||
KeypairData::Ed25519(k) => from_ed25519(ed25519_dalek::SigningKey::from_bytes(&k.private.to_bytes()), &comment),
|
||||
KeypairData::Ed25519(k) => {
|
||||
from_ed25519(ed25519_dalek::SigningKey::from_bytes(&k.private.to_bytes()), &comment)
|
||||
}
|
||||
KeypairData::Ecdsa(EcdsaKeypair::NistP256 { private, .. }) => {
|
||||
from_p256(p256::SecretKey::from_slice(private.as_slice()).map_err(|_| KeyError::Invalid)?, &comment)
|
||||
}
|
||||
@@ -135,8 +139,13 @@ pub fn import(text: &str, comment: &str) -> Result<KeyPair, KeyError> {
|
||||
/// rebuilt from its components here.
|
||||
fn rsa_from_openssh(k: &RsaKeypair) -> Result<rsa::RsaPrivateKey, KeyError> {
|
||||
let n = |m: &ssh_key::Mpint| rsa::BigUint::try_from(m).map_err(|_| KeyError::Invalid);
|
||||
let sk = rsa::RsaPrivateKey::from_components(n(&k.public.n)?, n(&k.public.e)?, n(&k.private.d)?, vec![n(&k.private.p)?, n(&k.private.q)?])
|
||||
.map_err(|_| KeyError::Invalid)?;
|
||||
let sk = rsa::RsaPrivateKey::from_components(
|
||||
n(&k.public.n)?,
|
||||
n(&k.public.e)?,
|
||||
n(&k.private.d)?,
|
||||
vec![n(&k.private.p)?, n(&k.private.q)?],
|
||||
)
|
||||
.map_err(|_| KeyError::Invalid)?;
|
||||
sk.validate().map_err(|_| KeyError::Invalid)?;
|
||||
Ok(sk)
|
||||
}
|
||||
@@ -169,7 +178,13 @@ fn from_rsa(sk: rsa::RsaPrivateKey, comment: &str) -> Result<KeyPair, KeyError>
|
||||
assemble(&format!("rsa-{bits}"), KeypairData::Rsa(enc(RsaKeypair::try_from(sk))?), private_pem, public_pem, comment)
|
||||
}
|
||||
|
||||
fn assemble(algorithm: &str, data: KeypairData, private_pem: String, public_pem: String, comment: &str) -> Result<KeyPair, KeyError> {
|
||||
fn assemble(
|
||||
algorithm: &str,
|
||||
data: KeypairData,
|
||||
private_pem: String,
|
||||
public_pem: String,
|
||||
comment: &str,
|
||||
) -> Result<KeyPair, KeyError> {
|
||||
let private = enc(PrivateKey::new(data, comment))?;
|
||||
let public = private.public_key();
|
||||
Ok(KeyPair {
|
||||
|
||||
@@ -87,7 +87,8 @@ fn every_private_key_format_imports_to_the_same_key() {
|
||||
for text in inputs {
|
||||
// Surrounding whitespace (a paste, a file with CRLF line ends) does not matter.
|
||||
let pasted = format!("\r\n {}\r\n", text.replace('\n', "\r\n"));
|
||||
let i = custos_keys::import(&pasted, "deploy").unwrap_or_else(|e| panic!("{alg:?} {}: {e:?}", text.lines().next().unwrap()));
|
||||
let i = custos_keys::import(&pasted, "deploy")
|
||||
.unwrap_or_else(|e| panic!("{alg:?} {}: {e:?}", text.lines().next().unwrap()));
|
||||
assert_eq!((i.algorithm.as_str(), i.fingerprint.as_str()), (alg.name(), k.fingerprint.as_str()), "{alg:?}");
|
||||
assert_eq!(i.public_pem, k.public_pem);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user