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

trailing white space in "-----BEGIN CERTIFICATE----- " causes readPemObject returning null #1533

Closed
WalkerWalker opened this issue Nov 16, 2023 · 3 comments

Comments

@WalkerWalker
Copy link

WalkerWalker commented Nov 16, 2023

if the certificate starts with "-----BEGIN CERTIFICATE----- ", or in general any pem with the begining line including a trailing white space, the readPemObject() function would return null and this causes the readObject in PEMParser to also return null.

It is because this line of code

if (index > 0 && line.endsWith("-----") && (line.length() - index) == 5)

I wonder if this is design choice or not? There are some old discussions about whether trailing white space(s) are allowed in x509certificate https://stackoverflow.com/questions/26496155/are-spaces-alowed-in-x509-certificates but it seems to me that the answers are not clear.

@dghgit
Copy link
Contributor

dghgit commented Nov 17, 2023

I'll admit it is a bit of a weird one, our parser was originally based on RFC 1421, the grammar at the end of it gives:

   <preeb> ::= "-----BEGIN PRIVACY-ENHANCED MESSAGE-----" CRLF
   <posteb> ::= "-----END PRIVACY-ENHANCED MESSAGE-----" CRLF / <preeb>

So at least as far as the original PEM definition goes, trailing white space would be an error. RFC 7468 is more recent and appears somewhat more forgiving though - the grammar in section 3 doesn't require CRLF and the standard does specifically talk about ignore whitespace. I think we can accommodate a line.trim() prior to doing the checks. I'll put it on the list.

@dghgit
Copy link
Contributor

dghgit commented Dec 8, 2023

This is now done in 178b02 - see https://www.bouncycastle.org/betas for details.

@WalkerWalker
Copy link
Author

WalkerWalker commented Jun 19, 2024

Thanks for the support. I wonder if 178b02 is included in 1.78 and/or 1.78.1 published in April, or not? Or one needs to wait until 1.79 to have the change in this ticket?

This is now done in 178b02 - see https://www.bouncycastle.org/betas for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants