Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit c048f97

Browse files
committed
Merge branch 'david/revert-ed25519-everywhere' into david/docker-env-file
2 parents 21cc950 + 24e284b commit c048f97

File tree

5 files changed

+64
-53
lines changed

5 files changed

+64
-53
lines changed

go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ module github.com/keybase/bot-sshca
33
go 1.12
44

55
require (
6-
github.com/ScaleFT/sshkeys v0.0.0-20181112160850-82451a803681
7-
github.com/dchest/bcrypt_pbkdf v0.0.0-20150205184540-83f37f9c154a // indirect
86
github.com/google/uuid v1.1.1
97
github.com/keybase/go-keybase-chat-bot v0.0.0-20190812134859-bc54fd9cf83b
108
github.com/sirupsen/logrus v1.4.2

go.sum

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
2-
github.com/ScaleFT/sshkeys v0.0.0-20181112160850-82451a803681 h1:JS2rl38kZmHgWa0xINSaSYH0Whtvem64/4+Ef0+Y5pE=
3-
github.com/ScaleFT/sshkeys v0.0.0-20181112160850-82451a803681/go.mod h1:WfDateMPQ/55dPbZRp5Zxrux5WiEaHsjk9puUhz0KgY=
42
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
53
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
64
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
75
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
8-
github.com/dchest/bcrypt_pbkdf v0.0.0-20150205184540-83f37f9c154a h1:saTgr5tMLFnmy/yg3qDTft4rE5DY2uJ/cCxCe3q0XTU=
9-
github.com/dchest/bcrypt_pbkdf v0.0.0-20150205184540-83f37f9c154a/go.mod h1:Bw9BbhOJVNR+t0jCqx2GC6zv0TGBsShs56Y3gfSCvl0=
106
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
117
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
128
github.com/keybase/go-keybase-chat-bot v0.0.0-20190812134859-bc54fd9cf83b h1:7Te2f9LQ/rd6XSzpntz6BaCBgglZ0uiCdv3/GdhX9VA=

src/keybaseca/sshutils/generate.go

Lines changed: 0 additions & 47 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// +build !windows
2+
3+
package sshutils
4+
5+
import (
6+
"fmt"
7+
"os/exec"
8+
"strings"
9+
)
10+
11+
// Generate a new SSH key. Places the private key at filename and the public key at filename.pub.
12+
// On unix, we use ed25519 keys since they may be more secure (and are smaller). The go crypto ssh library
13+
// does not support ed25519 keys so we use ssh-keygen in order to generate the key.
14+
func generateNewSSHKey(filename string) error {
15+
cmd := exec.Command("ssh-keygen", "-t", "ed25519", "-f", filename, "-m", "PEM", "-N", "")
16+
bytes, err := cmd.CombinedOutput()
17+
if err != nil {
18+
return fmt.Errorf("ssh-keygen failed: %s (%v)", strings.TrimSpace(string(bytes)), err)
19+
}
20+
return nil
21+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// +build windows
2+
// If you edit this file, be sure to test it on windows also. Our current test suite does not test windows support.
3+
4+
package sshutils
5+
6+
import (
7+
"crypto/rand"
8+
"crypto/rsa"
9+
"crypto/x509"
10+
"encoding/pem"
11+
"io/ioutil"
12+
"os"
13+
14+
"github.com/keybase/bot-sshca/src/shared"
15+
"golang.org/x/crypto/ssh"
16+
)
17+
18+
// Generate a new SSH key. Places the private key at filename and the public key at filename.pub.
19+
// On windows, we use 2048 bit rsa keys. go's ssh library doesn't support ed25519 and ssh-keygen isn't built in.
20+
func generateNewSSHKey(filename string) error {
21+
privateKey, err := rsa.GenerateKey(rand.Reader, 2048)
22+
if err != nil {
23+
return err
24+
}
25+
26+
privateKeyFile, err := os.Create(filename)
27+
if err != nil {
28+
return err
29+
}
30+
defer privateKeyFile.Close()
31+
32+
privateKeyPEM := &pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(privateKey)}
33+
err = pem.Encode(privateKeyFile, privateKeyPEM)
34+
if err != nil {
35+
return err
36+
}
37+
38+
pub, err := ssh.NewPublicKey(&privateKey.PublicKey)
39+
if err != nil {
40+
return err
41+
}
42+
return ioutil.WriteFile(shared.KeyPathToPubKey(filename), ssh.MarshalAuthorizedKey(pub), 0600)
43+
}

0 commit comments

Comments
 (0)