Closed FarooqKhan closed 6 years ago
You can try this.
It's been months, @FarooqKhan should probably close this.
Solved it eventually, since then I have changed my project so I am unable to update here the working code. But this can be closed
I'm trying to trust a specific self-signed certificate using restson/hyper-tls/native-tls but cannot wrap my head around this...
The site http://www.jalg.net/2017/09/hyper-client-and-self-signed-certs is now offline so the information that was there disappeared (even wayback machine doesn't have a snapshot).
I couldn't find any docs or example doing so... How can this be achieved?
Thanks!!
A quick google search brought this up: http://algermissen.io/2017/09/hyper-client-and-self-signed-certs
Thanks for the updated link! My google-foo couldn't find it... :(
I'm not sure the description there is sufficient though.
The piece of code on that site is:
let mut f = File::open("/...my cert file").unwrap();
let mut buffer = vec![];
f.read_to_end(&mut buffer).unwrap();
let cert = Certificate::from_der(buffer.as_slice()).unwrap();
let mut http = HttpConnector::new(4, handle);
http.enforce_http(false);
let mut tls = TlsConnector::builder().unwrap();
tls.add_root_certificate(cert);
let mut tls = tls.build().unwrap();
let ct = HttpsConnector::from((http, tls));
let client = Client::configure().connector(ct).build(handle);
I think TlsConnector
comes from native-tls
(https://docs.rs/native-tls/0.2.2/native_tls/struct.TlsConnector.html) which hyper-tls
does not expose. So a project depending on hyper-tls
only cannot use this if I understand correctly.
Thanks. I've described in https://github.com/spietika/restson-rust/pull/20 how I've made my client accept the self-signed certificate.
The main issue was that I was missing the tls_connector_builder.danger_accept_invalid_hostnames(true)
which was required for that specific server.
Do you have a working example of using a Self Signed Certificate with hyper-tls
I have tried several ways to do it but not succeeded.
Thanks