Skip to content

Instantly share code, notes, and snippets.

@Gsantomaggio
Last active July 25, 2023 14:19
Show Gist options
  • Save Gsantomaggio/52474bda544504ee74599484652776df to your computer and use it in GitHub Desktop.
Save Gsantomaggio/52474bda544504ee74599484652776df to your computer and use it in GitHub Desktop.
let stream = TcpStream::connect((broker.host.as_str(), broker.port)).await?;
let mut tls_builder: tokio_native_tls::native_tls::TlsConnectorBuilder = tokio_native_tls::native_tls::TlsConnector::builder();
let cert_bytes = include_bytes!("result/ca_certificate.pem");
let cert = Certificate::from_pem(cert_bytes).unwrap();
let s = tls_builder.add_root_certificate(cert)
.danger_accept_invalid_hostnames(false)
// .danger_accept_invalid_certs(true)
.min_protocol_version(Some(tokio_native_tls::native_tls::Protocol::Tlsv12));
let conn = tokio_native_tls::TlsConnector::from(s.build()?).connect(broker.host.as_str(), stream).await?;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment