2020-12-01 22:11:28 +00:00
|
|
|
use anyhow::Result;
|
2020-11-14 02:56:50 +00:00
|
|
|
use log::LevelFilter;
|
2020-11-13 19:20:59 +00:00
|
|
|
|
2020-12-01 22:11:28 +00:00
|
|
|
use std::fmt::Write;
|
|
|
|
|
|
|
|
use kochab::{Request, Response, Server};
|
2020-11-13 19:20:59 +00:00
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() -> Result<()> {
|
2020-11-14 02:56:50 +00:00
|
|
|
env_logger::builder()
|
2020-11-25 05:42:09 +00:00
|
|
|
.filter_module("kochab", LevelFilter::Debug)
|
2020-11-14 02:56:50 +00:00
|
|
|
.init();
|
|
|
|
|
2020-12-01 07:31:08 +00:00
|
|
|
Server::new()
|
2020-12-01 22:11:28 +00:00
|
|
|
.add_route("/", handle_request)
|
2020-12-14 00:53:18 +00:00
|
|
|
.serve_ip("localhost:1965")
|
2020-11-13 19:20:59 +00:00
|
|
|
.await
|
|
|
|
}
|
|
|
|
|
2020-12-01 22:11:28 +00:00
|
|
|
async fn handle_request(request: Request) -> Result<Response> {
|
|
|
|
if let Some(fingerprint) = request.certificate() {
|
|
|
|
let mut message = String::from("You connected with a certificate with a fingerprint of:\n");
|
|
|
|
|
|
|
|
for byte in fingerprint {
|
|
|
|
write!(&mut message, "{:x}", byte).unwrap();
|
2020-11-13 19:20:59 +00:00
|
|
|
}
|
2020-12-01 22:11:28 +00:00
|
|
|
|
|
|
|
Ok(Response::success_plain(message))
|
2020-11-20 04:39:07 +00:00
|
|
|
} else {
|
|
|
|
// The user didn't provide a certificate
|
2020-12-01 22:11:28 +00:00
|
|
|
Ok(Response::client_certificate_required("You didn't provide a client certificate"))
|
2020-11-20 04:39:07 +00:00
|
|
|
}
|
2020-11-13 19:20:59 +00:00
|
|
|
}
|