biffed: native_tls
We use openssl on all platforms now
This commit is contained in:
1 parent
7504742612
commit
cb9ec2fa2a
8 files changed
+7
-353
No files matched your search
Generated
-70
@@ -1677,24 +1677,6 @@ dependencies = [
|
||||
"winapi 0.3.8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "native-tls"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4b2df1a4c22fd44a62147fd8f13dd0f95c9d8ca7b2610299b2a2f9cf8964274e"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"libc",
|
||||
"log",
|
||||
"openssl",
|
||||
"openssl-probe",
|
||||
"openssl-sys",
|
||||
"schannel",
|
||||
"security-framework",
|
||||
"security-framework-sys",
|
||||
"tempfile",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "net2"
|
||||
version = "0.2.33"
|
||||
@@ -1945,12 +1927,6 @@ dependencies = [
|
||||
"openssl-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "openssl-probe"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de"
|
||||
|
||||
[[package]]
|
||||
name = "openssl-src"
|
||||
version = "111.6.1+1.1.1d"
|
||||
@@ -2604,16 +2580,6 @@ dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "schannel"
|
||||
version = "0.1.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "87f550b06b6cba9c8b8be3ee73f391990116bf527450d2556e9b9ce263b9a021"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"winapi 0.3.8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "scoped_threadpool"
|
||||
version = "0.1.9"
|
||||
@@ -2626,27 +2592,6 @@ version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b42e15e59b18a828bbf5c58ea01debb36b9b096346de35d941dcb89009f24a0d"
|
||||
|
||||
[[package]]
|
||||
name = "security-framework"
|
||||
version = "0.3.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ef2429d7cefe5fd28bd1d2ed41c944547d4ff84776f5935b456da44593a16df"
|
||||
dependencies = [
|
||||
"core-foundation 0.6.4",
|
||||
"core-foundation-sys 0.6.2",
|
||||
"libc",
|
||||
"security-framework-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "security-framework-sys"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e31493fc37615debb8c5090a7aeb4a9730bc61e77ab10b9af59f1a202284f895"
|
||||
dependencies = [
|
||||
"core-foundation-sys 0.6.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "0.9.0"
|
||||
@@ -3025,20 +2970,6 @@ dependencies = [
|
||||
"remove_dir_all",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tempfile"
|
||||
version = "3.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"rand 0.7.3",
|
||||
"redox_syscall",
|
||||
"remove_dir_all",
|
||||
"winapi 0.3.8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "term"
|
||||
version = "0.1.0"
|
||||
@@ -3619,7 +3550,6 @@ dependencies = [
|
||||
"log",
|
||||
"lru",
|
||||
"metrics",
|
||||
"native-tls",
|
||||
"notify",
|
||||
"notify-rust",
|
||||
"open",
|
||||
|
||||
+3
-5
@@ -41,8 +41,7 @@ lru = "0.4"
|
||||
open = "1.2"
|
||||
metrics = { version="0.12", features=["std"]}
|
||||
hdrhistogram = "6.3"
|
||||
native-tls = "0.2"
|
||||
openssl = {version="0.10", optional=true}
|
||||
openssl = "0.10"
|
||||
# file change notification
|
||||
notify = "4.0"
|
||||
palette = "0.5"
|
||||
@@ -105,9 +104,8 @@ core-graphics = "0.19"
|
||||
core-text = "15.0"
|
||||
|
||||
[features]
|
||||
default = ["enable_openssl", "vendor_openssl"]
|
||||
enable_openssl = ["openssl"]
|
||||
# FIXME: find a way to magically enable vendor_openssl only on macOS!
|
||||
default = ["vendor_openssl"]
|
||||
# FIXME: find a way to magically disable vendor_openssl only on linux!
|
||||
vendor_openssl = ["openssl/vendored"]
|
||||
|
||||
[workspace]
|
||||
|
||||
@@ -450,7 +450,6 @@ impl Reconnectable {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "enable_openssl")]
|
||||
pub fn tls_connect(
|
||||
&mut self,
|
||||
tls_client: TlsDomainClient,
|
||||
@@ -611,99 +610,6 @@ impl Reconnectable {
|
||||
self.stream.replace(stream);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "enable_openssl"))]
|
||||
pub fn tls_connect(
|
||||
&mut self,
|
||||
tls_client: TlsDomainClient,
|
||||
_initial: bool,
|
||||
ui: &mut ConnectionUI,
|
||||
) -> anyhow::Result<()> {
|
||||
use crate::server::listener::IdentitySource;
|
||||
use native_tls::TlsConnector;
|
||||
use std::convert::TryInto;
|
||||
|
||||
let remote_address = &tls_client.remote_address;
|
||||
|
||||
let remote_host_name = remote_address.split(':').next().ok_or_else(|| {
|
||||
anyhow!(
|
||||
"expected mux_server_remote_address to have the form 'host:port', but have {}",
|
||||
remote_address
|
||||
)
|
||||
})?;
|
||||
|
||||
if let Some(Ok(ssh_params)) = tls_client.ssh_parameters() {
|
||||
if self.tls_creds.is_none() {
|
||||
// We need to bootstrap via an ssh session
|
||||
let sess =
|
||||
ssh_connect_with_ui(&ssh_params.host_and_port, &ssh_params.username, ui)?;
|
||||
let mut chan = sess.channel_session()?;
|
||||
|
||||
// The `tlscreds` command will start the server if needed and then
|
||||
// obtain client credentials that we can use for tls.
|
||||
let cmd = format!("{} cli tlscreds", Self::wezterm_bin_path());
|
||||
ui.output_str(&format!("Running: {}\n", cmd));
|
||||
chan.exec(&cmd)?;
|
||||
let creds = match Pdu::decode(chan)?.pdu {
|
||||
Pdu::GetTlsCredsResponse(creds) => creds,
|
||||
_ => bail!("unexpected response to tlscreds"),
|
||||
};
|
||||
|
||||
// Save the credentials to disk, as that is currently the easiest
|
||||
// way to get them into the tls impl. Ideally we'd keep these entirely
|
||||
// in memory.
|
||||
std::fs::write(&self.tls_creds_ca_path()?, creds.ca_cert_pem.as_bytes())?;
|
||||
std::fs::write(
|
||||
&self.tls_creds_cert_path()?,
|
||||
creds.client_cert_pem.as_bytes(),
|
||||
)?;
|
||||
self.tls_creds.replace(creds);
|
||||
}
|
||||
}
|
||||
|
||||
let cert_file = match tls_client.pem_cert.clone() {
|
||||
Some(cert) => cert,
|
||||
None if self.tls_creds.is_some() => self.tls_creds_cert_path()?,
|
||||
None => bail!("no pem_cert configured"),
|
||||
};
|
||||
let key_file = match tls_client.pem_private_key.clone() {
|
||||
Some(key) => key,
|
||||
None if self.tls_creds.is_some() => self.tls_creds_cert_path()?,
|
||||
None => bail!("no pem_private_key configured"),
|
||||
};
|
||||
|
||||
let identity = IdentitySource::PemFiles {
|
||||
key: key_file.into(),
|
||||
cert: Some(cert_file),
|
||||
chain: tls_client.pem_ca.clone(),
|
||||
};
|
||||
|
||||
let connector = TlsConnector::builder()
|
||||
.identity(identity.try_into()?)
|
||||
.danger_accept_invalid_hostnames(tls_client.accept_invalid_hostnames)
|
||||
.build()?;
|
||||
|
||||
ui.output_str(&format!("Connecting to {}\n", remote_address));
|
||||
let stream = TcpStream::connect(remote_address)
|
||||
.with_context(|| format!("connecting to {}", remote_address))?;
|
||||
stream.set_nodelay(true)?;
|
||||
stream.set_write_timeout(Some(tls_client.write_timeout))?;
|
||||
stream.set_read_timeout(Some(tls_client.read_timeout))?;
|
||||
|
||||
let stream = Box::new(
|
||||
connector
|
||||
.connect(remote_host_name, stream)
|
||||
.with_context(|| {
|
||||
format!(
|
||||
"TlsConnector for {} with host name {}",
|
||||
remote_address, remote_host_name,
|
||||
)
|
||||
})?,
|
||||
);
|
||||
ui.output_str("Connected!\n");
|
||||
self.stream.replace(stream);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Client {
|
||||
|
||||
@@ -2,7 +2,7 @@ use crate::config::UnixDomain;
|
||||
use crate::create_user_owned_dirs;
|
||||
use crate::server::listener::{clientsession, umask};
|
||||
use crate::server::UnixListener;
|
||||
use anyhow::{anyhow, bail, Context as _};
|
||||
use anyhow::{anyhow, Context as _};
|
||||
use promise::spawn::spawn_into_main_thread;
|
||||
|
||||
pub struct LocalListener {
|
||||
@@ -64,7 +64,7 @@ fn safely_create_sock_path(unix_dom: &UnixDomain) -> anyhow::Result<UnixListener
|
||||
|
||||
let permissions = meta.permissions();
|
||||
if (permissions.mode() & 0o22) != 0 {
|
||||
bail!(
|
||||
anyhow::bail!(
|
||||
"The permissions for {} are insecure and currently \
|
||||
allow other users to write to it (permissions={:?})",
|
||||
sock_dir.display(),
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
use crate::config::{configuration, TlsDomainServer};
|
||||
use anyhow::{anyhow, bail, Context, Error};
|
||||
use log::error;
|
||||
use native_tls::Identity;
|
||||
use promise::spawn::spawn_into_main_thread;
|
||||
use std::convert::TryFrom;
|
||||
use std::net::TcpListener;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
use std::thread;
|
||||
|
||||
mod clientsession;
|
||||
mod local;
|
||||
mod not_ossl;
|
||||
mod ossl;
|
||||
mod pki;
|
||||
mod umask;
|
||||
@@ -20,41 +17,6 @@ lazy_static::lazy_static! {
|
||||
static ref PKI: pki::Pki = pki::Pki::init().expect("failed to initialize PKI");
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "enable_openssl"))]
|
||||
use not_ossl as tls_impl;
|
||||
#[cfg(feature = "enable_openssl")]
|
||||
use ossl as tls_impl;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum IdentitySource {
|
||||
Pkcs12File {
|
||||
path: PathBuf,
|
||||
password: String,
|
||||
},
|
||||
PemFiles {
|
||||
key: PathBuf,
|
||||
cert: Option<PathBuf>,
|
||||
chain: Option<PathBuf>,
|
||||
},
|
||||
}
|
||||
|
||||
impl TryFrom<IdentitySource> for Identity {
|
||||
type Error = Error;
|
||||
|
||||
fn try_from(source: IdentitySource) -> anyhow::Result<Identity> {
|
||||
match source {
|
||||
IdentitySource::Pkcs12File { path, password } => {
|
||||
let bytes = std::fs::read(&path)?;
|
||||
Identity::from_pkcs12(&bytes, &password)
|
||||
.with_context(|| format!("error loading pkcs12 file '{}'", path.display()))
|
||||
}
|
||||
IdentitySource::PemFiles { key, cert, chain } => {
|
||||
tls_impl::pem_files_to_identity(key, cert, chain)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn spawn_listener() -> anyhow::Result<()> {
|
||||
let config = configuration();
|
||||
for unix_dom in &config.unix_domains {
|
||||
@@ -65,7 +27,7 @@ pub fn spawn_listener() -> anyhow::Result<()> {
|
||||
}
|
||||
|
||||
for tls_server in &config.tls_servers {
|
||||
tls_impl::spawn_tls_listener(tls_server)?;
|
||||
ossl::spawn_tls_listener(tls_server)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
#![allow(unused)]
|
||||
|
||||
use super::*;
|
||||
use native_tls::TlsAcceptor;
|
||||
use std::convert::TryInto;
|
||||
|
||||
struct NetListener {
|
||||
acceptor: Arc<TlsAcceptor>,
|
||||
listener: TcpListener,
|
||||
}
|
||||
|
||||
impl NetListener {
|
||||
pub fn new(listener: TcpListener, acceptor: TlsAcceptor) -> Self {
|
||||
Self {
|
||||
listener,
|
||||
acceptor: Arc::new(acceptor),
|
||||
}
|
||||
}
|
||||
|
||||
fn run(&mut self) {
|
||||
for stream in self.listener.incoming() {
|
||||
match stream {
|
||||
Ok(stream) => {
|
||||
stream.set_nodelay(true).ok();
|
||||
let acceptor = self.acceptor.clone();
|
||||
|
||||
match acceptor.accept(stream) {
|
||||
Ok(stream) => {
|
||||
spawn_into_main_thread(async move {
|
||||
let mut session = clientsession::ClientSession::new(stream);
|
||||
thread::spawn(move || session.run());
|
||||
});
|
||||
}
|
||||
Err(e) => {
|
||||
error!("failed TlsAcceptor: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
error!("accept failed: {}", err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn spawn_tls_listener(tls_server: &TlsDomainServer) -> anyhow::Result<()> {
|
||||
let identity = IdentitySource::PemFiles {
|
||||
key: tls_server
|
||||
.pem_private_key
|
||||
.as_ref()
|
||||
.ok_or_else(|| anyhow!("missing pem_private_key config value"))?
|
||||
.into(),
|
||||
cert: tls_server.pem_cert.clone(),
|
||||
chain: tls_server.pem_ca.clone(),
|
||||
};
|
||||
|
||||
let mut net_listener = NetListener::new(
|
||||
TcpListener::bind(&tls_server.bind_address).with_context(|| {
|
||||
format!("error binding to bind_address {}", tls_server.bind_address,)
|
||||
})?,
|
||||
TlsAcceptor::new(identity.try_into()?)?,
|
||||
);
|
||||
thread::spawn(move || {
|
||||
net_listener.run();
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn pem_files_to_identity(
|
||||
_key: PathBuf,
|
||||
_cert: Option<PathBuf>,
|
||||
_chain: Option<PathBuf>,
|
||||
) -> anyhow::Result<Identity> {
|
||||
// This is a pain point in native_tls.
|
||||
// Once https://github.com/sfackler/rust-native-tls/pull/147
|
||||
// is done this might be doable in terms of pem files
|
||||
bail!("recompile wezterm using --features enable_openssl")
|
||||
}
|
||||
@@ -1,7 +1,4 @@
|
||||
#![cfg(feature = "enable_openssl")]
|
||||
use super::*;
|
||||
use openssl::pkcs12::Pkcs12;
|
||||
use openssl::pkey::PKey;
|
||||
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod, SslStream, SslVerifyMode};
|
||||
use openssl::x509::X509;
|
||||
|
||||
@@ -173,45 +170,3 @@ pub fn spawn_tls_listener(tls_server: &TlsDomainServer) -> Result<(), Error> {
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn pem_files_to_identity(
|
||||
key: PathBuf,
|
||||
cert: Option<PathBuf>,
|
||||
chain: Option<PathBuf>,
|
||||
) -> anyhow::Result<Identity> {
|
||||
// This is a bit of a redundant dance around;
|
||||
// the native_tls interface only allows for pkcs12
|
||||
// encoded identity information, but in my use case
|
||||
// I only have pem encoded identity information.
|
||||
// We can use openssl to convert the data to pkcs12
|
||||
// so that we can then pass it on using the Identity
|
||||
// type that native_tls requires.
|
||||
let key_bytes = std::fs::read(&key)?;
|
||||
let pkey = PKey::private_key_from_pem(&key_bytes)?;
|
||||
|
||||
let cert_bytes = std::fs::read(cert.as_ref().unwrap_or(&key))?;
|
||||
let x509_cert = X509::from_pem(&cert_bytes)?;
|
||||
|
||||
let chain_bytes = std::fs::read(chain.as_ref().unwrap_or(&key))?;
|
||||
let x509_chain = X509::stack_from_pem(&chain_bytes)?;
|
||||
|
||||
let password = "internal";
|
||||
let mut ca_stack = openssl::stack::Stack::new()?;
|
||||
for ca in x509_chain.into_iter() {
|
||||
ca_stack.push(ca)?;
|
||||
}
|
||||
let mut builder = Pkcs12::builder();
|
||||
builder.ca(ca_stack);
|
||||
let pkcs12 = builder.build(password, "", &pkey, &x509_cert)?;
|
||||
|
||||
let der = pkcs12.to_der()?;
|
||||
Identity::from_pkcs12(&der, password).with_context(|| {
|
||||
format!(
|
||||
"error creating identity from pkcs12 generated \
|
||||
from PemFiles {}, {:?}, {:?}",
|
||||
key.display(),
|
||||
cert,
|
||||
chain,
|
||||
)
|
||||
})
|
||||
}
|
||||
@@ -20,17 +20,7 @@ impl ReadAndWrite for UnixStream {
|
||||
false
|
||||
}
|
||||
}
|
||||
impl ReadAndWrite for native_tls::TlsStream<std::net::TcpStream> {
|
||||
fn set_non_blocking(&self, non_blocking: bool) -> anyhow::Result<()> {
|
||||
self.get_ref().set_nonblocking(non_blocking)?;
|
||||
Ok(())
|
||||
}
|
||||
fn has_read_buffered(&self) -> bool {
|
||||
self.buffered_read_size().unwrap_or(0) != 0
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "enable_openssl")]
|
||||
impl ReadAndWrite for openssl::ssl::SslStream<std::net::TcpStream> {
|
||||
fn set_non_blocking(&self, non_blocking: bool) -> anyhow::Result<()> {
|
||||
self.get_ref().set_nonblocking(non_blocking)?;
|
||||
@@ -128,13 +118,6 @@ impl AsPollFd for SocketDescriptor {
|
||||
}
|
||||
}
|
||||
|
||||
impl AsPollFd for native_tls::TlsStream<TcpStream> {
|
||||
fn as_poll_fd(&self) -> pollfd {
|
||||
self.get_ref().as_socket_descriptor().as_poll_fd()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "enable_openssl")]
|
||||
impl AsPollFd for openssl::ssl::SslStream<TcpStream> {
|
||||
fn as_poll_fd(&self) -> pollfd {
|
||||
self.get_ref().as_socket_descriptor().as_poll_fd()
|
||||
|
||||
Reference in new issue
Block a user