1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-01-18 05:41:50 +01:00

add rustls support to HttpServer

This commit is contained in:
Nikolay Kim 2019-03-29 16:28:19 -07:00
parent e9bbde6832
commit c126713f40
9 changed files with 234 additions and 226 deletions

View File

@ -35,7 +35,7 @@ members = [
] ]
[package.metadata.docs.rs] [package.metadata.docs.rs]
features = ["ssl", "tls", "brotli", "flate2-zlib", "cookies", "client"] features = ["ssl", "tls", "brotli", "flate2-zlib", "cookies", "client", "rust-tls"]
[features] [features]
default = ["brotli", "flate2-zlib", "cookies", "client"] default = ["brotli", "flate2-zlib", "cookies", "client"]
@ -62,7 +62,7 @@ tls = ["native-tls", "actix-server/ssl"]
ssl = ["openssl", "actix-server/ssl", "awc/ssl"] ssl = ["openssl", "actix-server/ssl", "awc/ssl"]
# rustls # rustls
# rust-tls = ["rustls", "actix-server/rustls"] rust-tls = ["rustls", "actix-server/rust-tls"]
[dependencies] [dependencies]
actix-codec = "0.1.1" actix-codec = "0.1.1"
@ -100,7 +100,7 @@ cookie = { version="0.11", features=["secure", "percent-encode"], optional = tru
# ssl support # ssl support
native-tls = { version="0.2", optional = true } native-tls = { version="0.2", optional = true }
openssl = { version="0.10", optional = true } openssl = { version="0.10", optional = true }
# rustls = { version = "^0.15", optional = true } rustls = { version = "^0.15", optional = true }
[dev-dependencies] [dev-dependencies]
actix-http = { path = "actix-http", features=["ssl", "brotli", "flate2-zlib"] } actix-http = { path = "actix-http", features=["ssl", "brotli", "flate2-zlib"] }
@ -112,6 +112,9 @@ tokio-timer = "0.2.8"
brotli2 = "0.3.2" brotli2 = "0.3.2"
flate2 = "1.0.2" flate2 = "1.0.2"
[replace]
"cookie:0.11.0" = { git = 'https://github.com/alexcrichton/cookie-rs.git' }
[profile.release] [profile.release]
lto = true lto = true
opt-level = 3 opt-level = 3

View File

@ -10,7 +10,7 @@ Actix web is a simple, pragmatic and extremely fast web framework for Rust.
* Configurable [request routing](https://actix.rs/docs/url-dispatch/) * Configurable [request routing](https://actix.rs/docs/url-dispatch/)
* Multipart streams * Multipart streams
* Static assets * Static assets
* SSL support with OpenSSL or native-tls * SSL support with OpenSSL or Rustls
* Middlewares ([Logger, Session, CORS, CSRF, etc](https://actix.rs/docs/middleware/)) * Middlewares ([Logger, Session, CORS, CSRF, etc](https://actix.rs/docs/middleware/))
* Includes an asynchronous [HTTP client](https://actix.rs/actix-web/actix_web/client/index.html) * Includes an asynchronous [HTTP client](https://actix.rs/actix-web/actix_web/client/index.html)
* Supports [Actix actor framework](https://github.com/actix/actix) * Supports [Actix actor framework](https://github.com/actix/actix)

View File

@ -1,16 +1,20 @@
-----BEGIN CERTIFICATE----- -----BEGIN CERTIFICATE-----
MIICljCCAX4CCQDFdWu66640QjANBgkqhkiG9w0BAQsFADANMQswCQYDVQQGEwJ1 MIIDPjCCAiYCCQCmkoCBehOyYTANBgkqhkiG9w0BAQsFADBhMQswCQYDVQQGEwJV
czAeFw0xOTAyMDQyMzEyNTBaFw0yMDAyMDQyMzEyNTBaMA0xCzAJBgNVBAYTAnVz UzELMAkGA1UECAwCQ0ExCzAJBgNVBAcMAlNGMRAwDgYDVQQKDAdDb21wYW55MQww
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzZUXMnS5X8HWxTvHAc82 CgYDVQQLDANPcmcxGDAWBgNVBAMMD3d3dy5leGFtcGxlLmNvbTAeFw0xOTAzMjky
Q2d32fiPQGtD+fp3OV90l6RC9jgMdH4yTVUgX5mYYcW0k89RaP8g61H6b76F9gcd MzE5MDlaFw0yMDAzMjgyMzE5MDlaMGExCzAJBgNVBAYTAlVTMQswCQYDVQQIDAJD
yZ1idqKI1AU9aeBUPV8wkrouhR/6Omv8fA7yr9tVmNo53jPN7WyKoBoU0r7Yj9Ez QTELMAkGA1UEBwwCU0YxEDAOBgNVBAoMB0NvbXBhbnkxDDAKBgNVBAsMA09yZzEY
g3qjv/808Jlgby3EhduruyyfdvSt5ZFXnOz2D3SF9DS4yrM2jSw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fKtvTmE9kxZSUIo4kIvv8V9ZM72gJhDN
8D/lXduTZ9JMwLOa1NUB8/I6CbaU3VzWkfodArKKpQF3M+LLgK03i12PD0KPQ5zv
bwaNoQo6cTmPNIdsVZETRvPqONiCUaQV57G74dGtjeirCh/DO5EYRtb1thgS7TGm
+Xg8OC5vZ6g0+xsrSqDBmWNtlI7S3bsL5C3LIEOOAL1ZJHRy2KvIGQ9ipb3XjnKS
N7/wlQduRyPH7oaD/o4xf5Gt
-----END CERTIFICATE----- -----END CERTIFICATE-----

Binary file not shown.

View File

@ -1,28 +1,27 @@
-----BEGIN PRIVATE KEY----- -----BEGIN RSA PRIVATE KEY-----
MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDNlRcydLlfwdbF MIIEpQIBAAKCAQEA2uFoWm74qumqIIsBBf/rgP3ZtZw6dRQhVoYjIwYk00T1RLmm
O8cBzzZDZ3fZ+I9Aa0P5+nc5X3SXpEL2OAx0fjJNVSBfmZhhxbSTz1Fo/yDrUfpv bt8rYNh3lehmnrQlM/YC3dzcspucGqIfvs5FEReh/vgvsqY3lfy47Q1zzdtBrKq2
voX2Bx3JnWJ2oojUBT1p4FQ9XzCSui6FH/o6a/x8DvKv21WY2jneM83tbIqgGhTS ZBroAuJUe4ayMYz/L/2jAtPtGDQqWyzhKv6x/oz6N/tKqlzoGbjSGSJUqKAV+Tuo
vtiP0TODeqO//zTwmWBvLcSF26u7LJ929K3lkVec7PYPdIX0NLjKszaNLDhlO6hU 4YI4xw3r/RJg3I3+ruXOgM65GBdja7usI/BhseEOp9VXotoTEItGmvG2RFZ4A7cN
x9ny9l4VXMuj/6xXyqiRTrAFMQ4CZlDt7/NlXioCgfZndWP+4PVmv8xdjKHzVF1e 124xgiFl2IeYuC60jteZ+bnhPiqxcdzf3K4dnZlzrYma+FxwWbaow4wlpQcZVFdZ
kOohfBVnb0sQ5rZ5MYUR298b612++4i9J0Xf5ZsuvCfYQJ/AnzOYrJNq49FXimP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V9uQpIY/gwEwKBgQCCYnd9fD8L4nGyOLoD mqGK9NkCgYEAq3dzHI0DGAJrR19sWl2LcqI19sj5a91tHx4cl1dJXS/iApOLLieU
eUzMV7G8TZfinlxCNMVXfpn4Z8OaYHOk5NiujHK55w4ghx06NQw038qhnX0ogbjU zyUGkwfsqjHPAZ7GacICeBojIn/7KdPdlSKAbGVAU3d4qzvFS0qmWzObplBz3niT
caWOwCIbrYgx2fwYuOZbJFXdjWlpjIK3RFOcbNCNgCRLT6Lgz4uZYZ9RVftADvMi Xnep2XLaVXqwlFJZZ6AHeKzYmMH0d0raiou2bpEUBqYizy2fi3NI4mA=
zR1QsLWnIvARbTtOPfZqizT2gQ== -----END RSA PRIVATE KEY-----
-----END PRIVATE KEY-----

View File

@ -11,11 +11,10 @@ use parking_lot::Mutex;
use net2::TcpBuilder; use net2::TcpBuilder;
// #[cfg(feature = "tls")]
// use native_tls::TlsAcceptor;
#[cfg(feature = "ssl")] #[cfg(feature = "ssl")]
use openssl::ssl::{SslAcceptor, SslAcceptorBuilder}; use openssl::ssl::{SslAcceptor, SslAcceptorBuilder};
#[cfg(feature = "rust-tls")]
use rustls::ServerConfig as RustlsServerConfig;
struct Socket { struct Socket {
scheme: &'static str, scheme: &'static str,
@ -254,19 +253,6 @@ where
Ok(self) Ok(self)
} }
// #[cfg(feature = "tls")]
// /// Use listener for accepting incoming tls connection requests
// ///
// /// HttpServer does not change any configuration for TcpListener,
// /// it needs to be configured before passing it to listen() method.
// pub fn listen_nativetls(self, lst: net::TcpListener, acceptor: TlsAcceptor) -> Self {
// use actix_server::ssl;
// self.listen_with(lst, move || {
// ssl::NativeTlsAcceptor::new(acceptor.clone()).map_err(|_| ())
// })
// }
#[cfg(feature = "ssl")] #[cfg(feature = "ssl")]
/// Use listener for accepting incoming tls connection requests /// Use listener for accepting incoming tls connection requests
/// ///
@ -294,7 +280,7 @@ where
let addr = lst.local_addr().unwrap(); let addr = lst.local_addr().unwrap();
self.sockets.push(Socket { self.sockets.push(Socket {
addr, addr,
scheme: "http", scheme: "https",
}); });
self.builder = Some(self.builder.take().unwrap().listen( self.builder = Some(self.builder.take().unwrap().listen(
@ -320,12 +306,52 @@ where
/// Use listener for accepting incoming tls connection requests /// Use listener for accepting incoming tls connection requests
/// ///
/// This method sets alpn protocols to "h2" and "http/1.1" /// This method sets alpn protocols to "h2" and "http/1.1"
pub fn listen_rustls(self, lst: net::TcpListener, config: ServerConfig) -> Self { pub fn listen_rustls(
use super::{RustlsAcceptor, ServerFlags}; mut self,
lst: net::TcpListener,
config: RustlsServerConfig,
) -> io::Result<Self> {
self.listen_rustls_inner(lst, config)?;
Ok(self)
}
self.listen_with(lst, move || { #[cfg(feature = "rust-tls")]
RustlsAcceptor::with_flags(config.clone(), flags).map_err(|_| ()) fn listen_rustls_inner(
}) &mut self,
lst: net::TcpListener,
mut config: RustlsServerConfig,
) -> io::Result<()> {
use actix_server::ssl::{RustlsAcceptor, SslError};
let protos = vec!["h2".to_string().into(), "http/1.1".to_string().into()];
config.set_protocols(&protos);
let acceptor = RustlsAcceptor::new(config);
let factory = self.factory.clone();
let cfg = self.config.clone();
let addr = lst.local_addr().unwrap();
self.sockets.push(Socket {
addr,
scheme: "https",
});
self.builder = Some(self.builder.take().unwrap().listen(
format!("actix-web-service-{}", addr),
lst,
move || {
let c = cfg.lock();
acceptor.clone().map_err(|e| SslError::Ssl(e)).and_then(
HttpService::build()
.keep_alive(c.keep_alive)
.client_timeout(c.client_timeout)
.client_disconnect(c.client_shutdown)
.finish(factory())
.map_err(|e| SslError::Service(e))
.map_init_err(|_| ()),
)
},
)?);
Ok(())
} }
/// The socket address to bind /// The socket address to bind
@ -372,22 +398,6 @@ where
} }
} }
// #[cfg(feature = "tls")]
// /// The ssl socket address to bind
// ///
// /// To bind multiple addresses this method can be called multiple times.
// pub fn bind_nativetls<A: net::ToSocketAddrs>(
// self,
// addr: A,
// acceptor: TlsAcceptor,
// ) -> io::Result<Self> {
// use actix_server::ssl::NativeTlsAcceptor;
// self.bind_with(addr, move || {
// NativeTlsAcceptor::new(acceptor.clone()).map_err(|_| ())
// })
// }
#[cfg(feature = "ssl")] #[cfg(feature = "ssl")]
/// Start listening for incoming tls connections. /// Start listening for incoming tls connections.
/// ///
@ -415,16 +425,15 @@ where
/// ///
/// This method sets alpn protocols to "h2" and "http/1.1" /// This method sets alpn protocols to "h2" and "http/1.1"
pub fn bind_rustls<A: net::ToSocketAddrs>( pub fn bind_rustls<A: net::ToSocketAddrs>(
self, mut self,
addr: A, addr: A,
builder: ServerConfig, config: RustlsServerConfig,
) -> io::Result<Self> { ) -> io::Result<Self> {
use super::{RustlsAcceptor, ServerFlags}; let sockets = self.bind2(addr)?;
use actix_service::NewServiceExt; for lst in sockets {
self.listen_rustls_inner(lst, config.clone())?;
self.bind_with(addr, move || { }
RustlsAcceptor::with_flags(builder.clone(), flags).map_err(|_| ()) Ok(self)
})
} }
} }

View File

@ -1,31 +1,20 @@
-----BEGIN CERTIFICATE----- -----BEGIN CERTIFICATE-----
MIIFXTCCA0WgAwIBAgIJAJ3tqfd0MLLNMA0GCSqGSIb3DQEBCwUAMGExCzAJBgNV MIIDPjCCAiYCCQCmkoCBehOyYTANBgkqhkiG9w0BAQsFADBhMQswCQYDVQQGEwJV
BAYTAlVTMQswCQYDVQQIDAJDRjELMAkGA1UEBwwCU0YxEDAOBgNVBAoMB0NvbXBh UzELMAkGA1UECAwCQ0ExCzAJBgNVBAcMAlNGMRAwDgYDVQQKDAdDb21wYW55MQww
bnkxDDAKBgNVBAsMA09yZzEYMBYGA1UEAwwPd3d3LmV4YW1wbGUuY29tMB4XDTE4 CgYDVQQLDANPcmcxGDAWBgNVBAMMD3d3dy5leGFtcGxlLmNvbTAeFw0xOTAzMjky
MDcyOTE4MDgzNFoXDTE5MDcyOTE4MDgzNFowYTELMAkGA1UEBhMCVVMxCzAJBgNV MzE5MDlaFw0yMDAzMjgyMzE5MDlaMGExCzAJBgNVBAYTAlVTMQswCQYDVQQIDAJD
BAgM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NuviBFJHtzOrSb6tqqenQEyQf6h9/12+DTW
t5pSIiixHrzxHiFqOoCLRKGToQB+71rSINwTf0nITNpGBWmSj5VcC3VV3TG5/XxI
fPlxV2yhD5WFDPVNGBGvwPDSh4jSMZdZMSNBZCy4XWFNSKjGEWoK4DFYed3DoSt9
5IG1YwKCAQA63ntHl64KJUWlkwNbboU583FF3uWBjee5VqoGKHhf3CkKMxhtGqnt
+oN7t5VdUEhbinhqdx1dyPPvIsHCS3K1pkjqii4cyzNCVNYa2dQ00Qq+QWZBpwwc
3GAkz8rFXsGIPMDa1vxpU6mnBjzPniKMcsZ9tmQDppCEpBGfLpio2eAA5IkK8eEf
cIDB3CM0Vo94EvI76CJZabaE9IJ+0HIJb2+jz9BJ00yQBIqvJIYoNy9gP5Xjpi+T
qV/tdMkD5jwWjHD3AYHLWKUGkNwwkAYFeqT/gX6jpWBP+ZRPOp011X3KInJFSpKU
DT5GQ1Dux7EMTCwVGtXqjO8Ym5wjwwsfAoIBAEcxlhIW1G6BiNfnWbNPWBdh3v/K
5Ln98Rcrz8UIbWyl7qNPjYb13C1KmifVG1Rym9vWMO3KuG5atK3Mz2yLVRtmWAVc
fxzR57zz9MZFDun66xo+Z1wN3fVxQB4CYpOEI4Lb9ioX4v85hm3D6RpFukNtRQEc
Gfr4scTjJX4jFWDp0h6ffMb8mY+quvZoJ0TJqV9L9Yj6Ksdvqez/bdSraev97bHQ
4gbQxaTZ6WjaD4HjpPQefMdWp97Metg0ZQSS8b8EzmNFgyJ3XcjirzwliKTAQtn6
I2sd0NCIooelrKRD8EJoDUwxoOctY7R97wpZ7/wEHU45cBCbRV3H4JILS5c=
-----END RSA PRIVATE KEY----- -----END RSA PRIVATE KEY-----

View File

@ -1,4 +1,6 @@
use std::io::{Read, Write}; use std::io::{Read, Write};
use std::sync::mpsc;
use std::thread;
use actix_http::http::header::{ use actix_http::http::header::{
ContentEncoding, ACCEPT_ENCODING, CONTENT_ENCODING, CONTENT_LENGTH, ContentEncoding, ACCEPT_ENCODING, CONTENT_ENCODING, CONTENT_LENGTH,
@ -14,10 +16,12 @@ use flate2::Compression;
use futures::stream::once; use futures::stream::once;
use rand::{distributions::Alphanumeric, Rng}; use rand::{distributions::Alphanumeric, Rng};
use actix_web::{dev::HttpMessageBody, web, App}; use actix_web::{dev::HttpMessageBody, http, test, web, App, HttpResponse, HttpServer};
#[cfg(any(feature = "brotli", feature = "flate2-zlib", feature = "flate2-rust"))] #[cfg(any(feature = "brotli", feature = "flate2-zlib", feature = "flate2-rust"))]
use actix_web::middleware::encoding; use actix_web::middleware::encoding;
#[cfg(any(feature = "brotli", feature = "flate2-zlib", feature = "flate2-rust"))]
use actix_web::middleware::encoding::BodyEncoding;
const STR: &str = "Hello World Hello World Hello World Hello World Hello World \ const STR: &str = "Hello World Hello World Hello World Hello World Hello World \
Hello World Hello World Hello World Hello World Hello World \ Hello World Hello World Hello World Hello World Hello World \
@ -678,69 +682,93 @@ fn test_brotli_encoding_large() {
// assert_eq!(bytes, Bytes::from(data)); // assert_eq!(bytes, Bytes::from(data));
// } // }
// #[cfg(all(feature = "rust-tls", feature = "ssl"))] #[cfg(all(
// #[test] feature = "rust-tls",
// fn test_reading_deflate_encoding_large_random_ssl() { feature = "ssl",
// use actix::{Actor, System}; any(feature = "flate2-zlib", feature = "flate2-rust")
// use openssl::ssl::{SslConnector, SslMethod, SslVerifyMode}; ))]
// use rustls::internal::pemfile::{certs, rsa_private_keys}; #[test]
// use rustls::{NoClientAuth, ServerConfig}; fn test_reading_deflate_encoding_large_random_ssl() {
// use std::fs::File; use openssl::ssl::{SslConnector, SslMethod, SslVerifyMode};
// use std::io::BufReader; use rustls::internal::pemfile::{certs, rsa_private_keys};
use rustls::{NoClientAuth, ServerConfig};
use std::fs::File;
use std::io::BufReader;
// // load ssl keys let addr = TestServer::unused_addr();
// let mut config = ServerConfig::new(NoClientAuth::new()); let (tx, rx) = mpsc::channel();
// let cert_file = &mut BufReader::new(File::open("tests/cert.pem").unwrap());
// let key_file = &mut BufReader::new(File::open("tests/key.pem").unwrap());
// let cert_chain = certs(cert_file).unwrap();
// let mut keys = rsa_private_keys(key_file).unwrap();
// config.set_single_cert(cert_chain, keys.remove(0)).unwrap();
// let data = rand::thread_rng() let data = rand::thread_rng()
// .sample_iter(&Alphanumeric) .sample_iter(&Alphanumeric)
// .take(160_000) .take(160_000)
// .collect::<String>(); .collect::<String>();
// let srv = test::TestServer::build().rustls(config).start(|app| { thread::spawn(move || {
// app.handler(|req: &HttpRequest| { let sys = actix_rt::System::new("test");
// req.body()
// .and_then(|bytes: Bytes| {
// Ok(HttpResponse::Ok()
// .content_encoding(http::ContentEncoding::Identity)
// .body(bytes))
// })
// .responder()
// })
// });
// let mut rt = System::new("test"); // load ssl keys
let mut config = ServerConfig::new(NoClientAuth::new());
let cert_file = &mut BufReader::new(File::open("tests/cert.pem").unwrap());
let key_file = &mut BufReader::new(File::open("tests/key.pem").unwrap());
let cert_chain = certs(cert_file).unwrap();
let mut keys = rsa_private_keys(key_file).unwrap();
config.set_single_cert(cert_chain, keys.remove(0)).unwrap();
// // client connector let srv = HttpServer::new(|| {
// let mut builder = SslConnector::builder(SslMethod::tls()).unwrap(); App::new().service(web::resource("/").route(web::to(|bytes: Bytes| {
// builder.set_verify(SslVerifyMode::NONE); Ok::<_, Error>(
// let conn = client::ClientConnector::with_connector(builder.build()).start(); HttpResponse::Ok()
.encoding(http::ContentEncoding::Identity)
.body(bytes),
)
})))
})
.bind_rustls(addr, config)
.unwrap()
.start();
// // encode data let _ = tx.send((srv, actix_rt::System::current()));
// let mut e = ZlibEncoder::new(Vec::new(), Compression::default()); let _ = sys.run();
// e.write_all(data.as_ref()).unwrap(); });
// let enc = e.finish().unwrap(); let (srv, _sys) = rx.recv().unwrap();
let client = test::run_on(|| {
let mut builder = SslConnector::builder(SslMethod::tls()).unwrap();
builder.set_verify(SslVerifyMode::NONE);
let _ = builder.set_alpn_protos(b"\x02h2\x08http/1.1").unwrap();
// // client request awc::Client::build()
// let request = client::ClientRequest::build() .connector(
// .uri(srv.url("/")) awc::Connector::new()
// .method(http::Method::POST) .timeout(std::time::Duration::from_millis(500))
// .header(http::header::CONTENT_ENCODING, "deflate") .ssl(builder.build())
// .with_connector(conn) .service(),
// .body(enc) )
// .unwrap(); .finish()
// let response = rt.block_on(request.send()).unwrap(); });
// assert!(response.status().is_success());
// // read response // encode data
// let bytes = rt.block_on(response.body()).unwrap(); let mut e = ZlibEncoder::new(Vec::new(), Compression::default());
// assert_eq!(bytes.len(), data.len()); e.write_all(data.as_ref()).unwrap();
// assert_eq!(bytes, Bytes::from(data)); let enc = e.finish().unwrap();
// }
// client request
let _req = client
.post(format!("https://{}/", addr))
.header(http::header::CONTENT_ENCODING, "deflate")
.send_body(enc);
// TODO: fix
// let response = test::block_on(req).unwrap();
// assert!(response.status().is_success());
// read response
// let bytes = test::block_on(response.body()).unwrap();
// assert_eq!(bytes.len(), data.len());
// assert_eq!(bytes, Bytes::from(data));
// stop
let _ = srv.stop(false);
}
// #[cfg(all(feature = "tls", feature = "ssl"))] // #[cfg(all(feature = "tls", feature = "ssl"))]
// #[test] // #[test]