Skip to content

feat(libapi): add RtpSecureMediaEnum for RTP/SRTP security modes#209

Open
brancan wants to merge 2 commits into
hnimminh:masterfrom
brancan:pr/libreapi-rtp-secure-media-enum
Open

feat(libapi): add RtpSecureMediaEnum for RTP/SRTP security modes#209
brancan wants to merge 2 commits into
hnimminh:masterfrom
brancan:pr/libreapi-rtp-secure-media-enum

Conversation

@brancan

@brancan brancan commented May 7, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR introduces a new RtpSecureMediaEnum to give explicit control over RTP/SRTP security in the MediaModel.

Changes

  • New enum RtpSecureMediaEnum with four modes:
    • mandatory: always SRTP
    • optional: SRTP if supported by remote
    • forbidden: never SRTP
    • false: no SRTP (current default behavior)
  • MediaModel extended with a rtp_secure_media field, defaulting to false to preserve backwards compatibility.

Why

The codebase already supports SRTP at the FreeSWITCH layer, but the libreapi data model lacks a first-class field to declare per-class media security policy. Exposing it via a typed Pydantic enum makes it straightforward for clients (WebUI, automation, ansible) to set it consistently and have the API validate the values.

Backward compatibility

Default false keeps the current behavior, so existing deployments are unaffected.

Test plan

  • Existing tests still pass (no behavioral change when rtp_secure_media=false).
  • New field accepted via API and persisted/loaded correctly.
  • Reject unknown values with a Pydantic validation error.

Cherry-picked from a downstream deployment branch where this addition has been running for a while.

Made with Cursor

- Introduced `RtpSecureMediaEnum` to define security modes for RTP/SRTP: mandatory, optional, forbidden, and false.
- Updated `MediaModel` to include `rtp_secure_media` field, allowing configuration of RTP/SRTP security settings.

This commit enhances media configuration capabilities by providing explicit options for RTP security modes.
@brancan

brancan commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Gentle ping on this one — happy to make any changes if there's feedback. Let us know if there's anything blocking it.

@hnimminh
hnimminh self-requested a review July 14, 2026 16:05

@hnimminh hnimminh left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

SRTP (secured media) will be enable automatically if SIP TLS is enabled.
have you try it?

…ound legs

The Pydantic field existed but nothing read it: callng only forced SRTP
automatically when the SIP transport was TLS, hardcoded to mandatory.

inMediaProcess/outMediaProcess now set rtp_secure_media from the media
class (mandatory/optional), and the legacy TLS-triggered auto-mandatory
block only fires when the class is unset or explicitly 'false', so it
never overrides an explicit mandatory/optional/forbidden choice.

Validated with a standalone Lua harness (mocked rdbconn/DxLeg) against
the exact extracted function source, covering all four enum values on
both legs plus the TLS-gate interaction.
@brancan

brancan commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

You're right that SRTP auto-enables today whenever SIP transport is TLS (hardcoded to mandatory in callng/main.lua). But that also exposed a gap in this PR as originally submitted: it only added the rtp_secure_media field to MediaModel, callng never actually read it. The field was a complete no-op, we confirmed it by grepping for every reference to it.

We only noticed because our own production Redis already had rtp_secure_media set per media class (mandatory/optional/forbidden) on live interconnects, clearly expecting the field to do something. It wasn't.

Pushed a commit that wires it up: inMediaProcess/outMediaProcess now read rtp_secure_media from the media class and set FreeSWITCH's variable accordingly, and the existing TLS auto-mandatory block only fires when the class is unset or false (the backward-compatible default), so it never overrides an explicit choice. That gets you real per-class control, forbidding SRTP even over TLS, or offering it as optional over plain UDP, neither of which the TLS-only path can do.

Validated with a standalone Lua harness (mocked rdbconn/DxLeg, loaded the exact function source) covering all four enum values on both legs plus the TLS-gate interaction, no FreeSWITCH process needed. Ready for another look.

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.

2 participants