add tls mux client
The latency is not great, and there are more authentication and authorization features that need to be added, but this shows that we can connect and talk to a remote muxer.
This commit is contained in:
1 parent
16bcf7cf54
commit
83de1117ff
4 files changed
+87
-1
No files matched your search
@@ -97,6 +97,31 @@ pub struct Config {
|
||||
/// the path to an x509 PEM encoded CA chain file
|
||||
pub mux_server_pem_ca: Option<PathBuf>,
|
||||
|
||||
/// When using the mux client domain, identifies the host:port
|
||||
/// pair of the remote server.
|
||||
pub mux_server_remote_address: Option<String>,
|
||||
|
||||
/// When using the mux client domain:
|
||||
/// the path to an x509 PEM encoded private key file
|
||||
pub mux_client_pem_private_key: Option<PathBuf>,
|
||||
|
||||
/// When using the mux client domain:
|
||||
/// the path to an x509 PEM encoded certificate file
|
||||
pub mux_client_pem_cert: Option<PathBuf>,
|
||||
|
||||
/// When using the mux client domain:
|
||||
/// the path to an x509 PEM encoded CA chain file
|
||||
pub mux_client_pem_ca: Option<PathBuf>,
|
||||
|
||||
/// When using the mux client domain, explicitly control whether
|
||||
/// the client checks that the certificate presented by the
|
||||
/// server matches the hostname portion of mux_server_remote_address.
|
||||
/// The default is true.
|
||||
/// This option is made available for troubleshooting purposes and
|
||||
/// should not be used outside of a controlled environment as it
|
||||
/// weakens the security of the TLS channel.
|
||||
pub mux_client_accept_invalid_hostnames: Option<bool>,
|
||||
|
||||
#[serde(default)]
|
||||
pub keys: Vec<Key>,
|
||||
}
|
||||
@@ -354,6 +379,11 @@ impl Default for Config {
|
||||
mux_server_pem_private_key: None,
|
||||
mux_server_pem_cert: None,
|
||||
mux_server_pem_ca: None,
|
||||
mux_server_remote_address: None,
|
||||
mux_client_pem_private_key: None,
|
||||
mux_client_pem_cert: None,
|
||||
mux_client_pem_ca: None,
|
||||
mux_client_accept_invalid_hostnames: None,
|
||||
keys: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,6 +96,8 @@ struct StartCommand {
|
||||
/// default domain for new tabs and windows
|
||||
#[structopt(long = "mux-client-as-default-domain")]
|
||||
mux_client_as_default_domain: bool,
|
||||
#[structopt(long = "mux-tls-client-as-default-domain")]
|
||||
mux_tls_client_as_default_domain: bool,
|
||||
|
||||
/// Instead of executing your shell, run PROG.
|
||||
/// For example: `wezterm start -- bash -l` will spawn bash
|
||||
@@ -146,6 +148,9 @@ fn run_terminal_gui(config: Arc<config::Config>, opts: &StartCommand) -> Result<
|
||||
let domain: Arc<dyn Domain> = if opts.mux_client_as_default_domain {
|
||||
let client = Client::new_unix_domain(&config)?;
|
||||
Arc::new(ClientDomain::new(client))
|
||||
} else if opts.mux_tls_client_as_default_domain {
|
||||
let client = Client::new_tls(&config)?;
|
||||
Arc::new(ClientDomain::new(client))
|
||||
} else {
|
||||
Arc::new(LocalDomain::new(&config)?)
|
||||
};
|
||||
|
||||
+51
-1
@@ -1,14 +1,19 @@
|
||||
#![allow(dead_code)]
|
||||
use crate::config::Config;
|
||||
use crate::server::codec::*;
|
||||
use crate::server::listener::IdentitySource;
|
||||
use crate::server::UnixStream;
|
||||
use failure::{bail, ensure, err_msg, Error, Fallible};
|
||||
use failure::{bail, ensure, err_msg, format_err, Error, Fallible};
|
||||
use log::info;
|
||||
use native_tls::TlsConnector;
|
||||
use std::convert::TryInto;
|
||||
use std::net::TcpStream;
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub trait ReadAndWrite: std::io::Read + std::io::Write {}
|
||||
impl ReadAndWrite for UnixStream {}
|
||||
impl ReadAndWrite for native_tls::TlsStream<std::net::TcpStream> {}
|
||||
|
||||
pub struct Client {
|
||||
stream: Box<dyn ReadAndWrite>,
|
||||
@@ -53,6 +58,51 @@ impl Client {
|
||||
Ok(Self { stream, serial: 0 })
|
||||
}
|
||||
|
||||
pub fn new_tls(config: &Arc<Config>) -> Fallible<Self> {
|
||||
let remote_address = config
|
||||
.mux_server_remote_address
|
||||
.as_ref()
|
||||
.ok_or_else(|| err_msg("missing mux_server_remote_address config value"))?;
|
||||
|
||||
let remote_host_name = remote_address.split(':').next().ok_or_else(|| {
|
||||
format_err!(
|
||||
"expected mux_server_remote_address to have the form 'host:port', but have {}",
|
||||
remote_address
|
||||
)
|
||||
})?;
|
||||
|
||||
let identity = IdentitySource::PemFiles {
|
||||
key: config
|
||||
.mux_client_pem_private_key
|
||||
.as_ref()
|
||||
.ok_or_else(|| err_msg("missing mux_client_pem_private_key config value"))?
|
||||
.into(),
|
||||
cert: config.mux_client_pem_cert.clone(),
|
||||
chain: config.mux_client_pem_ca.clone(),
|
||||
};
|
||||
|
||||
let connector = TlsConnector::builder()
|
||||
.identity(identity.try_into()?)
|
||||
.danger_accept_invalid_hostnames(
|
||||
config.mux_client_accept_invalid_hostnames.unwrap_or(false),
|
||||
)
|
||||
.build()?;
|
||||
|
||||
let stream = TcpStream::connect(remote_address)
|
||||
.map_err(|e| format_err!("connecting to {}: {}", remote_address, e))?;
|
||||
|
||||
let stream = Box::new(connector.connect(remote_host_name, stream).map_err(|e| {
|
||||
format_err!(
|
||||
"TlsConnector for {} with host name {}: {} ({:?})",
|
||||
remote_address,
|
||||
remote_host_name,
|
||||
e,
|
||||
e
|
||||
)
|
||||
})?);
|
||||
Ok(Self { stream, serial: 0 })
|
||||
}
|
||||
|
||||
pub fn send_pdu(&mut self, pdu: Pdu) -> Result<Pdu, Error> {
|
||||
let serial = self.serial;
|
||||
self.serial += 1;
|
||||
|
||||
@@ -48,6 +48,7 @@ impl LocalListener {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum IdentitySource {
|
||||
Pkcs12File {
|
||||
path: PathBuf,
|
||||
|
||||
Reference in new issue
Block a user