diff --git a/docs/http2.md b/docs/http2.md index 2ae4fbc..f0c7142 100644 --- a/docs/http2.md +++ b/docs/http2.md @@ -10,16 +10,11 @@ import RenderCodeBlock from '@theme/CodeBlock'; import CodeBlock from '@site/src -When either of the `rustls` or `openssl` features are enabled, `HttpServer` provides the [bind_rustls][bindrustls] method and [bind_openssl][bindopenssl] methods, respectively. +When either of the `rustls` or `openssl` features are enabled, `HttpServer` provides the [`bind_rustls()`][bindrustls] method and [`bind_openssl()`][bindopenssl] methods, respectively. - -{`[dependencies] -actix-web = { version = "${actixWebMajorVersion}", features = ["openssl"] } -openssl = { version = "0.10", features = ["v110"] } -`} - + @@ -29,7 +24,7 @@ Upgrades to HTTP/2 described in [RFC 7540 ยง3.2][rfcsection32] are not supported [rfcsection32]: https://httpwg.org/specs/rfc7540.html#rfc.section.3.2 [rfcsection34]: https://httpwg.org/specs/rfc7540.html#rfc.section.3.4 -[bindrustls]: https://docs.rs/actix-web/4/actix_web/struct.HttpServer.html#method.bind_rustls +[bindrustls]: https://docs.rs/actix-web/4/actix_web/struct.HttpServer.html#method.bind_rustls_0_22 [bindopenssl]: https://docs.rs/actix-web/4/actix_web/struct.HttpServer.html#method.bind_openssl [tlsalpn]: https://tools.ietf.org/html/rfc7301 [examples]: https://github.com/actix/examples/tree/master/https-tls diff --git a/examples/http2/Cargo.toml b/examples/http2/Cargo.toml index ea80535..e959518 100644 --- a/examples/http2/Cargo.toml +++ b/examples/http2/Cargo.toml @@ -4,6 +4,9 @@ version = "1.0.0" publish = false edition.workspace = true +# [dependencies] -actix-web = { version = "4", features = ["openssl"] } -openssl = { version = "0.10", features = ["v110"] } +actix-web = { version = "4", features = ["rustls-0_22"] } +rustls = "0.22" +rustls-pemfile = "2" +# diff --git a/examples/http2/src/main.rs b/examples/http2/src/main.rs index 82003e6..5e866fd 100644 --- a/examples/http2/src/main.rs +++ b/examples/http2/src/main.rs @@ -1,24 +1,36 @@ +use std::{fs::File, io::BufReader}; + //
use actix_web::{web, App, HttpRequest, HttpServer, Responder}; -use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod}; async fn index(_req: HttpRequest) -> impl Responder { - "Hello." + "Hello TLS World!" } #[actix_web::main] async fn main() -> std::io::Result<()> { - // load TLS keys + let mut certs_file = BufReader::new(File::open("cert.pem").unwrap()); + let mut key_file = BufReader::new(File::open("key.pem").unwrap()); + + // load TLS certs and key // to create a self-signed temporary cert for testing: // `openssl req -x509 -newkey rsa:4096 -nodes -keyout key.pem -out cert.pem -days 365 -subj '/CN=localhost'` - let mut builder = SslAcceptor::mozilla_intermediate(SslMethod::tls()).unwrap(); - builder - .set_private_key_file("key.pem", SslFiletype::PEM) + let tls_certs = rustls_pemfile::certs(&mut certs_file) + .collect::, _>>() + .unwrap(); + let tls_key = rustls_pemfile::pkcs8_private_keys(&mut key_file) + .next() + .unwrap() + .unwrap(); + + // set up TLS config options + let tls_config = rustls::ServerConfig::builder() + .with_no_client_auth() + .with_single_cert(tls_certs, rustls::pki_types::PrivateKeyDer::Pkcs8(tls_key)) .unwrap(); - builder.set_certificate_chain_file("cert.pem").unwrap(); HttpServer::new(|| App::new().route("/", web::get().to(index))) - .bind_openssl("127.0.0.1:8080", builder)? + .bind_rustls_0_22(("127.0.0.1", 8443), tls_config)? .run() .await } diff --git a/vars.js b/vars.js index 586aed4..a90d795 100644 --- a/vars.js +++ b/vars.js @@ -1,5 +1,5 @@ module.exports = { - rustVersion: "1.59", + rustVersion: "1.72", actixWebMajorVersion: "4", tokioMajorVersion: "1", };