1
0
mirror of https://github.com/vbrandl/bind9-api.git synced 2025-08-30 21:20:20 +02:00

TODO: TLS support

This commit is contained in:
Valentin Brandl
2018-07-08 21:59:38 +02:00
parent c50bcb38d7
commit a992d2ad49
4 changed files with 5 additions and 57 deletions

View File

@@ -6,14 +6,13 @@ description = "Web API to create, update and remove DNS entries in bind9"
license = "MIT/Apache-2.0"
[dependencies]
actix-web = { version = "0.6.14", features=["alpn"] }
actix-web = "0.6.14"
clap = "2.31.2"
crypto = { path = "../crypto" }
data = { path = "../data" }
failure = "0.1.1"
futures = "0.1.21"
log = "0.4.3"
openssl = "0.10"
pretty_env_logger = "0.2.3"
serde = "1.0.69"
serde_json = "1.0.22"

View File

@@ -49,7 +49,5 @@ pub fn parse_args() -> ::clap::ArgMatches<'static> {
(@arg PORT: -p --port +takes_value "Port to listen on (Defaults to 8000)")
(@arg HOST: -h --host +takes_value "Host to listen on (Defaults to 0.0.0.0)")
(@arg SERVER: -s --server +takes_value "Bind server (Defaults to 127.0.0.1)")
(@arg CERT: -c --cert +takes_value "TLS certificate chain file")
(@arg KEY: -k --key +takes_value "TLS key file")
).get_matches()
}

View File

@@ -47,7 +47,6 @@ extern crate failure;
extern crate futures;
#[macro_use]
extern crate log;
extern crate openssl;
extern crate pretty_env_logger;
extern crate serde;
extern crate serde_json;
@@ -60,7 +59,6 @@ use actix_web::{
};
use data::{Delete, Update};
use failure::Error;
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
use std::{
io::Write, process::{Command, Stdio}, sync::Arc,
};
@@ -149,31 +147,12 @@ fn main() {
.expect("Cannot parse port");
let host = matches.value_of("HOST").unwrap_or("0.0.0.0");
let host = format!("{}:{}", host, port);
let key = matches.value_of("KEY");
let cert = matches.value_of("CERT");
let server = server::new(move || {
server::new(move || {
App::with_state(config.clone())
.middleware(Logger::default())
.route("/record", http::Method::POST, update)
.route("/record", http::Method::DELETE, delete)
});
match (key, cert) {
(Some(k), Some(c)) => {
let mut builder = SslAcceptor::mozilla_intermediate(SslMethod::tls()).unwrap();
builder.set_private_key_file(k, SslFiletype::PEM).unwrap();
builder.set_certificate_chain_file(c).unwrap();
server.bind_ssl(host, builder)
},
(None, None) => server.bind(host),
(_, _) => panic!("When using TLS, the --cert and --key parameter must be set"),
}.unwrap()
.run()
// server::new(move || {
// App::with_state(config.clone())
// .middleware(Logger::default())
// .route("/record", http::Method::POST, update)
// .route("/record", http::Method::DELETE, delete)
// }).bind(host)
// .unwrap()
// .run();
}).bind(host)
.unwrap()
.run();
}