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:
Claude committed 2026-09-26 23:36:41 +00:00
1 parent d1c4424789
commit 8bb060167b
14 files changed
+448 -32

No files matched your search

+9 -2
View File
@@ -718,7 +718,14 @@ impl State {
let (_, use_srtp) =
UseSrtpExtension::parse(ext_data).map_err(InternalError::from)?;
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!(
"EncryptedExtensions UseSRTP; selected profile: {:?}",
client.negotiated_srtp_profile
@@ -1272,7 +1279,7 @@ fn handshake_create_client_hello(
// 5. use_srtp extension
let srtp_start = ext_buf.len();
let use_srtp = UseSrtpExtension::default();
let use_srtp = UseSrtpExtension::from_profiles(engine.config().srtp_profiles());
use_srtp.serialize(&mut ext_buf);
let srtp_end = ext_buf.len();
extensions.push(Extension {
@@ -85,7 +85,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 = ArrayVec::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 = ArrayVec::new();
// Add profiles in order of preference (most secure first)
+15 -6
View File
@@ -732,15 +732,24 @@ impl State {
server.shared_secret = Some(shared_secret);
// Select SRTP profile: first from client list that the server supports.
// Select SRTP profile: with a configured order, the first of ours
// that the client offers; otherwise the first from the client list
// that the server supports.
// Per RFC 5764 Section 4.1.1, the server MUST select a profile that
// both sides support.
if let Some(ref profiles) = client_srtp_profiles {
for profile_id in profiles {
let profile: SrtpProfile = (*profile_id).into();
if SrtpProfile::ALL.contains(&profile) {
server.negotiated_srtp_profile = Some(profile);
break;
if server.engine.config().has_srtp_profile_order() {
let offered: ArrayVec<SrtpProfile, 3> =
profiles.iter().map(|pid| (*pid).into()).collect();
server.negotiated_srtp_profile =
server.engine.config().select_srtp_profile(&offered);
} else {
for profile_id in profiles {
let profile: SrtpProfile = (*profile_id).into();
if SrtpProfile::ALL.contains(&profile) {
server.negotiated_srtp_profile = Some(profile);
break;
}
}
}
}