added more SSL config flags

This commit is contained in:
Leonard Lorenz 2020-10-23 00:55:27 +02:00
parent d6aee1e99d
commit e69dc686f0
2 changed files with 9 additions and 5 deletions

View file

@ -4,4 +4,5 @@
- ROOT_PATH: path where html, static and database reside
- SSL_PATH: path to SSL certificates containing key.pem and cert.pem
- BIND_PORT: port to bind to
- SSL_PRIV_NAME: private key for the certificate
- SSL_CERT_NAME: public key for the certificate (fullchain)

View file

@ -10,22 +10,25 @@ extern crate tera;
use actix_files as fs;
use actix_web::{App, HttpServer};
use config::get_from_env;
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
let root_path = config::get_from_env("ROOT_PATH", true);
let root_path = get_from_env("ROOT_PATH", true);
let mut builder = SslAcceptor::mozilla_intermediate(SslMethod::tls()).unwrap();
builder
.set_private_key_file(
config::get_from_env("SSL_PATH", true) + "/key.pem",
get_from_env("SSL_PATH", true) + &get_from_env("SSL_PRIV_NAME", true),
SslFiletype::PEM,
)
.unwrap();
builder
.set_certificate_chain_file(config::get_from_env("SSL_PATH", true) + "/cert.pem")
.set_certificate_chain_file(
get_from_env("SSL_PATH", true) + &get_from_env("SSL_CERT_NAME", true),
)
.unwrap();
App::new()
@ -37,7 +40,7 @@ async fn main() -> std::io::Result<()> {
.service(routes::blog_new_post)
.service(fs::Files::new("/static", root_path + "/static"))
})
.bind(String::from("localhost:") + &config::get_from_env("BIND_PORT", true))?
.bind(String::from("localhost:") + &get_from_env("BIND_PORT", true))?
.run()
.await
}