Skip to content

crypto/x509: VerifyOptions.Roots does not enforce that certificates are root certificates #51953

Description

@Hayden-IO

What version of Go are you using (go version)?

$ go version

1.18

What did you do?

https://go.dev/play/p/InpOJXUXnUl

A leaf and intermediate certificate can be provided to the root pool.

What did you expect to see?

I expected that verification would fail due to the lack of root certificates.

What did you see instead?

Successful verification.

It's unclear to me if this is an intentional feature or a bug.

Should a certificate in a root pool always be a CA certificate (related to RFC5280 4.2.1.9)?
The check that a parent is a CA certificate occurs in CheckSignatureFrom, called in buildChains, which is bypassed because the leaf certificate is in the root pool (https://go.dev/src/crypto/x509/verify.go#L781). Allowing a non-CA certificate to be verified successfully against itself seems prone to bugs.

Is a root certificate meant to be defined as a self-signed certificate, or any certificate that forms the trust anchor?
I expected that it must be a self-signed certificate, but an intermediate was permitted. This also seems prone to bugs, for example if a client supports a user-provided certificate chain and the client isn't enforcing that a chain is formed from a root.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions