diff --git a/Cargo.lock b/Cargo.lock index f147124..1aaca93 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -141,6 +141,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cfg_aliases" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" + [[package]] name = "clang-sys" version = "1.7.0" @@ -309,11 +315,11 @@ name = "ktls" version = "5.0.0" dependencies = [ "futures-util", - "ktls-recvmsg", "ktls-sys", "lazy_static", "libc", "memoffset", + "nix", "num_enum", "oorandom", "pin-project-lite", @@ -329,16 +335,6 @@ dependencies = [ "tracing-subscriber", ] -[[package]] -name = "ktls-recvmsg" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d32e94a63f2f71bf1402f8c60c771ac1a51fd5a832d6534edab426f066b053d9" -dependencies = [ - "libc", - "nix", -] - [[package]] name = "ktls-sys" version = "1.0.1" @@ -453,12 +449,13 @@ checksum = "c9be0862c1b3f26a88803c4a49de6889c10e608b3ee9344e6ef5b45fb37ad3d1" [[package]] name = "nix" -version = "0.27.1" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2eb04e9c688eff1c89d72b407f168cf79bb9e867a9d3323ed6c01519eb9cc053" +checksum = "ab2156c4fce2f8df6c499cc1c763e4394b7482525bf2a9701c9d79d215f519e4" dependencies = [ "bitflags 2.4.2", "cfg-if", + "cfg_aliases", "libc", "memoffset", ] diff --git a/Cargo.toml b/Cargo.toml index 00098ac..8891693 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,9 +22,9 @@ memoffset = "0.9.0" pin-project-lite = "0.2.13" tokio = { version = "1.36.0", features = ["net", "macros", "io-util"] } ktls-sys = "1.0.1" -ktls-recvmsg = { version = "0.1.3" } num_enum = "0.7.2" futures-util = "0.3.30" +nix = { version = "0.28.0", features = ["socket", "uio", "net"] } [dev-dependencies] lazy_static = "1.4.0" diff --git a/src/ktls_stream.rs b/src/ktls_stream.rs index 6b3c607..a83c5ce 100644 --- a/src/ktls_stream.rs +++ b/src/ktls_stream.rs @@ -1,4 +1,7 @@ -use ktls_recvmsg::{recvmsg, ControlMessageOwned, Errno, MsgFlags, SockaddrIn}; +use nix::{ + errno::Errno, + sys::socket::{recvmsg, ControlMessageOwned, MsgFlags, SockaddrIn, TlsGetRecordType}, +}; use num_enum::FromPrimitive; use std::{ io::{self, IoSliceMut}, @@ -71,17 +74,6 @@ enum TlsAlertDescription { Other(u8), } -#[derive(Debug, PartialEq, Clone, Copy, num_enum::FromPrimitive)] -#[repr(u8)] -enum TlsRecordType { - ChangeCipherSpec = 20, - Alert = 21, - Handshake = 22, - ApplicationData = 23, - #[num_enum(catch_all)] - Other(u8), -} - impl AsyncRead for KtlsStream where IO: AsRawFd + AsyncRead + AsyncReadReady, @@ -165,11 +157,11 @@ where _ => panic!("unexpected cmsg type: {cmsg:#?}"), }; - match TlsRecordType::from_primitive(record_type) { - TlsRecordType::ChangeCipherSpec => { + match record_type { + TlsGetRecordType::ChangeCipherSpec => { panic!("change_cipher_spec isn't supported by the ktls crate") } - TlsRecordType::Alert => { + TlsGetRecordType::Alert => { // the alert level and description are in iovs let iov = r.iovs().next().expect("expected data in iovs"); @@ -229,7 +221,7 @@ where } return task::Poll::Ready(Ok(())); } - TlsRecordType::Handshake => { + TlsGetRecordType::Handshake => { // TODO: this is where we receive TLS 1.3 resumption tickets, // should those be stored anywhere? I'm not even sure what // format they have at this point @@ -237,13 +229,16 @@ where "ignoring handshake message (probably a resumption ticket)" ); } - TlsRecordType::ApplicationData => { + TlsGetRecordType::ApplicationData => { unreachable!("received TLS application in recvmsg, this is supposed to happen in the poll_read codepath") } - TlsRecordType::Other(t) => { + TlsGetRecordType::Unknown(t) => { // just ignore the record? tracing::trace!("received record_type {t:#?}"); } + _ => { + tracing::trace!("received unsupported record type"); + } }; // FIXME: this is hacky, but can we do better?