Skip to content

Commit b9ff39e

Browse files
Parse SOL_TLS control message, closes #2064 (#2065)
* Parse SOL_TLS control message, closes #2064 * Only Linux gets SOL_TLS I guess (this is wrong, BSDs have it too) * Use libc constants * Also parse SOL_TLS on Android * Decode TLS record types * Only have TlsGetRecordType enum variant on supported platforms * Remove android from target platforms ...since the corresponding libc constant isn't gated for Android. * Add changelog entry
1 parent 49283c9 commit b9ff39e

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ targets = [
2828
]
2929

3030
[dependencies]
31-
libc = { version = "0.2.147", features = ["extra_traits"] }
31+
libc = { version = "0.2.148", features = ["extra_traits"] }
3232
bitflags = "2.3.1"
3333
cfg-if = "1.0"
3434
pin-utils = { version = "0.1.0", optional = true }

changelog/2065.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added `TlsGetRecordType` control message type and corresponding enum for linux

src/sys/socket/mod.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,10 @@ pub enum ControlMessageOwned {
863863
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
864864
Ipv6RecvErr(libc::sock_extended_err, Option<sockaddr_in6>),
865865

866+
/// `SOL_TLS` messages of type `TLS_GET_RECORD_TYPE`
867+
#[cfg(any(target_os = "linux"))]
868+
TlsGetRecordType(TlsGetRecordType),
869+
866870
/// Catch-all variant for unimplemented cmsg types.
867871
#[doc(hidden)]
868872
Unknown(UnknownCmsg),
@@ -880,6 +884,33 @@ pub struct Timestamps {
880884
pub hw_raw: TimeSpec,
881885
}
882886

887+
/// These constants correspond to TLS 1.2 message types, as defined in
888+
/// RFC 5246, Appendix A.1
889+
#[cfg(any(target_os = "linux"))]
890+
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
891+
#[repr(u8)]
892+
#[non_exhaustive]
893+
pub enum TlsGetRecordType {
894+
ChangeCipherSpec ,
895+
Alert,
896+
Handshake,
897+
ApplicationData,
898+
Unknown(u8),
899+
}
900+
901+
#[cfg(any(target_os = "linux"))]
902+
impl From<u8> for TlsGetRecordType {
903+
fn from(x: u8) -> Self {
904+
match x {
905+
20 => TlsGetRecordType::ChangeCipherSpec,
906+
21 => TlsGetRecordType::Alert,
907+
22 => TlsGetRecordType::Handshake,
908+
23 => TlsGetRecordType::ApplicationData,
909+
_ => TlsGetRecordType::Unknown(x),
910+
}
911+
}
912+
}
913+
883914
impl ControlMessageOwned {
884915
/// Decodes a `ControlMessageOwned` from raw bytes.
885916
///
@@ -1018,6 +1049,11 @@ impl ControlMessageOwned {
10181049
let dl = ptr::read_unaligned(p as *const libc::sockaddr_in6);
10191050
ControlMessageOwned::Ipv6OrigDstAddr(dl)
10201051
},
1052+
#[cfg(any(target_os = "linux"))]
1053+
(libc::SOL_TLS, libc::TLS_GET_RECORD_TYPE) => {
1054+
let content_type = ptr::read_unaligned(p as *const u8);
1055+
ControlMessageOwned::TlsGetRecordType(content_type.into())
1056+
},
10211057
(_, _) => {
10221058
let sl = std::slice::from_raw_parts(p, len);
10231059
let ucmsg = UnknownCmsg(*header, Vec::<u8>::from(sl));

0 commit comments

Comments
 (0)