diff --git a/security/rustls/Cargo.toml b/security/rustls/Cargo.toml index d1b86d49..265308c7 100644 --- a/security/rustls/Cargo.toml +++ b/security/rustls/Cargo.toml @@ -2,14 +2,15 @@ name = "rustls-example" version = "1.0.0" authors = ["Nikolay Kim "] -edition = "2018" +edition = "2021" [[bin]] name = "rustls-server" path = "src/main.rs" [dependencies] -env_logger = "0.8" -rustls = "0.18" -actix-web = { version = "3", features = ["rustls"] } -actix-files = "0.3" +env_logger = "0.9" +rustls = "0.20.2" +rustls-pemfile = "0.2.1" +actix-web = { version = "4.0.0-beta.21", features = ["rustls"] } +actix-files = "0.6.0-beta.15" diff --git a/security/rustls/src/main.rs b/security/rustls/src/main.rs index e656ec46..6e14c9af 100644 --- a/security/rustls/src/main.rs +++ b/security/rustls/src/main.rs @@ -3,8 +3,8 @@ use std::io::BufReader; use actix_files::Files; use actix_web::{middleware, web, App, HttpRequest, HttpResponse, HttpServer}; -use rustls::internal::pemfile::{certs, pkcs8_private_keys}; -use rustls::{NoClientAuth, ServerConfig}; +use rustls::{Certificate, PrivateKey, ServerConfig}; +use rustls_pemfile::{certs, pkcs8_private_keys}; /// simple handle async fn index(req: HttpRequest) -> HttpResponse { @@ -22,16 +22,26 @@ async fn main() -> std::io::Result<()> { env_logger::init(); // load ssl keys - let mut config = ServerConfig::new(NoClientAuth::new()); + let config = ServerConfig::builder() + .with_safe_defaults() + .with_no_client_auth(); let cert_file = &mut BufReader::new(File::open("cert.pem").unwrap()); let key_file = &mut BufReader::new(File::open("key.pem").unwrap()); - let cert_chain = certs(cert_file).unwrap(); - let mut keys = pkcs8_private_keys(key_file).unwrap(); + let cert_chain = certs(cert_file) + .unwrap() + .into_iter() + .map(Certificate) + .collect(); + let mut keys: Vec = pkcs8_private_keys(key_file) + .unwrap() + .into_iter() + .map(PrivateKey) + .collect(); if keys.is_empty() { eprintln!("Could not locate PKCS 8 private keys."); std::process::exit(1); } - config.set_single_cert(cert_chain, keys.remove(0)).unwrap(); + let config = config.with_single_cert(cert_chain, keys.remove(0)).unwrap(); println!("Starting https server: 127.0.0.1:8443"); HttpServer::new(|| { @@ -43,7 +53,7 @@ async fn main() -> std::io::Result<()> { // with path parameters .service(web::resource("/").route(web::get().to(|| { HttpResponse::Found() - .header("LOCATION", "/index.html") + .append_header(("LOCATION", "/index.html")) .finish() }))) .service(Files::new("/static", "static"))