ASN.1 Syntax Error: Trailing Data on valid CSR?

I have a CSR generated using openssl 1.1.0 for a fairly simple request - two names, as a normal SAN certificate. All the CSR validators claim it is valid, and it seems to contain the right data.

When I attempt to use the ZeroSSL LE client to request a certificate, I get this error (which I think is coming from LE):

Error requesting certificate: Error parsing certificate request: asn1: syntax error: trailing data

I’m generating the CSR using this openssl command:

OpenSSL req -config PDConSec.cfg -new -sha256 -key PDConSec.KEY -out PDConSec.CRT -batch -subj "/CN=www.pdconsec.net"

There’s a corresponding configuration file SiteAlias.cfg:

[req]
req_extensions = req_ext
distinguished_name = dn
[ dn ]
[ req_ext ]
subjectAltName = @alt_names
[alt_names]
DNS.1=www.pdconsec.net
DNS.2=pdconsec.net

It generates a CSR that validates on Comodo, Symantec etc. Is there something special I need to do to openssl to get it to generate “cleaner” output? I would have thought OpenSSL was basically the gold standard for most things SSL/certificate-based.

The only items I found in multiple Google searches were about changes to a Go code file, in which a change was merged to be strict about trailing data even though it’s not a security risk. I can’t see how that would affect this, but … you never know.

Suggestions on a fix are very welcome.

Edit: It seems that if I invert the order of the two names the CSR is accepted (so the last two lines of the CFG file are as follows:

DNS.1=pdconsec.net
DNS.2=www.pdconsec.net

This would seem to be functionally identical other than the order of the SANs. I’m not … horribly upset, but I’d really like to know what is going wrong so I don’t have to debug this in a hurry in six months time.

Edit 2: I don’t understand - some CSRs with a single name work, others with a single name fail. One with four names works with the www name first, but three others with only www.site.net and site.net do not unless I order them with the www name second. I don’t really even know what to look for, now.

Hi @DavidRawling,

Could you post an example of a CSR that validates and an example of one that fails to validate?

Hi Schoen

I’ve generated a test key using:

C:\OpenSSL-Win64\bin\openssl.exe genrsa -out PDConSec-Test.Key 2048

Here’s a failing sequence:

OpenSSL configuration PDConSec-Test1.cfg:

[req]
req_extensions = req_ext
distinguished_name = dn
[ dn ]
[ req_ext ]
subjectAltName = @alt_names
[alt_names]
DNS.1=www.pdconsec.net
DNS.2=pdconsec.net

CSR generation:

C:\OpenSSL-Win64\bin\openssl.exe req -config .\PDConSec-Test1.cfg -new -sha256 -key .\PDConSec-Test.Key -out .\PDConSec-Test1.csr -batch -subj "/CN=www.pdconsec.net"

Resulting CSR (Fails ASN.1 validation for trailing data):

-----BEGIN CERTIFICATE REQUEST-----
MIICnDCCAYQCAQAwGzEZMBcGA1UEAwwQd3d3LnBkY29uc2VjLm5ldDCCASIwDQYJ
KoZIhvcNAQEBBQADggEPADCCAQoCggEBANGp6Qa/2h5fqDCmpx4pYqqfClNwGKlF
fwAVt3b5hfAf8XNx/+ikeDnvGXaip/1SeJKJfI+hftATqQTHW3uBiYdtpQRHRgS2
jqdVXmSYb4LwO4w3dLPafIgOD79Ey/6Cm4+zqAvmYJdip4Sx/Wy8AWMUQ4MYQnjI
Yuuj7xHFBjVDmKoeLCrcyBL6BlSBSeREpghUHAmRDJCR4fH4vQdfKORiACcH2HKe
DDN4qXk1dRvCV9UOpuzfwUIySCCU98dRx4BRYiQ84v/Buc5laEfiIU2PyKjs23x5
HYantOzZKLGtm1J2E60SNu8jNn0nsxfL4nHGWZC3NJpc4hGGRTm1RsECAwEAAaA8
MDoGCSqGSIb3DQEJDjEtMCswKQYDVR0RBCIwIIIQd3d3LnBkY29uc2VjLm5ldIIM
cGRjb25zZWMubmV0MA0GCSqGSIb3DQEBCwUAA4IBAQCCsplnfz/kwbAhlRpahr1I
IUajguvq8JJruVrjx7rkhOZ+gAXIRBDUDDhDYN9ae9qFIAgetiq/GcyOWbLHcinT
qeGpuBhDhdbzT/SzGFX4rui0/KmZc1TEndZnN2y/EjJDlzgYmiVgFd0Qj70EStzu
+SuNu/ugqa6otTqS+LFVncYNshEvLK+dF0ucIjSp4zRGaaCCCH14ZoT3B6qs5pzc
e/kkpYH/iujLamfBk3CIoCcnc+xz7Gp7mnfbRBwmrLqho9vBvhuewy453CJlp+JT
dgCnNDloLeFYXKaKXsCis169stiq/ZQ6WTMX96smz4K5TAS3YSXXSeqKqJ4jTppJ
-----END CERTIFICATE REQUEST-----

And the validated set follows.

OpenSSL configuration PDConSec-Test2.cfg:

[req]
req_extensions = req_ext
distinguished_name = dn
[ dn ]
[ req_ext ]
subjectAltName = @alt_names
[alt_names]
DNS.1=pdconsec.net
DNS.2=www.pdconsec.net

CSR generation:

C:\OpenSSL-Win64\bin\openssl.exe req -config .\PDConSec-Test2.cfg -new -sha256 -key .\PDConSec-Test.Key -out .\PDConSec-Test2.csr -batch -subj "/CN=pdconsec.net"

Resulting CSR:

-----BEGIN CERTIFICATE REQUEST-----
MIICmDCCAYACAQAwFzEVMBMGA1UEAwwMcGRjb25zZWMubmV0MIIBIjANBgkqhkiG
9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0anpBr/aHl+oMKanHiliqp8KU3AYqUV/ABW3
dvmF8B/xc3H/6KR4Oe8ZdqKn/VJ4kol8j6F+0BOpBMdbe4GJh22lBEdGBLaOp1Ve
ZJhvgvA7jDd0s9p8iA4Pv0TL/oKbj7OoC+Zgl2KnhLH9bLwBYxRDgxhCeMhi66Pv
EcUGNUOYqh4sKtzIEvoGVIFJ5ESmCFQcCZEMkJHh8fi9B18o5GIAJwfYcp4MM3ip
eTV1G8JX1Q6m7N/BQjJIIJT3x1HHgFFiJDzi/8G5zmVoR+IhTY/IqOzbfHkdhqe0
7Nkosa2bUnYTrRI27yM2fSezF8viccZZkLc0mlziEYZFObVGwQIDAQABoDwwOgYJ
KoZIhvcNAQkOMS0wKzApBgNVHREEIjAgggxwZGNvbnNlYy5uZXSCEHd3dy5wZGNv
bnNlYy5uZXQwDQYJKoZIhvcNAQELBQADggEBALw5rkZO2bPSlGV2PxuABAclA0LM
w/0axdozgVFiXAY1+FqMfLgg8ffCTmV0J0p6lC8sNnBNWzTPLopkm5GdNrMKqQmU
wzXWA4JK5RuL67P6oTAy7KmUdZzH8PrjwpoewVkH2zfiPQZm507TWhMZ4srME1ZY
C6ZGqH4+G2uyJBUPBHKznCX+6VBOr8a9/9ZdAuE4g4unGuhb1wB/4eOX3lbDjUg6
TcdR0s/9c8dz3fhoMmsIKLp0sKPutm+G6xRFN40VQyTBaN2RIZDNbUdChjmOszWS
/Fw4MfQotiCe8g8wfBkLnaBPmzXiCVbHmtvTKtkChlyg3SwgECNoUe5NR5I=
-----END CERTIFICATE REQUEST-----

Thanks for posting this, I’ll have a look. I believe online ZeroSSL client should have no problems with this CSR and also letting LE.pl/LE.exe to create a CSR based on your [domain] key (or the key generated for you by the client itself) should work fine, but it would be good to get to the root cause of this anyway.

P.S. I believe I might know what might be happening in this case. Just to double-check, could you send me a few examples of non-working CSRs exactly the way they are stored? I’ll pm the email.

Thanks @leader, I’ve sent those to the email address in your PM. Luckily, I can regenerate them (since my script cleaned them up by default).

This should now be resolved - “a curious case” of CSRs produced with [some] external tools on Windows, and the way those were converted. Thanks for flagging that, it allowed me to replace one dependency with the code that should read those (and also some malformed) CSRs. The change will go to CPAN with v0.25, but it is now included already into Windows binaries of 0.24 release.

1 Like

Looks good - all the certs I had left to renew were successfully renewed. Sorry for conflating the two potential sources of issue together - looks like it was definitely a ZeroSSL problem, now fixed.

I’m glad @leader was able to take a look and figure this out!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.