Skip to content

Commit

Permalink
Use the system rand reader for SSH keypair generation (#12560)
Browse files Browse the repository at this point in the history
* Use the system rand reader for SSH keypair generation

* changelog
  • Loading branch information
sgmiller committed Sep 15, 2021
1 parent 8478615 commit 74b3227
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 7 additions & 3 deletions builtin/logical/ssh/path_config_ca.go
Expand Up @@ -7,6 +7,7 @@ import (
"crypto/x509"
"encoding/pem"
"fmt"
"io"

multierror "github.com/hashicorp/go-multierror"
"github.com/hashicorp/vault/sdk/framework"
Expand Down Expand Up @@ -190,7 +191,7 @@ func (b *backend) pathConfigCAUpdate(ctx context.Context, req *logical.Request,
}

if generateSigningKey {
publicKey, privateKey, err = generateSSHKeyPair()
publicKey, privateKey, err = generateSSHKeyPair(b.Backend.GetRandomReader())
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -264,8 +265,11 @@ func (b *backend) pathConfigCAUpdate(ctx context.Context, req *logical.Request,
return nil, nil
}

func generateSSHKeyPair() (string, string, error) {
privateSeed, err := rsa.GenerateKey(rand.Reader, 4096)
func generateSSHKeyPair(randomSource io.Reader) (string, string, error) {
if randomSource == nil {
randomSource = rand.Reader
}
privateSeed, err := rsa.GenerateKey(randomSource, 4096)
if err != nil {
return "", "", err
}
Expand Down
3 changes: 3 additions & 0 deletions changelog/12560.txt
@@ -0,0 +1,3 @@
```release-note:improvement
secrets/ssh: Use entropy augmentation when available for generation of the signing key.
```

0 comments on commit 74b3227

Please sign in to comment.