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

Certificate Issue in Windows and with Proxy #185

Open
ark- opened this issue Aug 16, 2017 · 8 comments
Open

Certificate Issue in Windows and with Proxy #185

ark- opened this issue Aug 16, 2017 · 8 comments
Labels
B-upstream Blocked: upstream. Depends on a dependency to make a change first.

Comments

@ark-
Copy link

ark- commented Aug 16, 2017

I use Rust in an corporate environment in Windows.

I sucessfully got cargo to work with the following settings in the .cargo/config file

proxy = "http://<ip>:3128"
check-revoke = false
cainfo = "c:/cert.pem"

Where cert.pem was obtained from my system.

Now, using reqwest I can successfully access HTTP urls using the proxy, however when accessing HTTPS urls I get the following error:

Error { kind: Io(Error { repr: Custom(Custom { kind: Other, error: Error { repr: Os { code: -2146762487, message: "A certificate chain processed, but terminated in a root certificate which is not trusted by the trust provider." } } }) }), url: Some("https://<website>.com") }

My code looks like so:

fn run_proxy() -> Result<()> {
    let proxy = format!("http://<ip>:3128");

    let mut buf = Vec::new();
    File::open("C:/cert.der")?
        .read_to_end(&mut buf)?;
    let cert = reqwest::Certificate::from_der(&buf)?;

    let url = "https://<website>.com";
    let res = reqwest::Client::builder()
        .unwrap()
        .add_root_certificate(cert)
        .unwrap()
        .proxy(reqwest::Proxy::all(&proxy).unwrap())
        .build()
        .unwrap()
        .get(url)
        .unwrap()
        .send()
        .unwrap();

    println!("{:?}", res.headers());

    let document = Document::from_read(res)?;
    println!("{:?}", document);

    Ok(())
}

Where cert.der is the DER encoded cert.pem seen in the above cargo config.

Am I using the library wrong, or is there a bug in reqwest or its dependencies? Happy to provide more information as required.

@seanmonstar
Copy link
Owner

The certificate is to be able to speak with the proxy, or with the destination website?

@ark-
Copy link
Author

ark- commented Aug 17, 2017

I believe it is the certificate for the proxy, the destination website is just reddit in this case

@seanmonstar
Copy link
Owner

Hm, and if you don't set the cert, what happens? You cannot connect to the proxy? Can you make requests without the proxy and cert?

@ark-
Copy link
Author

ark- commented Aug 18, 2017

HTTPS Tests

With proxy & without cert

Error { repr: Os { code: -2146762487, message: "A certificate chain processed, but terminated in a root certificate which is not trusted by the trust provider." } } }) }), url: Some("https://reddit.com/r/rust") }

Without proxy & with cert

Runs for a long time, finally giving
Error { repr: Os { code: 10060, message: "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond." } }), url: Some("https://reddit.com/r/rust") }

Without proxy or cert

Runs for a long time, finally giving
Error { repr: Os { code: 10060, message: "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond." } }), url: Some("https://reddit.com/r/rust") }

@seanmonstar
Copy link
Owner

Ah, so it looks like without the proxy, you're hitting a firewall or something that prevents the connection establishing with reddit. With the proxy and no certificate, are you able to connect to HTTP sites (not HTTPS)? I assume that without the certificate, the connection the proxy cannot be trusted, and so no other requests can work.

I'd love to dig further into this, it seems related to the use of schannel on Windows. But to unblock you, there is something you can do if you don't care to dig as well. Since reqwest uses schannel on Windows, that means it will make use of the certificate store of the operating system. See here for how to add a certificate to the OS trust store.

@seanmonstar
Copy link
Owner

Oh also, knowing what Windows version you're using would be very useful.

@seanmonstar seanmonstar added the B-upstream Blocked: upstream. Depends on a dependency to make a change first. label Aug 19, 2017
@ark-
Copy link
Author

ark- commented Aug 20, 2017

Thanks for the advice! I can try your suggestions on Monday when back in the office. I'm using Windows 7. by the way.

@ark-
Copy link
Author

ark- commented Aug 21, 2017

HTTP Tests

With proxy & with certificate: 🆗

With proxy & without certificate: 🆗

Without proxy & with cert:

Runs for a long time, finally giving
Error { repr: Os { code: 10060, message: "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond." } }), url: Some("http://www.netinstructions.com/how-to-monitor-your-linux-machine/") }

Without proxy or cert

Runs for a long time, finally giving
Error { repr: Os { code: 10060, message: "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond." } }), url: Some("http://www.netinstructions.com/how-to-monitor-your-linux-machine/") }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B-upstream Blocked: upstream. Depends on a dependency to make a change first.
Projects
None yet
Development

No branches or pull requests

2 participants