Verify inbound E2EE media HMACs#196
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
📜 Recent review details⏰ Context from checks skipped due to timeout. (1)
🧰 Additional context used📓 Path-based instructions (2)**/*.go📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/!(ltsm)/**/*.go📄 CodeRabbit inference engine (AGENTS.md)
Files:
🔇 Additional comments (6)
📝 WalkthroughSummary by CodeRabbit
Walkthrough
ChangesE2EE Media HMAC Verification
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Pull request overview
This PR hardens the inbound E2EE media pipeline by authenticating encrypted media with HMAC-SHA256 before AES-CTR decryption, aligning receive-side behavior with the existing send-side HMAC conventions (including the special video chunk-hash mode).
Changes:
- Add a shared decrypt helper that verifies the trailing 32-byte HMAC prior to AES-CTR decryption, with separate HMAC input modes for file-like media vs. video.
- Route video decryption through a dedicated
DecryptVideoMediahook to match theHMAC(generateChunkHashes(ciphertext))convention. - Fail closed on
ENC_KMfallback decrypt failures (audio/video) and add unit tests covering valid/tampered media and HMAC mode mismatches.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/connector/media.go | Adds HMAC verification on inbound decrypt and introduces a video-specific decrypt path using chunk-hash MAC input. |
| pkg/connector/media_test.go | Adds unit coverage for valid decrypts, tampering, and HMAC-mode mismatch behavior (file-like vs video). |
| pkg/connector/handlers/video.go | Uses the new video decrypt hook and fails closed on ENC_KM fallback decrypt errors. |
| pkg/connector/handlers/handler.go | Extends handler dependencies with DecryptVideoMedia for video-specific HMAC mode. |
| pkg/connector/handlers/audio.go | Fails closed on ENC_KM fallback decrypt errors instead of uploading raw encrypted bytes. |
| pkg/connector/handle_message.go | Wires DecryptVideoMedia to the LineClient’s video decrypt implementation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
HMAC(ciphertext)conventionHMAC(generateChunkHashes(ciphertext))conventionENC_KMfallback decrypt errors instead of uploading raw encrypted bytesFixes #191
Testing
GOWORK=off go test ./pkg/connector ./pkg/connector/handlersGOWORK=off go vet ./pkg/connector ./pkg/connector/handlersGOWORK=off go run honnef.co/go/tools/cmd/staticcheck@latest ./pkg/connector ./pkg/connector/handlersGOWORK=off go run golang.org/x/tools/cmd/goimports@latest -local github.com/highesttt/matrix-line-messenger -l ...git diff --checkdocker build -t matrix-line-media-hmac .Notes
The live E2E test covers valid media still bridging correctly. The HMAC failure behavior is covered at unit level by tampering encrypted media bytes and tags directly, which is the deterministic security property fixed here.