Skip to content

Commit

Permalink
Add hook for ENT tweaking of PKI contraints verification options.
Browse files Browse the repository at this point in the history
  • Loading branch information
victorr committed Nov 27, 2024
1 parent 48cec97 commit e6cbc06
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
8 changes: 7 additions & 1 deletion builtin/logical/pki/issuing/cert_verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
package issuing

import (
"context"
"fmt"
"github.com/hashicorp/vault/sdk/logical"
"os"
"strconv"
"time"
Expand Down Expand Up @@ -33,7 +35,7 @@ func isCertificateVerificationDisabled() (bool, error) {
return disable, nil
}

func VerifyCertificate(parsedBundle *certutil.ParsedCertBundle) error {
func VerifyCertificate(ctx context.Context, storage logical.Storage, issuerId IssuerID, parsedBundle *certutil.ParsedCertBundle) error {
if verificationDisabled, err := isCertificateVerificationDisabled(); err != nil {
return err
} else if verificationDisabled {
Expand Down Expand Up @@ -68,6 +70,10 @@ func VerifyCertificate(parsedBundle *certutil.ParsedCertBundle) error {
DisableNameConstraintChecks: false,
}

if err := entSetCertVerifyOptions(ctx, storage, issuerId, &options); err != nil {
return err
}

certificate, err := convertCertificate(parsedBundle.CertificateBytes)
if err != nil {
return err
Expand Down
19 changes: 19 additions & 0 deletions builtin/logical/pki/issuing/issuing_stubs_oss.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1

//go:build !enterprise

package issuing

import (
"context"

ctx509 "github.com/google/certificate-transparency-go/x509"
"github.com/hashicorp/vault/sdk/logical"
)

//go:generate go run github.com/hashicorp/vault/tools/stubmaker

func entSetCertVerifyOptions(ctx context.Context, storage logical.Storage, issuerId IssuerID, options *ctx509.VerifyOptions) error {
return nil
}
2 changes: 1 addition & 1 deletion builtin/logical/pki/path_issue_sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ func (b *backend) pathIssueSignCert(ctx context.Context, req *logical.Request, d
}
}

if err := issuing.VerifyCertificate(parsedBundle); err != nil {
if err := issuing.VerifyCertificate(sc.GetContext(), sc.GetStorage(), issuerId, parsedBundle); err != nil {
return nil, err
}

Expand Down

0 comments on commit e6cbc06

Please sign in to comment.