Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When used with a specified request the body is not decrypted #216

Closed
DataFrogman opened this issue Aug 2, 2023 · 2 comments
Closed

When used with a specified request the body is not decrypted #216

DataFrogman opened this issue Aug 2, 2023 · 2 comments

Comments

@DataFrogman
Copy link

Using the following code, the output from the printed body is ciphertext, not the decrypted plaintext of the accessed site. Is there a specific way that I am missing to specify a Request for hyper and still receive the decrypted contents?

let tls = rustls::ClientConfig::builder()
        .with_safe_defaults()
        .with_native_roots()
        .with_no_client_auth();

    let https = hyper_rustls::HttpsConnectorBuilder::new()
        .with_tls_config(tls)
        .https_or_http()
        .enable_http1()
        .build();

    let url = (String::from("https://") + &temp).parse::<hyper::Uri>()?;
    let request = Request::get(url)
         .method(Method::GET)
         .header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8")
         .header("Accept-Encoding", "gzip, deflate, br")
         .header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/114.0")
         .body(Body::empty())?;
    
    let client: Client<_, hyper::Body> = Client::builder().build(https);

    let resp = match tokio::time::timeout(tokio::time::Duration::from_secs(10), client
    .request(request)).await {
        Ok(x) => {
            match x {
                Ok(y) => y,
                Err(err) => {
                    println!("{domain}: {err:?}");
                    return Err(err.into())
                }
            }
        }
        Err(err) => {
            println!("{domain}: {err:?}");
            return Err(err.into())
        }
    };

    let body = resp.into_body();
    let body = hyper::body::to_bytes(body).await;

    let bytes = match body {
        Ok(x) => x,
        Err(err) => {
            println!("{domain}: {err:?}");
            return Err(err.into())
        }
    };
    let text = String::from_utf8_lossy(&bytes);
    println!("{text:?}");
    ```
@ctz
Copy link
Member

ctz commented Aug 2, 2023

This is a complete guess, but I think it is compression and not encryption.

This line says you are happy to receive and decompress gzip, deflate or brotli bodies:

     .header("Accept-Encoding", "gzip, deflate, br")

But there is nothing in the remainder of your program that looks at the content-encoding header of the response and decompresses the body if necessary. hyper doesn't do this for you. However, reqwest does (AIUI) include transparent gzip decompression by default.

@DataFrogman
Copy link
Author

DataFrogman commented Aug 2, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants