dimpl: configurable SRTP profile order
A DTLS 1.2 server in dimpl picks AES-256-GCM whenever the client offers it, and there is no setting. Our str0m peers are the DTLS server for official TeamSpeak 6 viewers, which offer all profiles, so our streams used GCM while official streams use AES_CM_128_HMAC_SHA1_80. ConfigBuilder::srtp_profiles sets the profiles in order of preference: the server picks the first of them the client offered, clients offer them in that order and reject a server that picks another. Unset, everything is as upstream. VOELIN-PATCH.md describes the patch and how to drop it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NJvYyRmTjKcb9i8eyYXK5G
This commit is contained in:
1 parent
d1c4424789
commit
8bb060167b
14 files changed
+448
-32
No files matched your search
+8
-1
@@ -524,7 +524,14 @@ impl State {
|
||||
UseSrtpExtension::parse(extension_data).map_err(InternalError::from)?;
|
||||
// Store the first profile as our negotiated profile
|
||||
if !use_srtp.profiles.is_empty() {
|
||||
client.negotiated_srtp_profile = Some(use_srtp.profiles[0].into());
|
||||
let profile: SrtpProfile = use_srtp.profiles[0].into();
|
||||
if !client.engine.config().srtp_profiles().contains(&profile) {
|
||||
return Err(Error::SecurityError(
|
||||
crate::SecurityError::ServerSelectedUnofferedSrtpProfile(profile),
|
||||
)
|
||||
.into());
|
||||
}
|
||||
client.negotiated_srtp_profile = Some(profile);
|
||||
trace!(
|
||||
"ServerHello UseSRTP extension processed; selected profile: {:?}",
|
||||
client.negotiated_srtp_profile
|
||||
|
||||
+1
-1
@@ -81,7 +81,7 @@ impl ClientHello {
|
||||
ranges.push((ExtensionType::SignatureAlgorithms, start_pos, buf.len()));
|
||||
|
||||
// Add use_srtp extension for DTLS-SRTP support
|
||||
let use_srtp = UseSrtpExtension::default();
|
||||
let use_srtp = UseSrtpExtension::from_profiles(config.srtp_profiles());
|
||||
let start_pos = buf.len();
|
||||
use_srtp.serialize(buf);
|
||||
ranges.push((ExtensionType::UseSrtp, start_pos, buf.len()));
|
||||
|
||||
@@ -87,7 +87,26 @@ impl UseSrtpExtension {
|
||||
UseSrtpExtension { profiles, mki }
|
||||
}
|
||||
|
||||
/// A UseSrtpExtension offering `profiles` in this order (duplicates
|
||||
/// skipped).
|
||||
pub fn from_profiles(profiles: &[SrtpProfile]) -> Self {
|
||||
let mut ids = SrtpProfileVec::new();
|
||||
for profile in profiles {
|
||||
let id = SrtpProfileId::from(*profile);
|
||||
if !ids.contains(&id) {
|
||||
// At most one entry per profile, so this always fits.
|
||||
let _ = ids.try_push(id);
|
||||
}
|
||||
}
|
||||
UseSrtpExtension {
|
||||
profiles: ids,
|
||||
mki: ArrayVec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a default UseSrtpExtension with standard profiles
|
||||
// Offers now come from Config::srtp_profiles (from_profiles).
|
||||
#[allow(dead_code)]
|
||||
pub fn default() -> Self {
|
||||
let mut profiles = SrtpProfileVec::new();
|
||||
// Add profiles in order of preference (most secure first)
|
||||
@@ -206,6 +225,28 @@ mod tests {
|
||||
assert_eq!(parsed.mki, mki);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_profiles_keeps_order() {
|
||||
let ext = UseSrtpExtension::from_profiles(&[
|
||||
SrtpProfile::AES128_CM_SHA1_80,
|
||||
SrtpProfile::AEAD_AES_256_GCM,
|
||||
SrtpProfile::AES128_CM_SHA1_80,
|
||||
]);
|
||||
assert_eq!(
|
||||
ext.profiles.as_slice(),
|
||||
&[
|
||||
SrtpProfileId::SRTP_AES128_CM_SHA1_80,
|
||||
SrtpProfileId::SRTP_AEAD_AES_256_GCM
|
||||
]
|
||||
);
|
||||
assert!(ext.mki.is_empty());
|
||||
// The default offer is the default configuration's.
|
||||
assert_eq!(
|
||||
UseSrtpExtension::from_profiles(SrtpProfile::ALL),
|
||||
UseSrtpExtension::default()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_use_srtp_parse_provided_bytes() {
|
||||
// Provided bytes: [0,8,0,7,0,8,0,1,0,2,0]
|
||||
|
||||
+5
-13
@@ -471,21 +471,13 @@ impl State {
|
||||
.into());
|
||||
}
|
||||
|
||||
// Select SRTP profile according to server priority: AES256GCM, AES128GCM, then SHA1
|
||||
// Select SRTP profile according to server priority: the configured
|
||||
// profiles (by default AES256GCM, AES128GCM, then SHA1)
|
||||
if let Some(profiles) = client_srtp_profiles {
|
||||
// Map client profile ids to SrtpProfile, then pick our preferred
|
||||
let mut selected_profile: Option<SrtpProfile> = None;
|
||||
for preferred in [
|
||||
SrtpProfile::AEAD_AES_256_GCM,
|
||||
SrtpProfile::AEAD_AES_128_GCM,
|
||||
SrtpProfile::AES128_CM_SHA1_80,
|
||||
] {
|
||||
if profiles.iter().any(|pid| preferred == (*pid).into()) {
|
||||
selected_profile = Some(preferred);
|
||||
break;
|
||||
}
|
||||
}
|
||||
server.negotiated_srtp_profile = selected_profile;
|
||||
let offered: ArrayVec<SrtpProfile, { SrtpProfileId::supported().len() }> =
|
||||
profiles.iter().map(|pid| (*pid).into()).collect();
|
||||
server.negotiated_srtp_profile = server.engine.config().select_srtp_profile(&offered);
|
||||
if let Some(profile) = server.negotiated_srtp_profile {
|
||||
debug!("Negotiated SRTP profile: {:?}", profile);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user