reqwest::Certificate::from_der and reqwest::Certificate::from_pem are inconsistent #1858
Labels
C-bug
Category: bug. Something is wrong. This is bad!
E-pr-welcome
The feature is welcome to be added, instruction should be found in the issue.
The reqwest::Certificate::from_der and reqwest::Certificate::from_pem functions have some inconsistent behavior (at least on MacOS) that can result in some difficult to troubleshoot issues. When you pass a DER-encoded buffer to the from_pem function, it does not fail but it yields a Certificate object that does not work. It does not work because internally the parse function just saves the buffer in an enum that indicates it is PEM then later an attempt is made to parse the buffer as PEM and fails. Attempting to parse PEM using from_der fails (hence the inconsistency). Ideally, from_pem would fail when presented a DER buffer.
The sample code below used these dependencies:
tokio = { version = "1.28.1", features = ["macros", "rt-multi-thread"] }
hex-literal = "0.4.1"
reqwest = {version = "0.11.18", features = ["rustls-tls"]}
The sample code include comments for generating test keys and certs using openssl and for using openssl s_server to stage the test. For parsing, each combination of PEM and DER is exercised, with only the attempt to parse DER using from_pem yielding unexpected results. One successfully parsed certificate and the non-functional certificate returned by from_pem are used to connect to the server (with the former working and the latter failing).
The text was updated successfully, but these errors were encountered: