<host>/ssh.pub

This commit is contained in:
Mikaël Cluseau
2026-05-30 09:36:35 +02:00
parent 1a4d908bef
commit 6d26fd9fa6
2 changed files with 25 additions and 1 deletions
+24
View File
@@ -1,6 +1,7 @@
package main
import (
"bytes"
"io"
"log"
"net/http"
@@ -13,6 +14,8 @@ import (
"novit.tech/direktil/local-server/pkg/mime"
)
var sshKeyTypes = []string{"rsa", "ecdsa", "ed25519"}
type AssetVariant struct {
name string
url string
@@ -132,6 +135,9 @@ func (ws wsHost) register(rws *restful.WebService, alterRB func(*restful.RouteBu
b("bootstrap.tar").
Produces(mime.TAR).
Doc("Get the " + ws.hostDoc + "'s bootstrap seed archive"),
// ssh
b("ssh.pub").Produces("text/plain").Doc("Get the " + ws.hostDoc + "'s ssh public keys"),
} {
alterRB(rb)
rws.Route(rb)
@@ -253,6 +259,9 @@ func renderHost(w http.ResponseWriter, r *http.Request, what string, host *local
case "ipxe":
err = renderIPXE(w, ctx)
case "ssh.pub":
err = renderSshPub(w, ctx)
default:
http.NotFound(w, r)
}
@@ -262,3 +271,18 @@ func renderHost(w http.ResponseWriter, r *http.Request, what string, host *local
http.Error(w, "", http.StatusServiceUnavailable)
}
}
func renderSshPub(w http.ResponseWriter, ctx *renderContext) (err error) {
buf := new(bytes.Buffer)
for _, t := range sshKeyTypes {
k, err := ctx.sshHostKeyPair(t)
if err != nil {
return err
}
buf.WriteString(k.Public)
}
_, err = w.Write(buf.Bytes())
return
}