Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the system rand reader for CA root and intermediate generation #12559

Merged
merged 2 commits into from Sep 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions builtin/logical/pki/cert_util.go
Expand Up @@ -11,6 +11,7 @@ import (
"encoding/base64"
"encoding/pem"
"fmt"
"io"
"net"
"net/url"
"regexp"
Expand Down Expand Up @@ -449,7 +450,8 @@ func generateCert(ctx context.Context,
b *backend,
input *inputBundle,
caSign *certutil.CAInfoBundle,
isCA bool) (*certutil.ParsedCertBundle, error) {
isCA bool,
randomSource io.Reader) (*certutil.ParsedCertBundle, error) {

if input.role == nil {
return nil, errutil.InternalError{Err: "no role found in data bundle"}
Expand Down Expand Up @@ -494,7 +496,7 @@ func generateCert(ctx context.Context,
}
}

parsedBundle, err := certutil.CreateCertificate(data)
parsedBundle, err := certutil.CreateCertificateWithRandomSource(data, randomSource)
if err != nil {
return nil, err
}
Expand All @@ -504,7 +506,7 @@ func generateCert(ctx context.Context,

// N.B.: This is only meant to be used for generating intermediate CAs.
// It skips some sanity checks.
func generateIntermediateCSR(b *backend, input *inputBundle) (*certutil.ParsedCSRBundle, error) {
func generateIntermediateCSR(b *backend, input *inputBundle, randomSource io.Reader) (*certutil.ParsedCSRBundle, error) {
creation, err := generateCreationBundle(b, input, nil, nil)
if err != nil {
return nil, err
Expand All @@ -514,7 +516,7 @@ func generateIntermediateCSR(b *backend, input *inputBundle) (*certutil.ParsedCS
}

addBasicConstraints := input.apiData != nil && input.apiData.Get("add_basic_constraints").(bool)
parsedBundle, err := certutil.CreateCSR(creation, addBasicConstraints)
parsedBundle, err := certutil.CreateCSRWithRandomSource(creation, addBasicConstraints, randomSource)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion builtin/logical/pki/path_intermediate.go
Expand Up @@ -75,7 +75,7 @@ func (b *backend) pathGenerateIntermediate(ctx context.Context, req *logical.Req
req: req,
apiData: data,
}
parsedBundle, err := generateIntermediateCSR(b, input)
parsedBundle, err := generateIntermediateCSR(b, input, b.Backend.GetRandomReader())
if err != nil {
switch err.(type) {
case errutil.UserError:
Expand Down
3 changes: 2 additions & 1 deletion builtin/logical/pki/path_issue_sign.go
Expand Up @@ -2,6 +2,7 @@ package pki

import (
"context"
"crypto/rand"
"encoding/base64"
"fmt"
"time"
Expand Down Expand Up @@ -219,7 +220,7 @@ func (b *backend) pathIssueSignCert(ctx context.Context, req *logical.Request, d
if useCSR {
parsedBundle, err = signCert(b, input, signingBundle, false, useCSRValues)
} else {
parsedBundle, err = generateCert(ctx, b, input, signingBundle, false)
parsedBundle, err = generateCert(ctx, b, input, signingBundle, false, rand.Reader)
}
if err != nil {
switch err.(type) {
Expand Down
2 changes: 1 addition & 1 deletion builtin/logical/pki/path_root.go
Expand Up @@ -155,7 +155,7 @@ func (b *backend) pathCAGenerateRoot(ctx context.Context, req *logical.Request,
apiData: data,
role: role,
}
parsedBundle, err := generateCert(ctx, b, input, nil, true)
parsedBundle, err := generateCert(ctx, b, input, nil, true, b.Backend.GetRandomReader())
if err != nil {
switch err.(type) {
case errutil.UserError:
Expand Down
3 changes: 3 additions & 0 deletions changelog/12559.txt
@@ -0,0 +1,3 @@
```release-note:improvement
secrets/pki: Use entropy augmentation when available when generating root and intermediate CA key material.
```