add let's encrypt certificate missing on some older android devices (#2752)

* add let's encrypt certificate missing on some older android devices

* create Certificate with Lazy::new()

* document certificate source

* use smaller *.der format instead of *.pem
This commit is contained in:
bjoern
2021-10-17 14:28:34 +02:00
committed by GitHub
parent 7fb305e898
commit 41ec380b55
2 changed files with 22 additions and 1 deletions

Binary file not shown.

View File

@@ -11,8 +11,10 @@ use anyhow::Result;
use async_std::io;
use async_std::net::TcpStream;
use async_native_tls::Certificate;
pub use async_smtp::ServerAddress;
use fast_socks5::client::Socks5Stream;
use once_cell::sync::Lazy;
#[derive(Copy, Clone, Debug, Display, FromPrimitive, PartialEq, Eq)]
#[repr(u32)]
@@ -368,8 +370,18 @@ fn get_readable_flags(flags: i32) -> String {
res
}
// this certificate is missing on older android devices (eg. lg with android6 from 2017)
// certificate downloaded from https://letsencrypt.org/certificates/
static LETSENCRYPT_ROOT: Lazy<Certificate> = Lazy::new(|| {
Certificate::from_der(include_bytes!(
"../assets/root-certificates/letsencrypt/isrgrootx1.der"
))
.unwrap()
});
pub fn dc_build_tls(strict_tls: bool) -> async_native_tls::TlsConnector {
let tls_builder = async_native_tls::TlsConnector::new();
let tls_builder =
async_native_tls::TlsConnector::new().add_root_certificate(LETSENCRYPT_ROOT.clone());
if strict_tls {
tls_builder
@@ -430,4 +442,13 @@ mod tests {
assert_eq!(param, loaded);
Ok(())
}
#[async_std::test]
async fn test_build_tls() -> Result<()> {
// we are using some additional root certificates.
// make sure, they do not break construction of TlsConnector
let _ = dc_build_tls(true);
let _ = dc_build_tls(false);
Ok(())
}
}