Skip to content

Commit

Permalink
Rename to EnableFallbackLegacyX509CertificateParser
Browse files Browse the repository at this point in the history
  • Loading branch information
hslatman committed Sep 10, 2024
1 parent 7537d36 commit 9c9d681
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions parse_go1.23_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ func TestParseWindowsSCEPCertificateRequest(t *testing.T) {
}

// enable the legacy parser when Go 1.23 or newer is used, and parse it again
EnableLegacyFallbackX509CertificateParser = true
EnableFallbackLegacyX509CertificateParser = true
p7, err = Parse(data)
if err != nil {
t.Errorf("failed parsing SCEP request data with legacy X509 certificate parser enabled: %v", err)
}
EnableLegacyFallbackX509CertificateParser = false
EnableFallbackLegacyX509CertificateParser = false

if len(p7.Certificates) != 1 {
t.Errorf("expected a single certificate; got %d", len(p7.Certificates))
Expand Down
8 changes: 4 additions & 4 deletions pkcs7.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func parseEncryptedData(data []byte) (*PKCS7, error) {
}, nil
}

// EnableLegacyFallbackX509CertificateParser enables parsing certificates
// EnableFallbackLegacyX509CertificateParser parsing certificates
// embedded in a PKCS7 message using the logic from crypto/x509 from before
// Go 1.23. Go 1.23 introduced a breaking change in case a certificate contains
// a critical authority key identifier, which is the correct thing to do based
Expand All @@ -226,12 +226,12 @@ func parseEncryptedData(data []byte) (*PKCS7, error) {
// See https://go-review.googlesource.com/c/go/+/562341 for the change in the
// Go source.
//
// When [EnableLegacyFallbackX509CertificateParser] is set to true, it'll first
// When [EnableFallbackLegacyX509CertificateParser] is set to true, it'll first
// try to parse the certificates using the regular Go crypto/x509 package, but
// if it fails on the above case, it'll retry parsing the certificates using a
// copy of the crypto/x509 package based on Go 1.23, but skips checking the
// authority key identifier extension being critical or not.
var EnableLegacyFallbackX509CertificateParser bool
var EnableFallbackLegacyX509CertificateParser bool

func (raw rawCertificates) Parse() ([]*x509.Certificate, error) {
if len(raw.Raw) == 0 {
Expand All @@ -245,7 +245,7 @@ func (raw rawCertificates) Parse() ([]*x509.Certificate, error) {

certificates, err := x509.ParseCertificates(val.Bytes)
if err != nil && err.Error() == "x509: authority key identifier incorrectly marked critical" {
if EnableLegacyFallbackX509CertificateParser {
if EnableFallbackLegacyX509CertificateParser {
certificates, err = legacyx509.ParseCertificates(val.Bytes)
}
}
Expand Down

0 comments on commit 9c9d681

Please sign in to comment.