Add OpenSSH KRL spec export
This commit is contained in:
parent
02444a7cfd
commit
b102e07204
9 changed files with 235 additions and 25 deletions
|
|
@ -18,8 +18,8 @@ use geth_resource::ResourceDescriptor;
|
|||
use geth_secrets::{BearerAccess, ResourceMasterSecret};
|
||||
use geth_ssh_identity::{
|
||||
SshCertApproval, SshCertKind, SshCertRequest, SshCertRequestStatus, SshCertificateRecord,
|
||||
SshRevocationEntry, SshRevocationKind, build_ssh_cert_sign_command, cert_request_id,
|
||||
certificate_id, revocation_id, ssh_public_key_fingerprint,
|
||||
SshRevocationEntry, SshRevocationExportFormat, SshRevocationKind, build_ssh_cert_sign_command,
|
||||
cert_request_id, certificate_id, openssh_krl_spec, revocation_id, ssh_public_key_fingerprint,
|
||||
};
|
||||
use geth_store::{
|
||||
Store, StoredAuthOp, StoredDbResource, StoredDocumentResource, StoredKeychainOp, StoredKvEntry,
|
||||
|
|
@ -92,6 +92,8 @@ pub enum NodeError {
|
|||
MissingSshCertPrincipal,
|
||||
#[error("ssh certificate flow error: {0}")]
|
||||
SshCertFlow(#[from] geth_ssh_identity::SshCertFlowError),
|
||||
#[error("ssh identity error: {0}")]
|
||||
SshIdentity(#[from] geth_ssh_identity::SshIdentityError),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
|
@ -668,24 +670,41 @@ pub fn handle_request(
|
|||
.map(ssh_revocation_from_stored)
|
||||
.collect::<Result<Vec<_>, _>>()?,
|
||||
}),
|
||||
ControlRequest::SshRevocationExport { out } => {
|
||||
ControlRequest::SshRevocationExport { out, format } => {
|
||||
let revocations = store
|
||||
.list_ssh_revocations()?
|
||||
.into_iter()
|
||||
.map(ssh_revocation_from_stored)
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
let format = format
|
||||
.parse::<SshRevocationExportFormat>()
|
||||
.map_err(NodeError::SshIdentity)?;
|
||||
if let Some(parent) = out.parent() {
|
||||
std::fs::create_dir_all(parent)?;
|
||||
}
|
||||
let mut body = String::new();
|
||||
for revocation in &revocations {
|
||||
body.push_str(&serde_json::to_string(revocation)?);
|
||||
body.push('\n');
|
||||
}
|
||||
let (body, note) = match format {
|
||||
SshRevocationExportFormat::Jsonl => {
|
||||
let mut body = String::new();
|
||||
for revocation in &revocations {
|
||||
body.push_str(&serde_json::to_string(revocation)?);
|
||||
body.push('\n');
|
||||
}
|
||||
(
|
||||
body,
|
||||
"JSONL geth revocation metadata; not an OpenSSH KRL binary".to_owned(),
|
||||
)
|
||||
}
|
||||
SshRevocationExportFormat::OpenSshKrlSpec => (
|
||||
openssh_krl_spec(&revocations)?,
|
||||
"OpenSSH KRL specification; generate a binary KRL with ssh-keygen -k -f <krl> [-s <ca.pub>] <spec>".to_owned(),
|
||||
),
|
||||
};
|
||||
std::fs::write(&out, body)?;
|
||||
Ok(ControlResponse::SshRevocationExported {
|
||||
out,
|
||||
format: format.to_string(),
|
||||
count: revocations.len(),
|
||||
note,
|
||||
})
|
||||
}
|
||||
ControlRequest::DbAdd { name, path } => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue