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

asn1: syntax error: PrintableString contains invalid character #43275

Closed
tengmatest opened this issue Dec 19, 2020 · 1 comment
Closed

asn1: syntax error: PrintableString contains invalid character #43275

tengmatest opened this issue Dec 19, 2020 · 1 comment

Comments

@tengmatest
Copy link

tengmatest commented Dec 19, 2020

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

$ go version
go version go1.14.2 darwin/amd64

Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

$ go env
mac

What did you do?

try to parse a CA file:

block, _ := pem.Decode(certBits)
ca, _ := x509.ParseCertificate(block.Bytes) 

What did you expect to see?

success

What did you see instead?

asn1: syntax error: PrintableString contains invalid character

this ca has special character, like "_" "@"

but encoding.asn1.isPrintable() not support .

current code:

// isPrintable reports whether the given b is in the ASN.1 PrintableString set.
// If asterisk is allowAsterisk then '*' is also allowed, reflecting existing
// practice. If ampersand is allowAmpersand then '&' is allowed as well.
func isPrintable(b byte, asterisk asteriskFlag, ampersand ampersandFlag) bool {
	return 'a' <= b && b <= 'z' ||
		'A' <= b && b <= 'Z' ||
		'0' <= b && b <= '9' ||
		'\'' <= b && b <= ')' ||
		'+' <= b && b <= '/' ||
		b == ' ' ||
		b == ':' ||
		b == '=' ||
		b == '?' ||
		// This is technically not allowed in a PrintableString.
		// However, x509 certificates with wildcard strings don't
		// always use the correct string type so we permit it.
		(bool(asterisk) && b == '*') ||
		// This is not technically allowed either. However, not
		// only is it relatively common, but there are also a
		// handful of CA certificates that contain it. At least
		// one of which will not expire until 2027.
		(bool(ampersand) && b == '&')
}
@tengmatest
Copy link
Author

find old issue

@tengmatest tengmatest reopened this Dec 19, 2020
@golang golang locked and limited conversation to collaborators Dec 19, 2021
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

2 participants