added structure for server ssh keys

This commit is contained in:
ghe0 2025-01-11 18:16:02 +02:00
parent 7864c53236
commit 56056deae3
Signed by: ghe0
GPG Key ID: 451028EE56A0FBB4
2 changed files with 20 additions and 6 deletions

@ -132,8 +132,13 @@ struct SSHKeyForm {
ssh_key: String, ssh_key: String,
} }
#[get("/ssh_key")] #[get("/server_ssh_pubkeys")]
async fn get_ssh_keys(req: HttpRequest) -> HttpResponse { async fn get_server_pubkeys() -> HttpResponse {
todo!();
}
#[get("/authorized_keys")]
async fn get_authorized_keys(req: HttpRequest) -> HttpResponse {
if let Err(e) = verify(&req) { if let Err(e) = verify(&req) {
return HttpResponse::BadRequest().body(format!("Signature verification failed: {}", e)); return HttpResponse::BadRequest().body(format!("Signature verification failed: {}", e));
}; };
@ -143,8 +148,8 @@ async fn get_ssh_keys(req: HttpRequest) -> HttpResponse {
} }
} }
#[post("/ssh_key")] #[post("/authorized_keys")]
async fn post_ssh_key(req: HttpRequest, form: web::Form<SSHKeyForm>) -> HttpResponse { async fn post_authorized_keys(req: HttpRequest, form: web::Form<SSHKeyForm>) -> HttpResponse {
if let Err(e) = verify(&req) { if let Err(e) = verify(&req) {
return HttpResponse::BadRequest().body(format!("Signature verification failed: {}", e)); return HttpResponse::BadRequest().body(format!("Signature verification failed: {}", e));
}; };
@ -194,8 +199,8 @@ async fn main() -> std::io::Result<()> {
.service(post_install_form) .service(post_install_form)
.service(post_decrypt_form) .service(post_decrypt_form)
.service(post_process_exit) .service(post_process_exit)
.service(post_ssh_key) .service(post_authorized_keys)
.service(get_ssh_keys) .service(get_authorized_keys)
.service(get_report) .service(get_report)
.service(homepage) .service(homepage)
}) })

@ -58,3 +58,12 @@ echo "" > /mnt/etc/fstab
hostname=$(cat /proc/cmdline | grep -oE 'detee_name=[0-9a-z\_\.\-]+' | cut -d '=' -f2) hostname=$(cat /proc/cmdline | grep -oE 'detee_name=[0-9a-z\_\.\-]+' | cut -d '=' -f2)
echo "=== Setting up guest hostname as $hostname" echo "=== Setting up guest hostname as $hostname"
[[ -n "$hostname" ]] && echo $hostname > /mnt/etc/hostname [[ -n "$hostname" ]] && echo $hostname > /mnt/etc/hostname
echo "=== Generating SSH public keys"
[[ -f "/mnt/etc/ssh/ssh_host_rsa_key" ]] ||
/mnt/usr/bin/ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N '' > /dev/null
[[ -f "/mnt/etc/ssh/ssh_host_ecdsa_key" ]] ||
/mnt/usr/bin/ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N '' > /dev/null
[[ -f "/mnt/etc/ssh/ssh_host_ed25519_key" ]] ||
/mnt/usr/bin/ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N '' > /dev/null
echo "=== Done! Download keys from /server_pubkeys"