Initial import
This commit is contained in:
commit
88bab6d5b9
3 changed files with 76 additions and 0 deletions
15
Cargo.toml
Normal file
15
Cargo.toml
Normal file
|
@ -0,0 +1,15 @@
|
|||
[package]
|
||||
name = "yodle"
|
||||
version = "0.1.0"
|
||||
authors = ["Reyk Floeter <contact@reykfloeter.com>"]
|
||||
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"
|
1
rustfmt.toml
Normal file
1
rustfmt.toml
Normal file
|
@ -0,0 +1 @@
|
|||
edition = "2018"
|
60
src/main.rs
Normal file
60
src/main.rs
Normal file
|
@ -0,0 +1,60 @@
|
|||
// Copyright (c) 2019 Reyk Floeter <contact@reykfloeter.com>
|
||||
//
|
||||
// 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);
|
||||
}
|
Loading…
Reference in a new issue