Added default server if client doesn't use sni
This commit is contained in:
@@ -2,7 +2,8 @@ port = 1965
|
|||||||
# use "::" for ipv6 and ipv4 or "0.0.0.0" for ipv4 only
|
# use "::" for ipv6 and ipv4 or "0.0.0.0" for ipv4 only
|
||||||
host = "::"
|
host = "::"
|
||||||
|
|
||||||
# There must be at least 1 server tag
|
# There must be at least 1 server tag if a client doesn't send sni the server
|
||||||
|
# will use this tag as its default.
|
||||||
# Server 1
|
# Server 1
|
||||||
[[server]]
|
[[server]]
|
||||||
hostname = "example.com"
|
hostname = "example.com"
|
||||||
|
|||||||
23
src/main.rs
23
src/main.rs
@@ -12,7 +12,6 @@ use std::io::{self, BufRead, BufReader};
|
|||||||
use std::net::ToSocketAddrs;
|
use std::net::ToSocketAddrs;
|
||||||
use std::os::unix::fs::PermissionsExt;
|
use std::os::unix::fs::PermissionsExt;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use tokio::io::AsyncWriteExt;
|
|
||||||
use tokio::net::TcpListener;
|
use tokio::net::TcpListener;
|
||||||
use tokio::prelude::*;
|
use tokio::prelude::*;
|
||||||
use tokio::runtime;
|
use tokio::runtime;
|
||||||
@@ -264,6 +263,7 @@ fn main() -> io::Result<()> {
|
|||||||
|
|
||||||
let cfg = config::Config::new(&p)?;
|
let cfg = config::Config::new(&p)?;
|
||||||
let cmap = cfg.to_map();
|
let cmap = cfg.to_map();
|
||||||
|
let default = &cfg.server[0].hostname;
|
||||||
println!("Serving {} vhosts", cfg.server.len());
|
println!("Serving {} vhosts", cfg.server.len());
|
||||||
|
|
||||||
let addr = format!("{}:{}", cfg.host, cfg.port);
|
let addr = format!("{}:{}", cfg.host, cfg.port);
|
||||||
@@ -286,24 +286,21 @@ fn main() -> io::Result<()> {
|
|||||||
let (stream, peer_addr) = listener.accept().await?;
|
let (stream, peer_addr) = listener.accept().await?;
|
||||||
let acceptor = acceptor.clone();
|
let acceptor = acceptor.clone();
|
||||||
let cmap = cmap.clone();
|
let cmap = cmap.clone();
|
||||||
|
let default = default.clone();
|
||||||
|
|
||||||
let fut = async move {
|
let fut = async move {
|
||||||
let mut stream = tokio_openssl::accept(&acceptor, stream)
|
let stream = tokio_openssl::accept(&acceptor, stream)
|
||||||
.await
|
.await
|
||||||
.expect("Couldn't accept");
|
.expect("Couldn't accept");
|
||||||
let sni = match stream.ssl().servername(NameType::HOST_NAME) {
|
|
||||||
Some(s) => s,
|
|
||||||
None => return Ok(()),
|
|
||||||
};
|
|
||||||
|
|
||||||
let srv = match cmap.get(sni) {
|
let srv = match stream.ssl().servername(NameType::HOST_NAME) {
|
||||||
Some(h) => h,
|
Some(s) => {
|
||||||
None => {
|
match cmap.get(s) {
|
||||||
// I'm not sure this will actually get called?
|
Some(ss) => ss,
|
||||||
stream.write_all(b"59\tNotFound!\r\n").await?;
|
None => cmap.get(&default).unwrap(),
|
||||||
stream.flush().await?;
|
|
||||||
return Ok(());
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
None => cmap.get(&default).unwrap(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let con = conn::Connection { stream, peer_addr };
|
let con = conn::Connection { stream, peer_addr };
|
||||||
|
|||||||
Reference in New Issue
Block a user