Repository: seanmonstar/reqwest (language: rust)

Issue:
Unable to parse CA trust store PEM file of ubuntu
Hello,

I'm currently want to try the new API [from_pem_bundle](https://docs.rs/reqwest/latest/reqwest/tls/struct.Certificate.html#method.from_pem_bundle) with the embedded ca store bundle on my ubuntu 22.04 (/etc/ssl/certs/ca-certificates.crt) but didn't manage to.

With this simple program (tested with reqwest 0.11.24)
```
use std::io::Read;
use std::result::Result;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut cert_bundle_buffer = Vec::new();
    std::fs::File::open("/etc/ssl/certs/ca-certificates.crt")?.read_to_end(&mut cert_bundle_buffer)?;
    match reqwest::Certificate::from_pem_bundle(&cert_bundle_buffer) {
        Ok(certs) => {
            for cert in certs {
                println!("add root cert {:?} ", cert);
            }
        },
        Err(e) => {
            println!("Cannot parse cert bundle file: {e}");
        }
    }
    Ok(())
}
```

I have
```
Cannot parse cert bundle file: builder error: error:0480006C:PEM routines:get_name:no start line:../crypto/pem/pem_lib.c:763:Expecting: CERTIFICATE
```

Openssl command manage to parse this bundle and find 137 certificates:
```
openssl storeutl -noout -text -certs /etc/ssl/certs/ca-certificates.crt
````

Do you know if this expected, am I missing some feature that must be enabled on the crate ?


Discussion / hints:
Do you know @gibbz00?
I think the issue is the usage of from_pem methods since [rustlfs_pemfile::certs](https://docs.rs/rustls-pemfile/2.0.0/rustls_pemfile/fn.certs.html) that is used under the hood return der encoded certificates , not pem .

I'll open a PR but maybe I misunderstood the usage of this method ( Edit: #2126 )
Hi, I'll take a look at this during the weekend. Quite busy with work right now, sorry :/


Fix patch:
diff --git a/src/tls.rs b/src/tls.rs
index 7b2e9532f..717a6abbc 100644
--- a/src/tls.rs
+++ b/src/tls.rs
@@ -163,7 +163,7 @@ impl Certificate {
 
         Self::read_pem_certs(&mut reader)?
             .iter()
-            .map(|cert_vec| Certificate::from_pem(&cert_vec))
+            .map(|cert_vec| Certificate::from_der(&cert_vec))
             .collect::<crate::Result<Vec<Certificate>>>()
     }
 
@@ -590,4 +590,38 @@ mod tests {
 
         Identity::from_pem(pem).unwrap();
     }
+
+    #[test]
+    fn certificates_from_pem_bundle() {
+        const PEM_BUNDLE: &[u8] = b"
+            -----BEGIN CERTIFICATE-----
+            MIIBtjCCAVugAwIBAgITBmyf1XSXNmY/Owua2eiedgPySjAKBggqhkjOPQQDAjA5
+            MQswCQYDVQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRkwFwYDVQQDExBBbWF6b24g
+            Um9vdCBDQSAzMB4XDTE1MDUyNjAwMDAwMFoXDTQwMDUyNjAwMDAwMFowOTELMAkG
+            A1UEBhMCVVMxDzANBgNVBAoTBkFtYXpvbjEZMBcGA1UEAxMQQW1hem9uIFJvb3Qg
+            Q0EgMzBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABCmXp8ZBf8ANm+gBG1bG8lKl
+            ui2yEujSLtf6ycXYqm0fc4E7O5hrOXwzpcVOho6AF2hiRVd9RFgdszflZwjrZt6j
+            QjBAMA8GA1UdEwEB/wQFMAMBAf8wDgYDVR0PAQH/BAQDAgGGMB0GA1UdDgQWBBSr
+            ttvXBp43rDCGB5Fwx5zEGbF4wDAKBggqhkjOPQQDAgNJADBGAiEA4IWSoxe3jfkr
+            BqWTrBqYaGFy+uGh0PsceGCmQ5nFuMQCIQCcAu/xlJyzlvnrxir4tiz+OpAUFteM
+            YyRIHN8wfdVoOw==
+            -----END CERTIFICATE-----
+
+            -----BEGIN CERTIFICATE-----
+            MIIB8jCCAXigAwIBAgITBmyf18G7EEwpQ+Vxe3ssyBrBDjAKBggqhkjOPQQDAzA5
+            MQswCQYDVQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRkwFwYDVQQDExBBbWF6b24g
+            Um9vdCBDQSA0MB4XDTE1MDUyNjAwMDAwMFoXDTQwMDUyNjAwMDAwMFowOTELMAkG
+            A1UEBhMCVVMxDzANBgNVBAoTBkFtYXpvbjEZMBcGA1UEAxMQQW1hem9uIFJvb3Qg
+            Q0EgNDB2MBAGByqGSM49AgEGBSuBBAAiA2IABNKrijdPo1MN/sGKe0uoe0ZLY7Bi
+            9i0b2whxIdIA6GO9mif78DluXeo9pcmBqqNbIJhFXRbb/egQbeOc4OO9X4Ri83Bk
+            M6DLJC9wuoihKqB1+IGuYgbEgds5bimwHvouXKNCMEAwDwYDVR0TAQH/BAUwAwEB
+            /zAOBgNVHQ8BAf8EBAMCAYYwHQYDVR0OBBYEFNPsxzplbszh2naaVvuc84ZtV+WB
+            MAoGCCqGSM49BAMDA2gAMGUCMDqLIfG9fhGt0O9Yli/W651+kI0rz2ZVwyzjKKlw
+            CkcO8DdZEv8tmZQoTipPNU0zWgIxAOp1AE47xDqUEpHJWEadIRNyp4iciuRMStuW
+            1KyLa2tJElMzrdfkviT8tQp21KW8EA==
+            -----END CERTIFICATE-----
+        ";
+
+        assert!(Certificate::from_pem_bundle(PEM_BUNDLE).is_ok())
+    }
 }


Test patch: