Added ephemeral ssh keys.

This commit is contained in:
rony5394
2026-03-14 14:39:19 +01:00
parent 0f5c47ad1f
commit be06e3b87c
5 changed files with 180 additions and 36 deletions

40
shared/ssh.go Normal file
View File

@@ -0,0 +1,40 @@
package shared
import (
"crypto/ed25519"
"crypto/rand"
"encoding/pem"
"golang.org/x/crypto/ssh"
)
type Keypair struct {
Public string
Private string
}
func GenerateSSHKeypair() Keypair {
publicKey, privateKey, err := ed25519.GenerateKey(rand.Reader)
if err != nil {
panic(err)
}
privBlock, err := ssh.MarshalPrivateKey(privateKey, "")
if err != nil {
panic(err)
}
privPem := pem.EncodeToMemory(privBlock)
sshPubKey, err := ssh.NewPublicKey(publicKey)
if err != nil {
panic(err)
}
pubBytes := ssh.MarshalAuthorizedKey(sshPubKey)
return Keypair{
Private: string(privPem),
Public: string(pubBytes),
}
}