Skip to content

Commit

Permalink
feat: Migrate from ktls-recvmsg to nix 0.28
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterthanlime committed Mar 20, 2024
1 parent 2c952e4 commit 2fbf142
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 32 deletions.
23 changes: 10 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
31 changes: 13 additions & 18 deletions src/ktls_stream.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -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<IO> AsyncRead for KtlsStream<IO>
where
IO: AsRawFd + AsyncRead + AsyncReadReady,
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -229,21 +221,24 @@ 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
tracing::trace!(
"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?
Expand Down

0 comments on commit 2fbf142

Please sign in to comment.