added: cert/SHA256:...

This commit is contained in:
2023-03-10 10:38:31 +01:00
parent ba77091de7
commit e696663aec
4 changed files with 65 additions and 9 deletions

View File

@@ -9,6 +9,7 @@ use std::time::SystemTime;
use anyhow::Context;
use axum::body;
use axum::extract::{Query, State};
use chrono::Duration;
use ssh_cert_dist_common::*;
use axum::{http::StatusCode, response::IntoResponse, Json, Router};
@@ -291,12 +292,12 @@ struct CertInfo {
impl From<&Certificate> for CertInfo {
fn from(cert: &Certificate) -> Self {
let validity = cert.valid_after_time().duration_since(cert.valid_before_time()).unwrap();
let validity = cert.valid_before_time().duration_since(cert.valid_after_time()).unwrap_or(Duration::zero().to_std().unwrap());
let validity_days = validity.as_secs() / ((60*60) * 24);
let host_key = if cert.cert_type().is_host() {
" -h"
} else { "" };
let opts = cert.critical_options().iter().map(|(opt, val)| if val.is_empty() { opt.clone() } else { format!("{opt}={val}") }).map(|arg| format!("-O {arg}")).join(" ");
let opts = cert.critical_options().iter().map(|(opt, val)| if val.is_empty() { opt.clone() } else { format!("{opt}={val}") }).map(|arg| format!("-O {arg}")).collect::<Vec<_>>().join(" ");
let renew_command = format!("ssh-keygen -s ./ca_key {host_key} -I {} -n {} -V {validity_days}d {opts}", cert.key_id(), cert.valid_principals().join(","));
CertInfo {
principals: cert.valid_principals().to_vec(),