1

Add SSH key generation

This commit is contained in:
Evan Pratten 2024-01-13 13:38:05 -05:00
parent 63208d5004
commit 64d5374ef0

View File

@ -0,0 +1,44 @@
const SSH_PUBKEYS = {
devices: {
desktop: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGBaSKoWYuR43fxRPy31P/X/2Ri2hYUZTjKiLBRDoa1F",
laptop: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGEqeWe+pVp3rTsmHr9v5Qcb+niHXihJxwVKcc7p6EXz",
tablet: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAID8oqpyU3UW9nLzhTFO6AnDvG2Gf/UQGbB0xgtT8JMmr",
phone: "ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBMbNW3x0Cx04MybxQo5FptZhdjiFJjKITtq67KqrDXAN+jepJwdIG6TUJzuJddztuYIsvPAoQPpiQVSPyC8y51Y=",
},
others: [
"sk-ssh-ed25519@openssh.com AAAAGnNrLXNzaC1lZDI1NTE5QG9wZW5zc2guY29tAAAAIAkdmKF1cYQTW7cfK7TYC5iVBsAg5g3SRJqlqo2NixHdAAAABHNzaDo="
]
}
export function onRequest(context) {
let request_url = new URL(context.request.url);
// Check request flags
let add_host_metadata = request_url.searchParams.has("hosts");
let add_markers = request_url.searchParams.has("markers");
// Construct the output
let output = "";
for (let key in SSH_PUBKEYS.others) {
output += `${SSH_PUBKEYS.others[key]}\n`;
}
for (let device in SSH_PUBKEYS.devices) {
output += SSH_PUBKEYS.devices[device];
if (add_host_metadata) {
output += ` ewpratten@ewpratten-${device}\n`;
} else {
output += "\n";
}
}
// Add markers if needed
if (add_markers) {
output = `\n# --- BEGIN EWPRATTEN SSH KEYS ---\n${output}\n# --- END EWPRATTEN SSH KEYS ---\n\n`;
}
return new Response(output, {
headers: {
"Content-Type": "text/plain",
},
});
}