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

crypto/x509: Verify allows serialNumber larger than 20 octets #72076

Open
dulanshuangqiao opened this issue Mar 3, 2025 · 7 comments
Open

crypto/x509: Verify allows serialNumber larger than 20 octets #72076

dulanshuangqiao opened this issue Mar 3, 2025 · 7 comments
Labels
BugReport Issues describing a possible bug in the Go implementation. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Unfortunate

Comments

@dulanshuangqiao
Copy link

Go version

go version go1.23.2 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/liu/.cache/go-build'
GOENV='/home/liu/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/liu/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/liu/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/snap/go/10730'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/snap/go/10730/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.23.2'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/liu/.config/go/telemetry'
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-build578094757=/tmp/go-build -gno-record-gcc-switches'

What did you do?

Perform certificate verification
go run go_verify.go
The execution result is passed verification
Certificate is valid!
I provide the test case used:certs&program.zip

What did you see happen?

RFC5280 states: Conforming CAs MUST NOT use serialNumber values longer than 20 octets.
GnuTLS performs this check during validation and refuses to accept such certificates.

certtool --verify --load-ca-certificate RootCA.pem --infile Cert174065870010.pem:
Loaded CAs (1 available)
|<2>| error: serial number value is longer than 20 octets
error parsing CRTs: Error in the certificate.
Setting log level to 10

What did you expect to see?

Validation failed

@mateusz834
Copy link
Member

See CL 589615.

CC @rolandshoemaker

@dulanshuangqiao
Copy link
Author

See CL 589615.

CC @rolandshoemaker

The GnuTLS results I provide as a comparison are based on gnutls-3.8.9 (2025-02-08)

@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label Mar 3, 2025
@JunyangShao
Copy link
Contributor

@golang/security

@JunyangShao JunyangShao added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 3, 2025
@rolandshoemaker
Copy link
Member

There is unfortunately not really anything we can do here. We tried restricting serials to 20 octets, and the public PKI works fine, but far far too many private PKIs get this horribly wrong and the breakage we saw was not worth enforcing this constraint.

@seankhliao seankhliao changed the title crypto/x509: Golang verification passed Serial Number with incorrect length crypto/x509: Verify allows serialNumber larger than 20 octets Mar 3, 2025
@dulanshuangqiao
Copy link
Author

There is unfortunately not really anything we can do here. We tried restricting serials to 20 octets, and the public PKI works fine, but far far too many private PKIs get this horribly wrong and the breakage we saw was not worth enforcing this constraint.

Thanks for your reply.
GnuTLS-3.8.9 adds this check under the --enable-strict-x509 configuration option. For reference, can this issue be made into a feature, and whether to enable this restriction is decided by the configuration option?

@ianlancetaylor
Copy link
Member

It is possible, but every configuration knob is an expense for maintenance, testing, and code comprehension. We wouldn't do it just because we can. We would only do it if there is a good reason for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BugReport Issues describing a possible bug in the Go implementation. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Unfortunate
Projects
None yet
Development

No branches or pull requests

7 participants