pub fn new_ssl_from_stream<A: ToSocketAddrsDomain>(
        socket_addr: A,
        validate_domain: bool,
        tcp_stream: TcpStream,
    ) -> Result<Self, Error> {
        let builder = ClientConfig::builder().with_safe_defaults();

        let config = if validate_domain {
            socket_addr.domain().ok_or(Error::MissingDomain)?;

            let mut store = RootCertStore::empty();
            store.add_server_trust_anchors(webpki_roots::TLS_SERVER_ROOTS.0.into_iter().map(|t| {
                OwnedTrustAnchor::from_subject_spki_name_constraints(
                    t.subject,
                    t.spki,
                    t.name_constraints,
                )
            }));

            // TODO: cert pinning
            builder.with_root_certificates(store).with_no_client_auth()
        } else {
            builder
                .with_custom_certificate_verifier(std::sync::Arc::new(
                    danger::NoCertificateVerification {},
                ))
                .with_no_client_auth()
        };

        let domain = socket_addr.domain().unwrap_or("NONE").to_string();
        let session = ClientConnection::new(
            std::sync::Arc::new(config),
            ServerName::try_from(domain.as_str())
                .map_err(|_| Error::InvalidDNSNameError(domain.clone()))?,
        )
        .map_err(Error::CouldNotCreateConnection)?;
        let stream = StreamOwned::new(session, tcp_stream);

        Ok(stream.into())
    }
/// Create a new SSL client using an existing TcpStream
Create a new SSL client using an existing TcpStream
Create a new SSL client using an existing TcpStream
pub fn new_ssl_from_stream<A: ToSocketAddrsDomain>(
        socket_addr: A,
        validate_domain: bool,
        tcp_stream: TcpStream,
    ) -> Result<Self, Error> {
        let builder = ClientConfig::builder().with_safe_defaults();
        let config = if validate_domain {
            socket_addr.domain().ok_or(Error::MissingDomain)?;
            let mut store = RootCertStore::empty();
            store.add_server_trust_anchors(webpki_roots::TLS_SERVER_ROOTS.0.into_iter().map(|t| {
                OwnedTrustAnchor::from_subject_spki_name_constraints(
                    t.subject,
                    t.spki,
                    t.name_constraints,
                )
            }));
            // TODO: cert pinning
            builder.with_root_certificates(store).with_no_client_auth()
        } else {
            builder
                .with_custom_certificate_verifier(std::sync::Arc::new(
                    danger::NoCertificateVerification {},
                ))
                .with_no_client_auth()
        };
        let domain = socket_addr.domain().unwrap_or("NONE").to_string();
        let session = ClientConnection::new(
            std::sync::Arc::new(config),
            ServerName::try_from(domain.as_str())
                .map_err(|_| Error::InvalidDNSNameError(domain.clone()))?,
        )
        .map_err(Error::CouldNotCreateConnection)?;
        let stream = StreamOwned::new(session, tcp_stream);
        Ok(stream.into())
    }
pub fn new_ssl_from_stream < A : ToSocketAddrsDomain > ( socket_addr : A , validate_domain : bool , tcp_stream : TcpStream , ) -> Result < Self , Error > { let builder = ClientConfig :: builder ( ) . with_safe_defaults ( ) ; let config = if validate_domain { socket_addr . domain ( ) . ok_or ( Error :: MissingDomain ) ? ; let mut store = RootCertStore :: empty ( ) ; store . add_server_trust_anchors ( webpki_roots :: TLS_SERVER_ROOTS . 0 . into_iter ( ) . map ( | t | { OwnedTrustAnchor :: from_subject_spki_name_constraints ( t . subject , t . spki , t . name_constraints , ) } ) ) ; // TODO: cert pinning builder . with_root_certificates ( store ) . with_no_client_auth ( ) } else { builder . with_custom_certificate_verifier ( std :: sync :: Arc :: new ( danger :: NoCertificateVerification { } , ) ) . with_no_client_auth ( ) } ; let domain = socket_addr . domain ( ) . unwrap_or ( " " ) . to_string ( ) ; let session = ClientConnection :: new ( std :: sync :: Arc :: new ( config ) , ServerName :: try_from ( domain . as_str ( ) ) . map_err ( | _ | Error :: InvalidDNSNameError ( domain . clone ( ) ) ) ? , ) . map_err ( Error :: CouldNotCreateConnection ) ? ; let stream = StreamOwned :: new ( session , tcp_stream ) ; Ok ( stream . into ( ) ) }
Create a new SSL client using an existing TcpStream
Create a new SSL client using an existing TcpStream
socket_addr
A
validate_domain
bool
tcp_stream
TcpStream
socket_addr
A
validate_domain
bool
tcp_stream
TcpStream