Half baked ssh key generation.

I'll just probably rework this whole thing.
This commit is contained in:
rony5394
2026-03-13 17:59:26 +01:00
parent 49f36ff8ba
commit 0f5c47ad1f
5 changed files with 123 additions and 24 deletions

45
docker/ssh.go Normal file
View File

@@ -0,0 +1,45 @@
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,
};
}