net/srtp: encrypt RTP header extensions (RFC 6904) - #444
Merged
Conversation
Encrypt the bodies of the RFC 8285 header-extension elements whose IDs are configured for encryption, leaving the 4-byte extension header, the element ID/length bytes, padding and unmarked elements in the clear so the extension stays parseable on the wire. The keystream is derived per stream with the header-extension key/salt labels (0x06/0x07) and applied with the packet's own SRTP IV. On send the extension is encrypted before the auth tag is computed; on receive it is decrypted only after the tag verifies, so the tag always covers the ciphertext. r_srtp_set_encrypted_header_extension registers which extension IDs are encrypted. The extra keys are derived when a stream is first used, so IDs must be registered during setup, before packets flow. Closes #443 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements RFC 6904 encryption of RTP header extensions in the SRTP layer, the first of the SRTP feature gaps split out of #221.
What
Encrypts the bodies of the RFC 8285 header-extension elements whose IDs are marked for encryption, while leaving the 4-byte extension header, each element's ID/length bytes, padding, and the bodies of unmarked elements in the clear. The extension therefore stays parseable on the wire, and the SRTP auth tag covers the encrypted form.
r_srtp_set_encrypted_header_extension (ctx, id, encrypted)registers which extension IDs are encrypted. The extra keys are derived when a stream is first used, so IDs must be registered during setup, before packets flow.0xBEDE) and two-byte (0x100x) RFC 8285 forms are handled; other profiles are authenticated but not encrypted.Testing
encrypt_hdr_ext_rfc6904asserts the produced ciphertext equals the RFC 6904 Appendix A.2 worked example byte-for-byte (SSRCCAFEBABE, seq0x1234, ROC 0, IDs 1/3/4 encrypted). This validates the key derivation, IV, AES-CM keystream and the per-element mask end to end against the spec.Security review
Audited for memory safety and cryptographic correctness. The element parse loop is bounds-checked against attacker-controlled length fields on the decrypt path, the encrypt-then-authenticate / verify-then-decrypt ordering holds on all paths including error returns, and the replay window is neither bypassed nor advanced on a failed packet. Derived key and salt scratch is cleared at teardown.
Scope
Header-extension encryption only. MKI and EKT remain tracked separately.
Closes #443
🤖 Generated with Claude Code