Validate PEM format in Certificate::from_pem for rustls#2970
Open
veeceey wants to merge 1 commit intoseanmonstar:masterfrom
Open
Validate PEM format in Certificate::from_pem for rustls#2970veeceey wants to merge 1 commit intoseanmonstar:masterfrom
veeceey wants to merge 1 commit intoseanmonstar:masterfrom
Conversation
Certificate::from_pem with the rustls backend was silently accepting DER-encoded input. The bytes were stored as-is and only failed later when added to the root certificate store, making it hard to debug. Now eagerly validates that the input contains at least one valid PEM certificate at construction time, matching the behavior of the native-tls backend which already rejects non-PEM input. Fixes seanmonstar#1858
Author
|
friendly bump! happy to make changes if anything needs updating |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1858
Certificate::from_pemwith the rustls backend was silently accepting DER-encoded input, only failing later during the TLS handshake with a confusing error. This happened because the rustls path just stored the raw bytes without any validation.Now it eagerly parses the PEM data upfront using
rustls_pemfile::certsand returns a clear error if no valid PEM certificates are found. The native-tls backend already validated eagerly, so this brings rustls in line.Added two tests to verify the behavior:
certificate_from_pem_invalid_rustls- rejects garbage inputcertificate_from_pem_rejects_der- rejects DER-encoded bytes