Discord Audio & Video End-to-End Encryption (DAVE) Protocol

repository·main·Indexed 41 days ago

https://github.com/discord/dave-protocol

Technical specifications and whitepaper for DAVE version 1.1, Discord's E2EE protocol for DM/GDM calls, server voice channels, and Go Live streams. It utilizes the Messaging Layer Security (MLS) protocol for group key exchange and the WebRTC encoded transform API for media encryption and decryption.

Tokens
10.8K
Snippets
15
Records
41
Agent score
3%

What's inside DAVE

  1. Overview of the Discord Audio & Video End-to-End Encryption (DAVE) Protocol

    main

    The DAVE protocol is Discord's implementation of end-to-end encryption (E2EE) for audio and video communications. It is designed to secure specific session types, including:

    • Direct Message (DM) calls
    • Group Direct Message (GDM) calls
    • Server voice channels (excluding stage channels)
    • Go Live streams

    As of September 2024, supporting Discord clients prefer using this protocol. By 2025, it is expected to be an enforced requirement for connecting to eligible audio/video session types.

  2. Overview of the DAVE Protocol architecture

    main

    The Discord Audio & Video End-to-End Encryption (DAVE) protocol (version 1.1) provides E2EE for DM/GDM calls, server voice channels, and Go Live streams.

    Core Workflow

    1. Protocol Negotiation: The Voice Gateway selects the appropriate DAVE protocol version for the media session members.
    2. Group Key Exchange: Members perform a group key exchange using the Messaging Layer Security (MLS) protocol. The Voice Gateway acts as the MLS delivery and authentication service.
    3. Key Extraction: Once the MLS group is established, members export a ratcheted per-sender symmetric media encryption key for every sender in the session.
    4. Media Encryption (Send-side): Using the WebRTC encoded transform API, senders encrypt encoded audio/video frames with their ratcheted symmetric sender key. The encrypted frame is then packetized by WebRTC into RTP packets and sent to the Selective Forwarding Unit (SFU).
    5. Media Decryption (Receive-side): The WebRTC depacketizer reconstructs the E2EE frame from RTP packets. A receive-side frame transformer then uses the sender's specific ratcheted symmetric sender key to decrypt the frame before returning the decoded frame to WebRTC.

    Key Components

    • Voice Gateway: A websocket server that handles RTC signaling, coordination, and acts as the MLS delivery/authentication service.
    • Selective Forwarding Unit (SFU): Relays RTP audio and video traffic between members.
    • MLS (Messaging Layer Security): The underlying group key exchange protocol.
    • WebRTC Encoded Transform API: The interface used to intercept and transform encoded frames for encryption/decryption.
  3. Generate displayable codes for fingerprints

    main

    The protocol uses a variation of Signal's displayable code algorithm to turn byte arrays (like epoch authenticators or pairwise fingerprints) into human-readable strings.

    Algorithm Steps:

    1. Ensure input data length $\ge$ desired code length.
    2. Ensure desired code length is a multiple of the group_size.
    3. Ensure group_size < 8.
    4. For each group:
      • Create an unsigned integer of group_size_bytes from the next chunk of input data (MSB to LSB).
      • Perform modulo 10 ^ group_size on that integer.
      • Pad with leading zeros to reach group_size length.
      • Concatenate to the final string.

    Standard Implementations:

    • Epoch Authenticator: 32-byte input $\rightarrow$ 30-digit code (6 groups of 5 digits).
    • Pairwise Verification Fingerprints: 64-byte input $\rightarrow$ 45-digit code (9 groups of 5 digits).
  4. Codec-Specific Unencrypted Range Handling

    main

    The encrypting frame transformer is codec-aware. It determines which parts of a frame must remain unencrypted so they can pass through WebRTC packetizers/depacketizers.

    Supported Codec Behaviors:

    CodecUnencrypted Range Logic
    OPUSFully encrypted. No metadata required by packetizer.
    VP8If Key Frame (P=0): 10 bytes unencrypted (full header). If non-Key Frame (P=1): 1 byte unencrypted (payload header).
    VP9Fully encrypted. Metadata is handled by the RTP payload descriptor.
    H264/H265Encrypts all VCL (Video Coding Layer) NAL unit payloads. Leaves non-VCL NAL units unencrypted. Also performs a scan to ensure H26X start codes do not appear in ciphertext.
    AV1Iterates OBUs. For each OBU: leaves 1-byte header, 1-byte optional extension, and optional LEB128 size unencrypted. Fully encrypts the OBU payload. Drops specific OBU types: OBU_TEMPORAL_DELIMITER (2), OBU_TILE_LIST (8), and OBU_PADDING (15).
  5. Verify group membership using the Epoch Authenticator

    main

    The Epoch Authenticator is an exported secret from MLS groups used for out-of-band verification. Media session members can use this to ensure their view of the group matches all other members.

    Discord first-party clients display this authenticator using a specific algorithm resulting in a 30-digit code (with a group size of 5). Clients display the authenticator for the latest epoch of the main call and any associated Go Live streams (note that Go Live streams use separate MLS groups).

  6. DAVE Protocol Security Goals and Threat Model

    main

    The DAVE protocol is designed to protect audio and video communications against passive and active eavesdroppers, including insiders (Discord employees/infrastructure maintainers), outsiders (unauthorized network actors), and participants (former or future call members).

    Security Goals

    • Confidentiality: Only active, authorized participants can access call contents. Forward secrecy ensures departed participants cannot access future communications, and backward secrecy ensures new participants cannot access prior communications.
    • Integrity: Prevents non-participants from tampering with, forging, or replaying encrypted calls.
    • Authenticity: Ensures participants can identify each other and trust they are communicating with expected parties.

    Explicit Limitations

    • Metadata Disclosure: Metadata (call existence, participants, duration, etc.) remains visible to insiders and outsiders.
    • Software/Device Compromise: The protocol cannot protect against vulnerabilities in Discord's software or a compromise of a participant's underlying device (e.g., credential theft or code execution).
    • Denial of Service: The protocol does not guarantee availability; insider adversaries can still deny service to specific users.
  7. Identify valid DAVE protocol frames

    main

    To be considered a valid protocol frame for decryption, an incoming frame must satisfy several criteria. If a frame fails these checks, it will not be processed. In 'passthrough mode', only frames that fail this check (or are specific silence packets) are passed through untransformed.

    Criteria for a protocol frame:

    • Minimum Size: Must be large enough to contain the minimum expected protocol supplemental data.
    • Magic Marker: Must contain the magic marker bytes 0xFAFA in the expected position.
    • Supplemental Data Size:
      • Must be larger than the minimum protocol supplemental data size.
      • Must be smaller than the total size of the frame.
    • Nonce: Must contain a ULEB128 encoded nonce.
    • Unencrypted Ranges: Must contain valid ULEB128 encoded unencrypted ranges that are:
      • Ordered by ascending range offset.
      • Distinct and non-overlapping.
      • Not overflowing the total size of the interleaved media frame.

    Note on Magic Markers: For video frames spanning multiple packets, only the last packet of the protocol frame includes the magic marker. If the SFU drops this last packet, the receiver cannot reconstruct the frame.

  8. Ensure identity keypair consistency across connections

    main

    To provide a seamless verification experience, clients must use the same ephemeral or persistent keypair for all active voice gateway connections (e.g., a specific voice channel and any associated Go Live streams within that channel).

    If a member presents more than one identity public key across active voice gateway connections, first-party clients will display them and their calls as unverified.

  9. Handle media key rotation and nonce wrap-around

    main

    To prevent nonce/key collisions, DAVE implements media key rotation via the sender key ratchet.

    Rotation Triggers:

    1. Epoch Changes: A new epoch generates a new sender_base_secret, resetting the nonce to 0 and the generation to 0.
    2. Long-lived Epochs (Nonce Exhaustion): When the most-significant byte of the nonce changes (after $2^{24}$ frames), the sender must ratchet the media key.

    Handling Edge Cases:

    • Nonce Wrap-around: In extremely long-lived epochs, the 32-bit nonce may wrap around. Senders and receivers must handle this and continue incrementing the generation.
    • Out-of-order Frames: To support decryption of out-of-order frames, the key ratchet must retain keys for previous generations for up to ten seconds before erasing them.
  10. Understand the DAVE Payload Format

    main

    The DAVE protocol uses an interleaved media frame format to allow unencrypted metadata to pass through WebRTC packetizers/depacketizers while encrypting the actual media.

    Payload Structure:

    1. Interleaved protocol media frame (variable): Contains the actual media data. Some parts are unencrypted (plaintext) and some are encrypted (ciphertext). The unencrypted ranges are defined in the footer.
    2. Truncated 8-byte AES-GCM authentication tag: A 64-bit tag used for integrity.
    3. Truncated ULEB128 synchronization nonce (variable): A compressed nonce.
    4. Unencrypted range ULEB128 offset/length pairs (variable): Defines the locations and sizes of the plaintext segments.
    5. Protocol supplemental data size (1 byte): Size of the footer.
    6. Magic Marker (2 bytes): The constant 0xFAFA.
    /* Payload Layout Diagram */
    // 0                   1                   2                   3
    // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
    // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    // /                                                               /
    // +            Interleaved protocol media frame (variable)        +
    // /                                                               /
    // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    // |                                                               |
    // +          Truncated 8-byte AES-GCM authentication tag          |
    // |                                                               |
    // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    // /       Truncated ULEB128 synchronization nonce (variable)      /
    // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    // /    Unencrypted range ULEB128 offset/length pairs (variable)   /
    // +               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    // /               |  Suppl. Size  |      Magic Marker 0xFAFA      |
    // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  11. Manage E2EE upgrades and downgrades (Initial Transitory Phase)

    main

    During the transition period where E2EE is not yet mandatory, sessions may switch between transport-only encryption and E2EE.

    Upgrade (Transport-only $\rightarrow$ E2EE)

    When the participant list changes to include only DAVE-supporting clients, the gateway announces a protocol change via dave_protocol_prepare_epoch (opcode 24) and initiates MLS group creation.

    Downgrade (E2EE $\rightarrow$ Transport-only)

    When a non-supporting client joins:

    1. The gateway broadcasts dave_protocol_prepare_transition (opcode 21) to announce a transition to protocol version 0.
    2. Clients enable Passthrough Mode on receive-side frame transforms and report readiness via dave_protocol_ready_for_transition (opcode 23).
    3. Upon dave_protocol_execute_transition (opcode 22), clients immediately switch send-side transforms to passthrough mode.

    Passthrough Mode

    In non-E2EE sessions or during transitions, WebRTC encoded transforms use a passthrough mode. This allows media frames to pass to WebRTC without modification. Only frames that fail the protocol frame check are passed through.

  12. Configure the MLS Delivery Service (Voice Gateway)

    main

    The Discord voice gateway acts as the MLS delivery service. It manages the current epoch, group members, and leaf node indexes.

    External Sender Requirements:

    • The gateway must be added as an external_sender using the MLS group extension external_senders.
    • Before initial group negotiation or adding new members, the gateway must send its credential and signature public key to all members via dave_mls_external_sender_package (opcode 25).
    • Security Requirement: New members must verify there is exactly one external sender with a credential/signature public key matching what was received from the gateway.

    Proposal Handling:

    • Only Add and Remove proposals sent by the gateway's external sender are permitted.
    • Proposals are broadcast via dave_mls_proposals (opcode 27).
    • Clients must reject any proposal that is not an allowed type or is not from the expected external sender.