Some cleanup.
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
package shared
|
||||
package shared
|
||||
|
||||
import (
|
||||
"crypto/ed25519"
|
||||
"crypto/rand"
|
||||
"encoding/pem"
|
||||
"log/slog"
|
||||
"os"
|
||||
|
||||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
@@ -16,19 +18,22 @@ type Keypair struct {
|
||||
func GenerateSSHKeypair() Keypair {
|
||||
publicKey, privateKey, err := ed25519.GenerateKey(rand.Reader)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
slog.Error("Failed to generate an ssh keypair.", slog.Any("propagatedError", err));
|
||||
os.Exit(42);
|
||||
}
|
||||
|
||||
privBlock, err := ssh.MarshalPrivateKey(privateKey, "")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
slog.Error("Failed to marshal private key", slog.Any("propagatedError", err));
|
||||
os.Exit(42);
|
||||
}
|
||||
|
||||
privPem := pem.EncodeToMemory(privBlock)
|
||||
|
||||
sshPubKey, err := ssh.NewPublicKey(publicKey)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
slog.Error("Failed deriving public ssh key from a private one.", slog.Any("propagatedError", err));
|
||||
os.Exit(42);
|
||||
}
|
||||
|
||||
pubBytes := ssh.MarshalAuthorizedKey(sshPubKey)
|
||||
|
||||
Reference in New Issue
Block a user