Skip to content
SIP Mastery

Part 5 · Media / Module 18

SRTP and media security

How the voice itself is protected — SRTP and SRTCP encryption and authentication, worked through with real cryptography; the three ways to agree on keys (SDES in a=crypto, DTLS-SRTP with a=fingerprint and a=setup, and ZRTP) and who can read each; the SRTP profiles and best-effort SRTP; new keys on re-INVITE; and SRTP to RTP at an SBC.

AdvancedNOC coreDEV core

After this module, you can

  • Explain what SRTP encrypts, what it authenticates, and what stays readable.
  • Follow an RTP packet through SRTP key derivation, encryption, and authentication.
  • Compare SDES, DTLS-SRTP, and ZRTP, and say who on the path can read the keys in each.
  • Read a=crypto, a=fingerprint, and a=setup, and predict the DTLS roles.
  • Choose between RTP/SAVP, UDP/TLS/RTP/SAVP, and best-effort SRTP for a peer.
  • Explain what changes on a re-INVITE, and what an SBC does when one leg uses SRTP and the other RTP.
On this page6 sections
  1. 18.1SRTP and SRTCP: encryption and authentication
  2. 18.2Key exchange: SDES, DTLS-SRTP, ZRTP
  3. SDES: the key in the SDP
  4. DTLS-SRTP: the keys from a handshake on the media path
  5. ZRTP: the keys from the media stream, checked by the users
  6. 18.3Profiles: RTP/SAVP, RTP/SAVPF, and best-effort SRTP
  7. 18.4New keys on re-INVITE; SRTP to RTP at an SBC
  8. Common mistakes
  9. Summary

18.1 SRTP and SRTCP: encryption and authentication

TLS protects SIP (Module 14). It does not protect the voice: RTP is a separate stream, and plain RTP can be recorded by anyone on the path. SRTP (Secure RTP) encrypts the payload of each RTP packet and adds an authentication tag. SRTCP does the same for RTCP.

RFC 3711 §3 · SRTP Framework
“We define SRTP as a profile of RTP.”
Read the section ↗
Part of the packet SRTP Why
RTP header: sequence number, timestamp, SSRC, payload type Readable, but authenticated Routers, SBCs, and the receiver need it before decryption
Payload: the audio Encrypted (AES in counter mode) The secret part
Authentication tag Added at the end: 10 bytes (or 4) Detects any change to the header or payload
RFC 3711 §3.1 · Secure RTP
“The "Encrypted Portion" of an SRTP packet consists of the encryption of the RTP payload (including RTP padding when present) of the equivalent RTP packet.”
Read the section ↗

The two sides never use the 30-byte master key directly. Each derives session keys from it: one to encrypt, one to authenticate, and a salt. Each packet gets its own IV from the salt, the SSRC, and the packet index, so the same audio never encrypts to the same bytes twice. The tool below does the real calculation, with the AES and HMAC of your browser:

SRTP · RFC 3711, real AES and HMAC

From an RTP packet and an a=crypto key to SRTP

  • Readable
  • Encrypted
  • Auth tag
RTP sequence number 26232
  1. 1 · Master key and salt base64 in the SDP, 30 bytes

    key 3d 2d 6e 40 25 5e 78 21 42 6a 75 66 72 39 29 3fsalt 2c 23 35 68 5c 60 3d 26 5d 7b 71 69 50 51
  2. 2 · Session keys AES-CM with labels 0, 1, 2 (§4.3)

    calculating…
  3. 3 · IV for this packet salt ⊕ SSRC ⊕ index (§4.1.1)

    calculating…

    “IV = (k_s * 2^16) XOR (SSRC * 2^64) XOR (i * 2^16)” RFC 3711 §4.1.1 ↗

  4. 4 · The SRTP packet

    calculating…

    The plain payload was ff fd fb fe fc ff fd fb …: G.711 silence. Press Next packet: the same audio encrypts to different bytes, because the IV changes with the sequence number.

Readable: version, payload type 0, sequence number 26232, timestamp, SSRC 0x3a5f12c4, and the packet size and timing. An eavesdropper knows that Alice talks to Bob, with G.711, and when.

Not readable: the 160 bytes of audio. Without the session key, they look like random bytes.

“The "Encrypted Portion" of an SRTP packet consists of the encryption of the RTP payload (including RTP padding when present) of the equivalent RTP packet.” RFC 3711 §3.1 ↗

RFC 3711 §4.2 · Message Authentication and Integrity
“If the two tags are equal, then the message/tag pair is valid; otherwise, it is invalid and the error audit message "AUTHENTICATION FAILURE" MUST be returned.”
Read the section ↗
Crypto-suite Encryption Tag Overhead per packet
AES_CM_128_HMAC_SHA1_80 AES-128 in counter mode HMAC-SHA1, 80 bits 10 bytes
AES_CM_128_HMAC_SHA1_32 AES-128 in counter mode HMAC-SHA1, 32 bits 4 bytes: saves bandwidth on voice
AEAD_AES_128_GCM AES-GCM: encryption and tag in one 16 bytes Newer; common in WebRTC

SRTP does not hide who talks to whom, when, or how much: the IP addresses, the ports, and the RTP header stay visible, and so does the timing of each packet.

RFC 3711 §3 · SRTP Framework
“Secure RTCP (SRTCP) provides the same security services to RTCP as SRTP does to RTP.”
Read the section ↗

18.2 Key exchange: SDES, DTLS-SRTP, ZRTP

SRTP needs both sides to know the keys. There are three common ways to agree on them, and they differ in who else can read the keys.

SDES: the key in the SDP

SDESSDES. SRTP keys sent in the SDP, in a=crypto lines (RFC 4568). Safe only when the SIP travels over TLS. puts the master key and salt in the SDP, base64 encoded, in an a=crypto line. Each side sends its own key, for the media it sends.

m=audio 49170 RTP/SAVP 0 101
a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:WVNfX19zZW1jdGwgKCkgewkyMjA7fQp9CnVubGVz|2^31
a=crypto:2 AES_CM_128_HMAC_SHA1_32 inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^31
        │   │                          │                                        └─ lifetime: packets
        │   │                          └─ master key (16 bytes) + salt (14 bytes)
        │   └─ crypto-suite
        └─ tag: the answer picks one tag
RFC 4568 §7.1.2 · Generating the Initial Answer - Unicast Streams
“For each unicast media line that uses the secure RTP transport and contains one or more "a=crypto" lines in the offer, the answerer MUST either accept one (and only one) of the crypto lines for that media stream, or it MUST reject the media stream.”
Read the section ↗
RFC 4568 §7.1.2 · Generating the Initial Answer - Unicast Streams
“When the answerer accepts an SRTP unicast media stream with a crypto line, the answerer MUST include one or more master keys appropriate for the selected crypto algorithm; the master key(s) included in the answer MUST be different from those in the offer.”
Read the section ↗

Call flow · SDES over TLS

Fixed: SDES keys over TLS

  • SIP
  • RTP media
Alice192.0.2.10Bob203.0.113.2001INVITE (RTP/SAVP)02200 OK (RTP/SAVP)03ACK04SRTP audio
01/04

The offer asks for SRTP and carries two keys in a=crypto: one for each crypto-suite Alice can use.

All steps as text
  1. Alice → Bob: INVITE (RTP/SAVP). The offer asks for SRTP and carries two keys in a=crypto: one for each crypto-suite Alice can use.
  2. Bob → Alice: 200 OK (RTP/SAVP). Bob accepts crypto line 1, and sends his own key for the media he sends.
  3. Alice → Bob: ACK. The call is up.
  4. Alice → Bob: SRTP audio. Each side encrypts with its own key and decrypts with the other. On the path, only the RTP header is readable.

SDES is simple, and most SIP phones and trunks use it. Its weakness: the key is in the SIP message. Anyone who can read the SIP can decrypt the call, so the SIP must travel over TLS. And TLS only protects each hop: every proxy and SBC on the path decrypts the SIP, and can read the key.

RFC 4568 §8.3 · Signaling Authentication and Signaling Encryption
“Failure to encrypt the SDP message containing an inline SRTP master key renders the SRTP authentication or encryption service useless in practically all circumstances.”
Read the section ↗
RFC 4568 §8.3 · Signaling Authentication and Signaling Encryption
“Network or transport security protocols that terminate at each intermediate system, therefore, SHOULD NOT be used for protecting SDP security descriptions.”
Read the section ↗

DTLS-SRTP: the keys from a handshake on the media path

DTLSDTLS. TLS for UDP. DTLS-SRTP runs a DTLS handshake on the media ports to create the SRTP keys.-SRTP moves the key exchange out of SIP. The SDP carries only a fingerprint: the hash of each side’s certificate. Then the two phones run a DTLS handshake on the media ports, check each other’s certificate against the fingerprint, and derive the SRTP keys from the handshake. WebRTC always uses DTLS-SRTP (Module 26).

RFC 5763 §5 · Establishing a Secure Channel
“Note that the entire authentication and key exchange for securing the media traffic is handled in the media path through DTLS. The signaling path is only used to verify the peers' certificate fingerprints.”
Read the section ↗
m=audio 49170 UDP/TLS/RTP/SAVP 0 101
a=setup:actpass
a=fingerprint:sha-256 4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB:3E:4B:65:7D:D1:93:A0:72:CF:1B:9C:0D

a=setup decides who starts the handshake, the DTLS client. The offer says actpass: “either”. The answer chooses: active (I start; recommended, because the handshake can begin while the answer is still on its way) or passive (you start).

RFC 8842 §5.2 · Generating the Initial SDP Offer
“When an offerer sends the initial offer, the offerer MUST insert an SDP "setup" attribute [RFC4145] with an "actpass" attribute value, as well as one or more SDP "fingerprint" attributes according to the procedures in [RFC8122].”
Read the section ↗
RFC 5763 §5 · Establishing a Secure Channel
“setup:active allows the answer and the DTLS handshake to occur in parallel. Thus, setup:active is RECOMMENDED.”
Read the section ↗
Offer Allowed answers (RFC 4145) Who sends the ClientHello
actpass active or passive The side that is active
active passive The offerer
passive active The answerer

Call flow · DTLS-SRTP

DTLS-SRTP: keys from a handshake on the media path

  • SIP
  • RTP media
  • TCP / IP
Alice192.0.2.10Bob203.0.113.2001INVITE (UDP/TLS/RTP/SAVP)02200 OK (setup:active)03ACK04DTLS ClientHello05DTLS ServerHello, Certificate06DTLS Certificate, Finished07SRTP audio
01/07

The offer has no key. It has the fingerprint of Alice's certificate, and a=setup:actpass: Bob chooses the DTLS role.

All steps as text
  1. Alice → Bob: INVITE (UDP/TLS/RTP/SAVP). The offer has no key. It has the fingerprint of Alice's certificate, and a=setup:actpass: Bob chooses the DTLS role.
  2. Bob → Alice: 200 OK (setup:active). Bob answers a=setup:active: he will start the DTLS handshake. His fingerprint is in the answer.
  3. Alice → Bob: ACK. The call is up. The media is not yet secure.
  4. Bob → Alice: DTLS ClientHello. Bob starts the handshake on the media ports, 3456 to 49170. DTLS, not SIP, carries the key exchange.
  5. Alice → Bob: DTLS ServerHello, Certificate. Alice answers with her certificate. Bob checks that its hash matches the fingerprint in her SDP.
  6. Bob → Alice: DTLS Certificate, Finished. Bob sends his certificate; Alice checks it against his fingerprint. Both derive the SRTP keys from the handshake.
  7. Alice → Bob: SRTP audio. The media is SRTP. The keys never appeared in SIP, so a proxy that reads the SDP still cannot decrypt.
RFC 5763 §5 · Establishing a Secure Channel
“The certificate presented during the DTLS handshake MUST match the fingerprint exchanged via the signaling path in the SDP.”
Read the section ↗

A proxy cannot read DTLS-SRTP keys. But an attacker who can change the SDP can replace both fingerprints and sit in the middle of the handshake. The defence is to sign the SDP: an Identity header (STIR, Module 28) covers the fingerprint.

ZRTP: the keys from the media stream, checked by the users

ZRTPZRTP. A key exchange inside the media stream. The callers compare a short code to detect a man in the middle. needs nothing in the SIP or the SDP. The two phones run a Diffie-Hellman exchange inside the media stream. Then each phone shows a short code, such as “alpha bravo”, and the two people read it to each other. A man in the middle would produce two different codes.

RFC 6189 §1 · Introduction
“It uses ephemeral Diffie-Hellman (DH) with hash commitment and allows the detection of man-in-the-middle (MiTM) attacks by displaying a short authentication string (SAS) for the users to read and verbally compare over the phone.”
Read the section ↗
RFC 6189 §1 · Introduction
“It also does not rely on SIP signaling for the key management, and in fact, it does not rely on any servers at all.”
Read the section ↗

ZRTP needs no server and no certificate, but it needs a ZRTP phone at each end, and users who actually compare the code. It is rare outside secure-phone apps.

Compare where the keys travel, and what three kinds of attacker can read:

Key exchange comparison

Where do the SRTP keys travel, and who can read them?

  • SIP
  • Key in clear
  • Key exchange
  • SRTP

Keys travel: In the SDP, in plain text

AliceProxyBobINVITE · a=crypto key AINVITE · a=crypto key A200 OK · a=crypto key B200 OK · a=crypto key BSRTP

Capture view: on the network between Alice and the proxy

  • INVITE (UDP 5060)a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:WVNfX19zZW1j…
  • 200 OK (UDP 5060)a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:PS1uQCVeeCFC…
  • SRTPHeader readable; payload encrypted, but the keys are known
AttackerResultWhy
Eavesdropper on the networkCan decryptReads both keys from the SIP, and decrypts the call.
A proxy or SBC on the pathCan decryptReads the keys.
Attacker who can change the SDPCan decryptReplaces the keys, or removes a=crypto.

“Failure to encrypt the SDP message containing an inline SRTP master key renders the SRTP authentication or encryption service useless in practically all circumstances.” RFC 4568 §8.3 ↗

SDES DTLS-SRTP ZRTP
Keys in The SDP (a=crypto) A DTLS handshake on the media ports A Diffie-Hellman exchange in the media
SDP carries The keys Fingerprints and a=setup Nothing (optionally a hash)
Needs SIP over TLS Certificates (self-signed is fine) ZRTP at both ends; users compare a code
Proxies can read the keys Yes No No
Used by Most SIP phones and trunks WebRTC, newer SIP phones and SBCs Secure-phone apps

18.3 Profiles: RTP/SAVP, RTP/SAVPF, and best-effort SRTP

The m= line says whether the stream is encrypted:

Profile on the m= line Meaning
RTP/AVP Plain RTP
RTP/SAVP SRTP. Keys usually from SDES
RTP/AVPF, RTP/SAVPF The same, with RTCP feedback (Module 17)
UDP/TLS/RTP/SAVP, UDP/TLS/RTP/SAVPF SRTP with keys from DTLS
RFC 5764 §8 · Session Description for RTP/SAVP over DTLS
“When a RTP/SAVP or RTP/SAVPF stream is transported over DTLS with UDP, the token SHALL be UDP/TLS/RTP/SAVP or UDP/TLS/RTP/SAVPF respectively.”
Read the section ↗

An offer of RTP/SAVP requires SRTP: a phone that supports only RTP/AVP has nothing it can accept, and rejects the call with 488 Not Acceptable Here. To encrypt when possible and still reach older phones, many devices send best-effort SRTP: RTP/AVP with a=crypto. A phone that knows SRTP answers with its own a=crypto and both encrypt; a phone that does not ignores the attribute and answers plain RTP.

RTP/SAVP only: 488

RTP/SAVP to a peer without SRTP: 488

  • SIP
Alice192.0.2.10Bob203.0.113.2001INVITE (RTP/SAVP)02488 Not Acceptable Here03ACK
01/03

Alice requires SRTP: her only m= line is RTP/SAVP.

All steps as text
  1. Alice → Bob: INVITE (RTP/SAVP). Alice requires SRTP: her only m= line is RTP/SAVP.
  2. Bob → Alice: 488 Not Acceptable Here. Bob's phone knows only RTP/AVP. It has nothing it can accept, so it rejects the whole call.
  3. Alice → Bob: ACK. Alice acknowledges the 488. The call fails, though both phones can do G.711.
RFC 4568 §6 · SRTP Security Descriptions
“SRTP security descriptions MUST only be used with the SRTP transport (e.g., "RTP/SAVP" or "RTP/SAVPF").”
Read the section ↗

Best-effort SRTP is not in RFC 4568, but it is common. The standard way to offer both is SDP capability negotiation (RFC 5939), which few devices support. Whatever the method, the user should see whether the call is encrypted, because best effort can quietly fall back to plain RTP.

18.4 New keys on re-INVITE; SRTP to RTP at an SBC

re-INVITE with SDES. Each new offer can keep the keys or send new ones; many phones send new keys in every offer. For a moment, the receiver must accept packets with both the old and the new key: SRTP authentication tells it which key a packet uses.

RFC 4568 §7.1.4 · Modifying the Session
“When modifying the session, all negotiated aspects of the SRTP media stream can be modified. For example, a new crypto suite can be used or a new master key can be established.”
Read the section ↗

re-INVITE with DTLS-SRTP. A new offer keeps the same DTLS association, and the same keys, unless something changes it: a new a=tls-id, a new fingerprint, or new addresses (RFC 8842). Then the phones run a new handshake.

SRTP to RTP at an SBC. Many carrier trunks accept only plain RTP. The SBC at the edge then terminates SRTP: it decrypts the media from the phone, and sends plain RTP to the carrier. The SBC is a B2BUA (Module 25), so it can also translate SDES on one side to DTLS-SRTP on the other.

Alice ── SIP/TLS + SRTP (SDES) ──► SBC ── SIP/UDP + RTP ──► Carrier
                                    │
                         decrypts and re-encrypts here
Leg Signaling Media Who can listen
Phone to SBC SIP over TLS, SDES keys SRTP Only the phone and the SBC
SBC to carrier SIP over UDP or TLS RTP or SRTP Anyone on that path, if it is RTP

Media security is hop by hop as soon as an SBC is in the middle: the call is only as private as its least protected leg.

Common mistakes

SDES over SIP without TLS, so the keys are visible on the network

A phone is set to “SRTP: required” but its SIP transport is still UDP. The media is SRTP, the call shows a lock icon, and a capture of RTP shows only encrypted payloads. But the INVITE and the 200 OK carry both keys in a=crypto, in plain text. Anyone who captures the signaling can decrypt every packet with free tools.

Broken

Broken: SDES keys over UDP

  • SIP
  • RTP media
  • ⚠Problem
Alice192.0.2.10Bob203.0.113.2001INVITE (RTP/SAVP)02200 OK (RTP/SAVP)03ACK04SRTP audio⚠
01/04

The same offer, with the keys in a=crypto. But this INVITE goes over UDP: every byte is readable on the network.

All steps as text
  1. Alice → Bob: INVITE (RTP/SAVP). The same offer, with the keys in a=crypto. But this INVITE goes over UDP: every byte is readable on the network.
  2. Bob → Alice: 200 OK (RTP/SAVP). Bob accepts crypto line 1, and sends his own key for the media he sends.
  3. Alice → Bob: ACK. The call is up.
  4. Alice → Bob: SRTP audio. The media is SRTP, but the keys travelled in plain text. Anyone who captured the INVITE and the 200 OK can decrypt the call. Problem: Encrypted media, readable keys: the encryption protects nothing.

Remember: SDES keys are only as secret as the SIP that carries them. Use SIP over TLS (or WSS) on every hop that carries a=crypto, or use DTLS-SRTP, which puts no key in the SDP. Turn on Attacker with the key in the SRTP tool above to see what a captured key gives away.

Offering RTP/SAVP to a peer that supports only RTP/AVP, which gives 488

A company turns on SRTP on its phones, and calls to one supplier start to fail with 488 Not Acceptable Here. The phones offer only m=audio … RTP/SAVP; the supplier’s PBX knows only RTP/AVP, so no stream can be accepted. Internal calls work, which hides the problem until someone calls out.

RTP/SAVP: 488

RTP/SAVP to a peer without SRTP: 488

  • SIP
Alice192.0.2.10Bob203.0.113.2001INVITE (RTP/SAVP)02488 Not Acceptable Here03ACK
01/03

Alice requires SRTP: her only m= line is RTP/SAVP.

All steps as text
  1. Alice → Bob: INVITE (RTP/SAVP). Alice requires SRTP: her only m= line is RTP/SAVP.
  2. Bob → Alice: 488 Not Acceptable Here. Bob's phone knows only RTP/AVP. It has nothing it can accept, so it rejects the whole call.
  3. Alice → Bob: ACK. Alice acknowledges the 488. The call fails, though both phones can do G.711.

Remember: require RTP/SAVP only towards peers that support it. Towards others, offer best-effort SRTP (RTP/AVP with a=crypto) or let the SBC terminate SRTP. A 488 with a Warning header that names the transport is the clue.

Both sides use the same DTLS a=setup role

A phone offers a=setup:active instead of actpass, and the other side, which prefers to be active, also answers active. Both send a DTLS ClientHello; neither answers as a server; the handshake never finishes. The SIP call is connected, but there are no SRTP keys, so there is no audio. The same happens with passive on both sides: each waits for the other.

Broken

Broken: both sides are DTLS active

  • SIP
  • TCP / IP
  • ⚠Problem
Alice192.0.2.10Bob203.0.113.2001INVITE (UDP/TLS/RTP/SAVP)02200 OK (setup:active)03ACK04DTLS ClientHello05DTLS ClientHello⚠
01/05

Alice's offer says a=setup:active: she will start the DTLS handshake herself.

All steps as text
  1. Alice → Bob: INVITE (UDP/TLS/RTP/SAVP). Alice's offer says a=setup:active: she will start the DTLS handshake herself.
  2. Bob → Alice: 200 OK (setup:active). Bob also answers a=setup:active. Both sides now think they start the handshake.
  3. Alice → Bob: ACK. The call is up, but the DTLS roles clash.
  4. Alice → Bob: DTLS ClientHello. Alice starts a handshake as the client.
  5. Bob → Alice: DTLS ClientHello. Bob also starts one as the client. Neither side acts as the server, so neither handshake finishes. Problem: Neither side acts as the DTLS server. No keys, no SRTP: the call is up but silent.
RFC 4145 §4.1 · The Setup Attribute in the Offer/Answer Model
“The offerer states which role or roles it is willing to perform; and the answerer, taking the offerer's willingness into consideration, chooses which roles both endpoints will actually perform during connection establishment.”
Read the section ↗

Remember: an offer for DTLS-SRTP says a=setup:actpass; the answer says active (recommended) or passive, never actpass, and never the same fixed role as the offer. In a capture, two ClientHellos and no ServerHello mean a role clash.

Summary

  • SRTP encrypts the RTP payload with AES and adds an authentication tag (usually 10 bytes). The header stays readable but cannot be changed. SRTCP protects RTCP the same way.
  • Session keys come from a master key and salt; each packet has its own IV, from the salt, the SSRC, and the packet index.
  • SDES sends the keys in a=crypto: simple, but every proxy can read them, and without TLS anyone can. DTLS-SRTP sends only fingerprints and makes the keys in a handshake on the media path; a=setup (actpass in the offer, active or passive in the answer) picks the DTLS client. ZRTP makes the keys in the media and lets the users compare a code.
  • RTP/SAVP requires SRTP and gets 488 from a peer that cannot do it; best-effort SRTP offers RTP/AVP with a=crypto. DTLS-SRTP uses UDP/TLS/RTP/SAVP.
  • A re-INVITE may bring new SDES keys, or a new DTLS handshake. An SBC that terminates SRTP decrypts the media: privacy is only as strong as the weakest leg.