Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse SOL_TLS control message, closes #2064 #2065

Merged
merged 8 commits into from
Nov 10, 2023

Conversation

fasterthanlime
Copy link
Contributor

cf. #2064 - I've added the absolute minimum I need. We could swap that u8 with something more strongly-typed, but since I'm clearly the first person using ktls & the nix crate together, I'm treading lightly in terms of added lines.

Copy link
Member

@asomers asomers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a cool feature. I've long wanted to play with ktls myself (though in my case, the FreeBSD version), but haven't found an excuse. But before we can accept this, you need to move all of the C-API definitions into the libc crate. And you should also add a CHANGELOG entry.

src/sys/socket/mod.rs Outdated Show resolved Hide resolved
src/sys/socket/mod.rs Outdated Show resolved Hide resolved
/// `SOL_TLS` messages of type `TLS_GET_RECORD_TYPE`, containing the TLS message content type,
/// normally one of change_cipher_spec(20), alert(21), handshake(22) (for TLS 1.3
/// resumption tickets), application_data(23)
TlsGetRecordType(u8),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be an enum type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I briefly considered it but, for it to be future-proof it'd need an "Unknown" variant. I don't mind it happening, but I feel like there'd be many back-and-forths on the PR until everyone's happy with it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is good enough. Matching against magic numbers isn't Rusty at all. I think you should add the various types, including an Unknown variant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you wish — there's now an enum with the variants I know/care about.

bors added a commit to rust-lang/libc that referenced this pull request Jul 16, 2023
linux: add a few kTLS defintions

related: nix-rust/nix#2065

i think android has support, too, but if I put it in `linux-like` does that imply emscripten support?
@fasterthanlime
Copy link
Contributor Author

@asomers twelve years later, the requisite changes have been merged into libc (and released to crates.io), so this PR now bumps the dependency and uses the constants from there.

@fasterthanlime
Copy link
Contributor Author

@asomers is there anything I can do to help move this along? rustls/ktls#24 has been blocked on it for a while (..mostly while waiting for libc to merge+release, but the ball's in nix's court now).

@fasterthanlime
Copy link
Contributor Author

Update: I'm maintaining a fork of just this bit of nix now: https://crates.io/crates/ktls-recvmsg

(I'd like to deprecate that fork eventually)

@@ -1015,6 +1020,11 @@ impl ControlMessageOwned {
let dl = ptr::read_unaligned(p as *const libc::sockaddr_in6);
ControlMessageOwned::Ipv6OrigDstAddr(dl)
},
#[cfg(all(target_os = "linux"))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also include android.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine, but be warned I have not tested it on Android at all nor do I plan on maintaining/supporting that platform personally. My general opinion is that it's better to wait for someone who needs it, and then they can be a point of contact re: getting it working on that platform. That person isn't me for Android.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to revert this, since the libc constants for this are not available on android (my fault, since I did that PR too, but I'm not willing to block this PR on this).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. I thought the constant was available on Android in libc. I guess I grepped wrong. Sorry.

/// `SOL_TLS` messages of type `TLS_GET_RECORD_TYPE`, containing the TLS message content type,
/// normally one of change_cipher_spec(20), alert(21), handshake(22) (for TLS 1.3
/// resumption tickets), application_data(23)
TlsGetRecordType(u8),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is good enough. Matching against magic numbers isn't Rusty at all. I think you should add the various types, including an Unknown variant.

#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[repr(u8)]
#[non_exhaustive]
pub enum TlsGetRecordType {
Copy link
Contributor

@Arnavion Arnavion Nov 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edit: nvm, I confused the content type with the handshake type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fwiw, re: your original comment:

That said, and I know @asomers asked for it, but I don't think this belongs in the nix crate because it's about TLS, not libc or Linux.

I agree with this, but I'm willing to do whatever to get this PR merged at this point. I agree the API boundaries are kinda unclear right now, after all libc itself is a grab bag 🤷

Copy link
Member

@asomers asomers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The enum looks good. But don't forget to add a changelog entry.

@SteveLauC
Copy link
Member

Please see CONTRIBUTING.md on how to add changelog entries

@SteveLauC SteveLauC added this pull request to the merge queue Nov 10, 2023
Merged via the queue into nix-rust:master with commit b9ff39e Nov 10, 2023
35 checks passed
@SteveLauC
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants