Comments (5)
There isnt'! Would you be interested in providing one?
from hyper-rustls.
Hey, I'm currently working on this. The only thing blocking me is going from having a use mio::net::TcpStream
and rustls::ClientConnection
to creating an HttpsConnector
.
from hyper-rustls.
For anyone who is interested, I think using tokio-rustls in conjunction with hyper is the way to go.
Here's a quick program to get you started:
use std::{
net::{Ipv4Addr, SocketAddr, SocketAddrV4},
sync::Arc,
time::Instant,
};
use http_body_util::{BodyExt, Empty};
use hyper::{body::Bytes, Request};
use tokio::{
io::{self, AsyncWriteExt},
net::TcpStream,
};
use tokio_rustls::rustls::{ClientConfig, OwnedTrustAnchor, RootCertStore, ServerName};
use tokio_rustls::TlsConnector;
async fn async_request(ip: Ipv4Addr, domain: &str, url: &str) {
let mut root_cert_store = RootCertStore::empty();
root_cert_store.add_server_trust_anchors(webpki_roots::TLS_SERVER_ROOTS.0.iter().map(|ta| {
OwnedTrustAnchor::from_subject_spki_name_constraints(
ta.subject,
ta.spki,
ta.name_constraints,
)
}));
let config = ClientConfig::builder()
.with_safe_defaults()
.with_root_certificates(root_cert_store)
.with_no_client_auth();
let connector = TlsConnector::from(Arc::new(config));
let dnsname = ServerName::try_from(domain).unwrap();
let addr = SocketAddr::V4(SocketAddrV4::new(ip, 443));
let stream = TcpStream::connect(&addr).await.expect("Could not connect");
let mut stream = connector
.connect(dnsname, stream)
.await
.expect("Could not connect connector?");
let (mut request_sender, connection) = hyper::client::conn::http1::handshake(stream)
.await
.expect("Could not perform http1 handshake");
// spawn a task to poll the connection and drive the HTTP state
tokio::spawn(async move {
if let Err(e) = connection.await {
eprintln!("Error in connection: {}", e);
}
});
let parsed_url = url.parse::<hyper::Uri>().expect("Could not parse url");
let request = Request::builder()
// We need to manually add the host header because SendRequest does not
.header("Host", "example.com")
.method("GET")
.uri(parsed_url)
.body(Empty::<Bytes>::new())
.expect("Could not build HTTP request");
let mut response = request_sender
.send_request(request)
.await
.expect("Could not send request");
while let Some(next) = response.frame().await {
let frame = next.expect("Could not unwrap next frame");
if let Some(chunk) = frame.data_ref() {
io::stdout()
.write_all(&chunk)
.await
.expect("Could not write to stdout");
}
}
}
All you need to do is call async_request
like so:
async_request(
Ipv4Addr::new(93, 184, 216, 34),
"example.com.",
"https://example.com/",
)
.await;
from hyper-rustls.
I don't see how that example is using trust-dns-resolver for DNS resolution.
from hyper-rustls.
I didn't actually integrate it with the Https resolver. This thread just comes up on google when you look for ways to use rustls without performing resolutions, so I provided an example I landed on. This example takes in an ip address so that no resolutions are necessary. I haven't actually checked if it does not perform resolutions or not.
To complete the example you could add the trustDNS resolver to provide the IP.
Not a full example, just leaving it in case people come upon the same path as me.
from hyper-rustls.
Related Issues (20)
- More elaborate custom server name HOT 1
- Cannot access peer certificates with example's TlsStream HOT 7
- `HttpsConnectorBuilder::enable_all_versions` doesn't enable ALPN for http/1.1 HOT 1
- Release TLSAcceptor HOT 2
- example of client with mutual tls HOT 3
- When used with a specified request the body is not decrypted HOT 2
- Getting ip address of connection HOT 1
- Creating an HTTPS connection using `HttpsConnectorBuilder` does not allow you to obtain the website's URL. HOT 1
- Hyper v1 compatibility HOT 12
- Release with rustls 0.22 support? HOT 5
- Release 0.25.0 without hyper 1 support? HOT 1
- Prepare v0.25 release, update to Rustls v0.22 HOT 5
- Prepare v0.26 release, update to Hyper 1.0 HOT 8
- v0.26 server example error: failed to serve connection: error shutting down connection HOT 2
- Add support for providing HttpConnector HOT 3
- Rust minimum version should be updated HOT 4
- 0.23.2 of rusttls HOT 3
- Expose feature flag to enable FIPS compliant build of AWS-LC. HOT 1
- Latest version (0.27.1) fails to build for `docs.rs` HOT 2
- wrong feature name for webpki? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hyper-rustls.