I need to implement a actix_web
TLS 1.0 webserver. I'm currently using rustls
and just discovered it doesn't support this.
My code is as follows:
fn load_rustls_config() -> rustls::ServerConfig {
// init server config builder with safe defaults
let config = ServerConfig::builder().with_safe_defaults().with_no_client_auth();
// load TLS key/cert files
let cert_file = &mut BufReader::new(File::open("./certs/root.crt").expect("Certificate not found!"));
let key_file = &mut BufReader::new(File::open("./certs/root.key").expect("Key not found!"));
// convert files to key/cert objects
let cert_chain = certs(cert_file).unwrap().into_iter().map(Certificate).collect();
let mut keys: Vec<PrivateKey> = pkcs8_private_keys(key_file).unwrap().into_iter().map(PrivateKey).collect();
// exit if no keys could be parsed
if keys.is_empty() {
eprintln!("Could not locate PKCS 8 private keys.");
std::process::exit(1);
}
config.with_single_cert(cert_chain, keys.remove(0)).unwrap()
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
let config = load_rustls_config();
info!("Certificates loaded.");
println!("Started!");
HttpServer::new(|| {
App::new()
.service(test)
.route("{path:.*}", web::get().to(index))
})
.bind("0.0.0.0:80")?
.bind("0.0.0.0:5107")?
.bind_rustls("0.0.0.0:443", config)?
.run()
.await
}
I don't know how to go about converting this or using a different library. Is it even possible to do this? Just thought I'd ask to make sure I won't go down a rabbit hole that leads nowhere.