feat: add actix with rustls
This commit is contained in:
1865
actix_rustls/Cargo.lock
generated
Normal file
1865
actix_rustls/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
12
actix_rustls/Cargo.toml
Normal file
12
actix_rustls/Cargo.toml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
[package]
|
||||||
|
name = "actix_rustls"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
rustls = "0.18"
|
||||||
|
actix-web = { version = "3.1", features = ["rustls"] }
|
||||||
|
|
||||||
3
actix_rustls/README.md
Normal file
3
actix_rustls/README.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
https://www.mdeditor.tw/pl/pVR6
|
||||||
|
|
||||||
|
|
||||||
36
actix_rustls/src/main.rs
Normal file
36
actix_rustls/src/main.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
use rustls::ClientHello;
|
||||||
|
use rustls::NoClientAuth;
|
||||||
|
use rustls::ServerConfig;
|
||||||
|
use rustls::ResolvesServerCert;
|
||||||
|
use rustls::sign::CertifiedKey;
|
||||||
|
use actix_web::App;
|
||||||
|
use actix_web::HttpServer;
|
||||||
|
use actix_web::get;
|
||||||
|
use actix_web::Responder;
|
||||||
|
|
||||||
|
struct CustomResolvesServerCert;
|
||||||
|
impl ResolvesServerCert for CustomResolvesServerCert {
|
||||||
|
fn resolve(&self, client_hello: ClientHello) -> Option<CertifiedKey> {
|
||||||
|
println!("Request server name: {:?}", client_hello.server_name());
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[get("/")]
|
||||||
|
async fn index() -> impl Responder {
|
||||||
|
format!("Hello world!")
|
||||||
|
}
|
||||||
|
|
||||||
|
#[actix_web::main]
|
||||||
|
async fn main() -> std::io::Result<()> {
|
||||||
|
let mut config = ServerConfig::new(NoClientAuth::new());
|
||||||
|
config.cert_resolver = Arc::new(CustomResolvesServerCert);
|
||||||
|
|
||||||
|
let listen = "127.0.0.1:8443";
|
||||||
|
println!("Listen at: {}", listen);
|
||||||
|
HttpServer::new(|| App::new().service(index))
|
||||||
|
.bind_rustls(listen, config)?
|
||||||
|
.run()
|
||||||
|
.await
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user