Skip to content

Expose EncryptRTP API through SRTP#360

Open
kevmo314 wants to merge 2 commits intomasterfrom
write-to-pair
Open

Expose EncryptRTP API through SRTP#360
kevmo314 wants to merge 2 commits intomasterfrom
write-to-pair

Conversation

@kevmo314
Copy link

@kevmo314 kevmo314 commented Jan 4, 2026

Description

Exposes EncryptRTP() to allow users to manually encrypt packets.

See pion/ice#863.

Reference issue

Fixes #...

session_srtp.go Outdated
Comment on lines 157 to 159
if pw, ok := s.session.nextConn.(interface {
WriteToPair(uint64, []byte) (int, error)
}); ok {
Copy link
Author

Choose a reason for hiding this comment

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

This assertion is unfortunate but since the underlying connection here is a net.Conn there's no strict requirement to actually support the same API.

Copy link
Author

Choose a reason for hiding this comment

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

On the other hand, this change also makes this API unintentionally backwards-compatible so we don't actually need to bump pion/ice and it will get picked up when the parent updates the dep version...

@codecov
Copy link

codecov bot commented Jan 4, 2026

Codecov Report

❌ Patch coverage is 44.44444% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.55%. Comparing base (030374f) to head (dbb7282).

Files with missing lines Patch % Lines
session_srtp.go 44.44% 4 Missing and 1 partial ⚠️

❌ Your patch check has failed because the patch coverage (44.44%) is below the target coverage (70.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #360      +/-   ##
==========================================
- Coverage   82.63%   82.55%   -0.08%     
==========================================
  Files          19       19              
  Lines        1457     1462       +5     
==========================================
+ Hits         1204     1207       +3     
- Misses        140      141       +1     
- Partials      113      114       +1     
Flag Coverage Δ
go 82.55% <44.44%> (-0.08%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kevmo314 kevmo314 requested a review from JoTurk January 6, 2026 17:22
Exposes `EncryptRTP()` which returns encrypted bytes, allowing
callers to write to any destination. This avoids leaking ICE
semantics into the SRTP layer.

See pion/ice#863.
@kevmo314 kevmo314 changed the title Expose WriteRTPToPair API through SRTP Expose EncryptRTP API through SRTP Jan 11, 2026
@kevmo314 kevmo314 requested a review from JoTurk January 11, 2026 04:10
@JoTurk
Copy link
Member

JoTurk commented Jan 11, 2026

@kevmo314 maybe we have to think about also datachannels, and adding batching in the future, maybe it should be some sort of conn that works with srtp, sctp without any change, Maybe I'm missing something, but I just don't want us to maintain multiple write paths, especially if we're going to add batch writer soon.

@kevmo314
Copy link
Author

@kevmo314 maybe we have to think about also datachannels, and adding batching in the future, maybe it should be some sort of conn that works with srtp, sctp without any change, Maybe I'm missing something, but I just don't want us to maintain multiple write paths, especially if we're going to add batch writer soon.

If we do not want ICE semantics to leak into SRTP, then SRTP cannot know about the existence of multiple paths since the net.Conn only exposes a single io.Writer destination. I'm not convinced of the value of creating a pion-specific Conn that exposes that information since that would be ICE leaking semantics through this new Conn type?

Exposing a separate encrypt API therefore seems reasonable, as it's signalling that "I want this packet processed but I will manage the sending myself". That fits in with the batching and datachannels context you raised as well, since it is up to the caller to get the packet to the destination and the caller is choosing to opt out of those features, which seems reasonable.

The crux of the issue is the necessary statefulness of SRTP though:

srtp/srtp.go

Line 146 in 030374f

s.updateRolloverCount(header.SequenceNumber, diff, false, 0)
I believe all the write paths must share the same encryption context otherwise the receiver will not be able to decrypt the packets correctly?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants