rustls / tokio-rustls

Async TLS for the Tokio runtime
Apache License 2.0
125 stars 70 forks source link

Reading cert chain and private key not working for axum-admin #86

Closed greenpdx closed 1 month ago

greenpdx commented 1 month ago

I am trying to get https://github.com/lingdu1234/axum_admin working. In axum_admin/bin/src/main.rs in "rustls_server_config" function is failing because it changed from Certificate to CertificateDer.
I believe the problem is old dependence else where in Cargo.toml ( will be updating the toml files)

Using the code published let lcerts: Vec<_> = CertificateDer::pem_file_iter(&CFG.cert.cert).unwrap().collect();

I get this error mismatched types expected struct Vec<CertificateDer<'static>> found struct `Vec<Result<CertificateDer<'_>, rustls_pki_types::pem::Error>>

This error is telling me that there is a unwrap()/match not being executed in the pem_file_iter() function.

Why? Where would I look to fix it? How do I fix this?

Later I will ask about reading in the private key

ctz commented 1 month ago

To get a Vec<CertificateDer<'static>>, try this:

CertificateDer::pem_file_iter("filename.pem")
    .expect("cannot open file")
    .map(|c| c.expect("file contains invalid data"))
    .collect()
greenpdx commented 1 month ago

thanks