Repository: go
Issue: crypto/x509: potentially anomalous path building results
Labels: Security,NeedsInvestigation

### Go version

go1.21.5 linux/amd64

### Output of `go env` in your module/workspace:

```shell
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/runner/.cache/go-build'
GOENV='/home/runner/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/runner/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/runner/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/hostedtoolcache/go/1.21.5/x64'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/hostedtoolcache/go/1.21.5/x64/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.21.5'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1019109943=/tmp/go-build -gno-record-gcc-switches'
```


### What did you do?

Hi there! I'm opening this to root-cause a [handful](https://x509-limbo.com/anomalous-results/gocryptox509-go1.21.5/) of potentially anomalous path building results with `crypto/x509`, which we found with [x509-limbo](https://x509-limbo.com/).

First, a disclaimer: I suspect that many of the results above are expected or are non-issues from crypto/x509's perspective, since many are "pedantic" checks against a strict reading of RFC 5280. For example, [`rfc5280::nc::not-allowed-in-ee-critical`](https://x509-limbo.com/testcases/rfc5280/#rfc5280ncnot-allowed-in-ee-critical) is technically disallowed under RFC 5280, but all other implementations appear to broadly ignore it.

There are, however, some discrepancies for which crypto/x509 is the outlier. A sampling of anomalous positives (chains built where other implementations fail):

* [`rfc5280::aki::critical-aki`](https://x509-limbo.com/testcases/rfc5280/#rfc5280akicritical-aki): all other implementations under test reject critical AKIs; crypto/x509 accepts it
* [`rfc5280::nc::nc-permits-invalid-dns-san`](https://x509-limbo.com/testcases/rfc5280/#rfc5280ncnc-permits-invalid-dns-san): crypto/x509 and OpenSSL both accept a malformed DNS SAN that conflicts with a Name Constraint
* [`rfc5280::ee-critical-aia-invalid`](https://x509-limbo.com/testcases/rfc5280/#rfc5280ee-critical-aia-invalid): all other implementations reject critical AIAs; crypto/x509 accepts them (despite not supporting AIA chasing)

There are also some anomalous negatives (chains that fail to build where success is expected), but crypto/x509 is largely in consensus with other implementations around them (the main outlier is OpenSSL).


### What did you see happen?

The full rendering of potentially anomalous results is here: <https://x509-limbo.com/anomalous-results/gocryptox509-go1.21.5/>

As mentioned above, some of these are almost certainly intended behavior on crypto/x509's part as part of handling real-world chains, especially outside of the Web PKI. However, I could find a document or docstring anywhere that explicitly enumerated these (in absolute fairness, nobody does this 🙂), so I figured I would open this up for general review and consideration.

### What did you expect to see?

In cases involving critical or out-of-policy extensions that crypto/x509 appears to otherwise ignore, I expected to see chain build failures rather than successes. However, see qualifications above 🙂