Half baked ssh key generation.
I'll just probably rework this whole thing.
This commit is contained in:
45
docker/ssh.go
Normal file
45
docker/ssh.go
Normal 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,
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user