[control] QC minors: device install links open a page and download on POST (never listed), approve and install failures show on the request and the CLI waits, PBKDF2 floor, private pki dirs or an error, trusted_proxies for a proxy in front, a placeholder keeps the device allow list from being empty (Caddy refuses that)
This commit is contained in:
@@ -616,9 +616,86 @@ async fn bundle_url(st: &AppState, token: &str) -> String {
|
||||
format!("https://{authority}{path}")
|
||||
}
|
||||
|
||||
/// The one-time download itself. The link is the secret: no token or sign-in is needed, and
|
||||
/// it works once.
|
||||
#[utoipa::path(get, path = "/api/v1/device-bundles/{token}", tag = "certs",
|
||||
/// `GET` on a one-time link: a small page with a Download button that posts back. Link
|
||||
/// previews and prefetchers only ever GET, so they cannot use up the download.
|
||||
pub async fn bundle_page(st: Arc<AppState>, token: String) -> Response {
|
||||
let valid = token.len() == 64 && token.bytes().all(|c| c.is_ascii_hexdigit());
|
||||
let name = if valid {
|
||||
let ctl = st.ctl.clone();
|
||||
tokio::task::spawn_blocking(move || {
|
||||
ctl.pki.as_ref().and_then(|p| p.peek_bundle(&token, now()))
|
||||
})
|
||||
.await
|
||||
.ok()
|
||||
.flatten()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let (status, body) = match name {
|
||||
Some(n) => (
|
||||
StatusCode::OK,
|
||||
format!(
|
||||
"<h1>Install the certificate for {}</h1>\
|
||||
<p>This link works once. After the download, open the file and enter the \
|
||||
one-time password shown in Ianitor.</p>\
|
||||
<form method=\"post\"><button type=\"submit\">Download domi-device.p12</button></form>",
|
||||
html_escape(&n)
|
||||
),
|
||||
),
|
||||
None => (
|
||||
StatusCode::GONE,
|
||||
format!(
|
||||
"<h1>This link has been used</h1><p>{}</p>",
|
||||
html_escape(&message("pki.bundle_used", &Params::new()))
|
||||
),
|
||||
),
|
||||
};
|
||||
let page = format!(
|
||||
"<!doctype html><html lang=\"en\"><head><meta charset=\"utf-8\">\
|
||||
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\
|
||||
<meta name=\"robots\" content=\"noindex\"><title>Ianitor: device certificate</title>\
|
||||
<style>body{{margin:0;padding:24px 16px;background:#0f1115;color:#e6e8ee;\
|
||||
font:16px/1.5 system-ui,sans-serif}}main{{max-width:32rem;margin:0 auto}}\
|
||||
h1{{font-size:1.25rem}}button{{font:inherit;padding:10px 16px;border-radius:8px;\
|
||||
border:0;background:#7aa2ff;color:#0f1115;cursor:pointer}}\
|
||||
button:focus-visible{{outline:2px solid #e6e8ee;outline-offset:2px}}</style>\
|
||||
</head><body><main>{body}</main></body></html>"
|
||||
);
|
||||
let mut r = (status, page).into_response();
|
||||
let h = r.headers_mut();
|
||||
h.insert(
|
||||
header::CONTENT_TYPE,
|
||||
HeaderValue::from_static("text/html; charset=utf-8"),
|
||||
);
|
||||
h.insert(header::CACHE_CONTROL, HeaderValue::from_static("no-store"));
|
||||
h.insert("referrer-policy", HeaderValue::from_static("no-referrer"));
|
||||
h.insert(
|
||||
"content-security-policy",
|
||||
HeaderValue::from_static(
|
||||
"default-src 'none'; style-src 'unsafe-inline'; form-action 'self'; frame-ancestors 'none'; base-uri 'none'",
|
||||
),
|
||||
);
|
||||
r
|
||||
}
|
||||
|
||||
fn html_escape(s: &str) -> String {
|
||||
let mut o = String::with_capacity(s.len());
|
||||
for c in s.chars() {
|
||||
match c {
|
||||
'&' => o.push_str("&"),
|
||||
'<' => o.push_str("<"),
|
||||
'>' => o.push_str(">"),
|
||||
'"' => o.push_str("""),
|
||||
'\'' => o.push_str("'"),
|
||||
c => o.push(c),
|
||||
}
|
||||
}
|
||||
o
|
||||
}
|
||||
|
||||
/// The one-time download itself (`POST`, from the link's page). The link is the secret: no
|
||||
/// token or sign-in is needed, and it works once.
|
||||
#[utoipa::path(post, path = "/api/v1/device-bundles/{token}", tag = "certs",
|
||||
responses((status = 200, description = "application/x-pkcs12"), (status = 410, body = super::views::ErrorEnvelope)))]
|
||||
pub async fn download_bundle(
|
||||
State(st): Shared,
|
||||
|
||||
Reference in New Issue
Block a user