commit 88bab6d5b92ee0abe1a80886d5e6b1a50d5e2900 Author: Reyk Floeter Date: Fri Nov 29 21:38:59 2019 +0000 Initial import diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..d0934e9 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "yodle" +version = "0.1.0" +authors = ["Reyk Floeter "] +edition = "2018" + +[dependencies] +derive_more = "0.99" +dirs = "2.0" +env_logger = "0.7" +futures = "0.3" +getopts = "0.2" +log = "0.4" +tokio = { version = "0.2", features = ["full"] } +tokio-libtls = "1.1.0-alpha.2" diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..32a9786 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1 @@ +edition = "2018" diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..2cc10b0 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,60 @@ +// Copyright (c) 2019 Reyk Floeter +// +// Permission to use, copy, modify, and distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +#[macro_use] +extern crate log; + +mod cert; + +use cert::ServerKeyPair; +use log::LevelFilter; +use std::io; +use tokio::io::{AsyncReadExt, AsyncWriteExt}; +use tokio_libtls::prelude::*; + +async fn async_https_connect(servername: String) -> io::Result<()> { + let request = format!( + "GET / HTTP/1.1\r\n\ + Host: {}\r\n\ + Connection: close\r\n\r\n", + servername + ); + + let config = TlsConfigBuilder::new().build()?; + let mut tls = AsyncTls::connect(&(servername + ":443"), &config, None).await?; + tls.write_all(request.as_bytes()).await?; + + let mut buf = vec![0u8; 1024]; + tls.read_exact(&mut buf).await?; + + let ok = b"HTTP/1.1 200 OK\r\n"; + assert_eq!(&buf[..ok.len()], ok); + + Ok(()) +} + +#[tokio::main] +async fn main() { + env_logger::builder() + .filter_level(LevelFilter::Debug) + .init(); + + async_https_connect("www.example.com".to_owned()) + .await + .unwrap(); + + let server_key = ServerKeyPair::new(); + + info!("{:?}", server_key); +}