Files
blazena/docker/ssh.go
rony5394 0f5c47ad1f Half baked ssh key generation.
I'll just probably rework this whole thing.
2026-03-13 17:59:26 +01:00

46 lines
688 B
Go

package docker
import (
"crypto/ed25519"
"crypto/rand"
"crypto/x509"
"encoding/pem"
"golang.org/x/crypto/ssh"
)
type Keypair struct {
public []byte
private []byte
}
func generateKeypair() Keypair {
publicKey, privateKey, err := ed25519.GenerateKey(rand.Reader)
if err != nil {
panic(err)
}
privBytes, err := x509.MarshalPKCS8PrivateKey(privateKey)
if err != nil {
panic(err)
}
privPem := pem.EncodeToMemory(&pem.Block{
Type: "PRIVATE KEY",
Bytes: privBytes,
})
sshPubKey, err := ssh.NewPublicKey(publicKey)
if err != nil {
panic(err)
}
pubBytes := ssh.MarshalAuthorizedKey(sshPubKey)
return Keypair{
private: privPem,
public: pubBytes,
};
}