tokio-rs / tls

A collection of Tokio based TLS libraries.
https://tokio.rs
MIT License
253 stars 86 forks source link

TlsAcceptor not responding #149

Closed Unbreak4ble closed 1 year ago

Unbreak4ble commented 1 year ago

i have the following primary code

fn setup_cert(host: String) -> Result<Identity, ()>{
    let Some(certificate) = cert::setup_tls_cert(host.clone()) else { return Err(()); };
    let Some(pkey) = cert::get_pkcs8_key() else { return Err(()); };
    let Ok(identy) = Identity::from_pkcs8(&certificate.as_bytes(), &pkey.as_bytes()) else { return Err(()); };
    Ok(identy)
}

pub async fn handleTlsConnection(client: TcpStream, host: String)/* -> Result<(), std::io::Error>*/ {
    debug::new_connection(true, client.try_clone());
    let Ok(client) = TokioTcpStream::from_std(client) else { return; };
    let Ok(mut stream) = new_tls_connection(host.clone(), "443".to_string()).await else { return; };
    let Ok(tls_cert) = setup_cert(host.clone()) else { return; };
    let Ok(tls_cert) = native_tls::TlsAcceptor::builder(tls_cert).build() else { return; };
    let acceptor = TlsAcceptor::from(tls_cert);
    println!("waiting");
    let Ok(mut client) = acceptor.accept(client).await else { 
        debug::PROXY_DEBUG!(0b00001000, "error: tls handshake");
        return;
    };
    println!("connection established for {}", host);
    handle_connection(client, stream);
}

everything working fine until the "waiting" string is printed, the "connection established for ..." string was not printed, not even the "error: tls handshake" was printed. I don't know whats is causing this problem. I already checked the PEM certificate and the pkcs8 private key, so i think that the problem isn't the certificate.

Unbreak4ble commented 1 year ago

fixed.