Skip to main content
gortsplib supports end-to-end encryption using TLS for the control channel (RTSPS) and SRTP/SRTCP for media packets. Both are enabled by setting a single field on the Server struct.

TLSConfig

Set Server.TLSConfig to a *tls.Config to enable secure mode. When set:
  • The server accepts only TLS connections on RTSPAddress (RTSPS, default port 8322).
  • SRTP/SRTCP is automatically negotiated for media packets on UDP transport.
  • The SDP sent to clients uses the SAVP transport profile instead of AVP.
When TLSConfig is set, TCP transport is encrypted via TLS and UDP transport is encrypted via SRTP/SRTCP. Both are negotiated automatically — no additional configuration is needed.

TLS and SRTP interaction

SRTP key material is generated per stream when ServerStream.Initialize() is called. The keys are exchanged over the TLS-protected RTSP channel using MIKEY, embedded in the SDP. Clients that support SAVP will use these keys to encrypt and decrypt UDP media packets.

Full example

server-secure/main.go

Generating a self-signed certificate

For development and testing you can generate a self-signed certificate with OpenSSL:
This produces server.key (private key) and server.crt (certificate), which you load with tls.LoadX509KeyPair.
Self-signed certificates are suitable for local development only. Clients will reject them unless configured to skip certificate verification. Use a certificate signed by a trusted CA for production deployments.

Connecting to a secure server

Clients connect using the rtsps:// scheme. For example, to test with FFmpeg: