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

proposal: x/crypto: decode ASN.1 BOOLEAN 0x01 as true when validating certificate basic constraints #53932

Closed
jtallinger opened this issue Jul 18, 2022 · 1 comment

Comments

@jtallinger
Copy link

Hi,

When parsing a private root certificate I get following error:
x509: invalid basic constraints b

Decoding the certificate we can see:

OBJECT IDENTIFIER basicConstraints (2.5.29.19)
BOOLEAN TRUE
OCTET STRING 30 03 01 01 01

ASN.1 BER encoding specifies that for booleans, false is encoded as 0 and true as any non-0 value. However, for DER (which is a subset of BER) true has only one legal value: 255. Meaning the above certificate is not using the correct value (01 instead of FF).

Now the issue is that many applications are wrongly using 01 and clients accept that (Curl, Chrome etc.). One could argue that it should be fixed in the application issuing the cert, but this is difficult to justify when thousands of devices have been deployed with this certificate and other clients interpret 01 as true and it has worked fine for years.

With the current Go crypto implementation the validation is very strict, preventing us from using Go's http client to validate tls connection unless InsecureSkipVerify is set to true.

For the sake of compatibility with other languages and legacy setups I propose we add "case 1: *out = true" to crypto/cryptobyte/asn1.go ReadASN1Boolean() which solves the problem.

https://github.com/golang/go/blob/master/src/vendor/golang.org/x/crypto/cryptobyte/asn1.go#L249-L265

func (s *String) ReadASN1Boolean(out *bool) bool {
	var bytes String
	if !s.ReadASN1(&bytes, asn1.BOOLEAN) || len(bytes) != 1 {
		return false
	}

	switch bytes[0] {
	case 0:
		*out = false
	case 1:
		*out = true
	case 0xff:
		*out = true
	default:
		return false
	}

	return true
}
@gopherbot gopherbot added this to the Proposal milestone Jul 18, 2022
@seankhliao
Copy link
Member

Duplicate of #11091

@seankhliao seankhliao marked this as a duplicate of #11091 Jul 18, 2022
@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Jul 18, 2022
@golang golang locked and limited conversation to collaborators Jul 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants