Added default server if client doesn't use sni

This commit is contained in:
int 80h
2020-05-14 15:33:45 -04:00
parent dfae3705c4
commit 3fff95daec
2 changed files with 13 additions and 15 deletions

View File

@@ -2,7 +2,8 @@ port = 1965
# use "::" for ipv6 and ipv4 or "0.0.0.0" for ipv4 only
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]]
hostname = "example.com"

View File

@@ -12,7 +12,6 @@ use std::io::{self, BufRead, BufReader};
use std::net::ToSocketAddrs;
use std::os::unix::fs::PermissionsExt;
use std::path::{Path, PathBuf};
use tokio::io::AsyncWriteExt;
use tokio::net::TcpListener;
use tokio::prelude::*;
use tokio::runtime;
@@ -264,6 +263,7 @@ fn main() -> io::Result<()> {
let cfg = config::Config::new(&p)?;
let cmap = cfg.to_map();
let default = &cfg.server[0].hostname;
println!("Serving {} vhosts", cfg.server.len());
let addr = format!("{}:{}", cfg.host, cfg.port);
@@ -286,24 +286,21 @@ fn main() -> io::Result<()> {
let (stream, peer_addr) = listener.accept().await?;
let acceptor = acceptor.clone();
let cmap = cmap.clone();
let default = default.clone();
let fut = async move {
let mut stream = tokio_openssl::accept(&acceptor, stream)
let stream = tokio_openssl::accept(&acceptor, stream)
.await
.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) {
Some(h) => h,
None => {
// I'm not sure this will actually get called?
stream.write_all(b"59\tNotFound!\r\n").await?;
stream.flush().await?;
return Ok(());
let srv = match stream.ssl().servername(NameType::HOST_NAME) {
Some(s) => {
match cmap.get(s) {
Some(ss) => ss,
None => cmap.get(&default).unwrap(),
}
},
None => cmap.get(&default).unwrap(),
};
let con = conn::Connection { stream, peer_addr };