Skip to content
Tutorials Center
My learning

Topics

Lesson 30 of 36 ยท Security and Applications

WebRTC Security: DTLS, SRTP and Certificate Fingerprints

See how WebRTC encrypts everything by default: the DTLS handshake, SRTP media keys, SDP certificate fingerprints, what a signalling attacker can do, and how to verify peers.

Every WebRTC byte is encrypted: audio, video and data channels. This is not an option you enable; browsers refuse to send media any other way. That is a big reason WebRTC can be used for private calls on ordinary networks. But "encrypted" does not mean "safe against everything", and understanding exactly what is protected and by whom helps you avoid real mistakes.

In this lesson you will follow the handshake step by step, find the certificate fingerprint in an SDP offer, and learn the one part of WebRTC security that is left to your application: trusting the signalling channel.

The pieces

  • DTLS (Datagram TLS): TLS adapted to UDP. Each peer proves it holds a private key and both derive shared secrets. It also secures data channels (via SCTP).
  • SRTP (Secure RTP): the encrypted form of RTP that carries audio and video. Its keys come out of the DTLS handshake (this is called DTLS-SRTP).
  • ICE finds the network path; it does not encrypt.
  • SDP fingerprints: a hash of each peer's DTLS certificate, exchanged through signalling so the handshake can be checked.
sequenceDiagram
  participant A as Peer A
  participant S as Signalling server
  participant B as Peer B
  A->>S: Offer (contains a=fingerprint of A's certificate)
  S->>B: Offer
  B->>S: Answer (contains a=fingerprint of B's certificate)
  S->>A: Answer
  A->>B: DTLS handshake over the ICE path
  Note over A,B: each side checks the other's certificate against the fingerprint from the SDP
  A->>B: SRTP and data channel traffic, keys from DTLS

The signalling channel carries the promise (fingerprints); DTLS proves it.

Certificates are self-signed

Browsers generate a self-signed certificate for each RTCPeerConnection (or you provide one). It is not issued by a certificate authority, because there is nobody to ask. Trust comes instead from the fingerprint in the SDP: if the certificate presented during DTLS does not hash to the fingerprint you received in signalling, the handshake fails.

Look at it in code. The offer contains the line a=fingerprint:sha-256 ..., and the certificate object exposes the same value.

JS Find the fingerprint in the SDP

Press Run (or Ctrl + Enter) to see the console output here.

No output.

a=setup:actpass means "I can act as either DTLS client or server"; the answer picks one (usually active). The roles only decide who sends the first handshake message.

Because certificates can be reused, you can also keep one in IndexedDB and pass it to several connections, which makes the fingerprint stable. Most apps just let the browser generate a new one each time.

What an attacker can and cannot do

The handshake is only as trustworthy as the fingerprints you received. They come through your signalling channel. Consider the cases:

Attacker position Can read media? Why
On the network path (Wi-Fi sniffer, ISP) No Media is encrypted with keys from DTLS
Running a TURN server No It forwards encrypted packets only
Running an SFU Yes, in plain SFU mode The SFU terminates DTLS-SRTP with each client, so it sees decrypted media
Controlling the signalling server Yes, by substituting fingerprints A man in the middle can replace fingerprints and relay both calls

That last row is the important one. WebRTC's encryption protects you from the network, but it cannot tell whether the signalling server is honest. If you need protection from your own server, you need extra measures:

  • Verify fingerprints out of band. Both users read a short code derived from the two fingerprints and compare it by voice (like Signal's safety numbers).
  • Use identity assertions from a third-party identity provider (RTCPeerConnection identity API; limited support).
  • End-to-end encryption through an SFU with insertable streams: the browsers encrypt frames before sending, so the SFU forwards ciphertext (see WebRTC in Real Apps).
JS Compare fingerprints out of band

Press Run (or Ctrl + Enter) to see the console output here.

No output.

If the two people read out different six-digit codes, somebody tampered with the fingerprints in transit.

Other security properties worth knowing

  • Secure context. getUserMedia and most WebRTC features require HTTPS (or localhost). Do not serve a call page over plain HTTP.
  • Signalling must be protected too. Use wss:// and authenticate users, so strangers cannot join rooms or inject messages.
  • Authenticate TURN usage with short-lived credentials (TURN Servers).
  • Treat data channel messages as untrusted input. A peer is another program. Validate sizes and shapes, never evaluate received text, never insert it into HTML.
  • Limit what peers can request, for example max message size and maximum number of channels.
  • Rotate certificates. Browser certificates last about 30 days by default; do not pin them for long.

Common mistakes

  • Believing the SFU cannot see your media. It can, unless you add end-to-end encryption.
  • An unauthenticated signalling server. Anyone who guesses a room name joins your call.
  • Logging SDP with fingerprints and credentials into public analytics.
  • Rendering received data as HTML. That is a cross-site scripting hole.
  • Assuming a lock icon means identity. DTLS proves "the same key as announced", not who the person is.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Where does the SRTP key material come from?

    DTLS-SRTP derives the SRTP keys from the DTLS handshake, so they never travel through signalling.
  2. 2. What is the purpose of a=fingerprint in the SDP?

    The fingerprint is a hash of the DTLS certificate; the handshake fails if the presented certificate does not match.
  3. 3. Which party can see decrypted media in a plain SFU deployment?

    Each client has its own encrypted session with the SFU, which therefore handles plain media unless end-to-end encryption is added.
  4. 4. How can users detect a malicious signalling server swapping fingerprints?

    If both sides derive the same code from the real fingerprints, matching codes prove no substitution happened.

Summary

  • WebRTC always encrypts: DTLS for the handshake and data channels, SRTP for media.
  • Certificates are self-signed; the SDP fingerprint is what ties them to the signalling exchange.
  • Networks and TURN servers cannot read media; an SFU can unless you add end-to-end encryption.
  • A dishonest signalling server can swap fingerprints, so authenticate it, use wss://, and verify codes when it matters.
  • Validate every message you receive from a peer.

Next: Privacy, Permissions and IP Leaks