WebRTC: Difference between revisions

From VoIPmonitor.org
Jump to navigation Jump to search
No edit summary
 
Line 1: Line 1:
VoIPmonitor sniffer is able to analyse SIP over WebSocket encrypted or unencrypted. For unencrypted WebSocket just configure WebScoket port as sipport:  
{{DISPLAYTITLE:Monitoring Encrypted WebRTC (WSS/DTLS-SRTP)}}


voipmonitor.conf:
'''This guide provides a complete, step-by-step tutorial for configuring Asterisk to support secure WebRTC clients and enabling VoIPmonitor to capture and decrypt the associated SIP over Secure WebSocket (WSS) and SRTP traffic.'''
sipport = 5060, 8088


this example will analyse SIP TCP/UDP and SIP over WebSocket on port 8088
== Overview ==
WebRTC (Web Real-Time Communication) requires encrypted transport for both signaling and media. This is achieved using:
*'''WSS (Secure WebSocket):''' For the SIP signaling, encrypting it with TLS.
*'''DTLS-SRTP:''' For the media (RTP) stream, encrypting it with DTLS negotiation to establish SRTP keys.


For encrypted webscoket see following examples for Freeswitch and Asterisk:
VoIPmonitor can sniff and decrypt both layers, provided it has access to the private TLS key used by the PBX. This guide will walk through the full setup for Asterisk.


= Freeswitch =  
== Part 1: Configuring VoIPmonitor to Decrypt TLS ==
First, ensure your sensor is configured to decrypt TLS traffic. In `/etc/voipmonitor.conf`, you must enable the SSL module and provide the path to the same private key your PBX will use.


== vars.conf ==
<pre>
<param name="tls-version" value="tlsv1.2"/>  
# /etc/voipmonitor.conf
<param name="tls-ciphers" value="AES128-SHA" >


== voipmonitor.conf ==
ssl = yes
ssl = yes
ssl_ipport = 192.168.0.1 : 7443 /etc/voipmonitor/privkey.pem


= Asterisk =
# Point to the private key used by your PBX.
# Format: <IP of PBX> : <WSS Port> /path/to/private.key
#
# Example for this guide:
ssl_ipport = 192.168.2.107 : 8089 /etc/asterisk/keys/asterisk.pem
</pre>
''Note: This configuration is also applicable for FreeSWITCH. You would just need to point to the key file used by FreeSWITCH.''


== http.conf ==
== Part 2: Configuring Asterisk for Secure WebRTC ==
This section details the full configuration for Asterisk, from generating keys to setting up PJSIP endpoints.


;
=== Step 1: Generate TLS Certificates ===
; Asterisk Builtin mini-HTTP server
First, we need to create a Certificate Authority (CA) and a server certificate that Asterisk will use for its HTTPS and WSS interfaces.
;
;
[general]
enabled=yes
bindaddr=0.0.0.0
bindport=8088
;prefix=asterisk
;sessionlimit=100
;enablestatic=yes
;redirect = / /static/config/index.html
tlsenable=yes          ; enable tls - default no.
tlsbindaddr=0.0.0.0:8089    ; address and port to bind to - default is bindaddr and port 8089.
tlscertfile=/etc/asterisk/keys/asterisk.pem  ; path to the certificate file (*.pem) only.
tlscipher=AES128-SHA
;tlsprivatekey=</path/to/private.pem>    ; path to private key file (*.pem) only.


== rtp.conf ==
<pre>
# Create a directory for your keys
mkdir -p /etc/asterisk/keys
cd /etc/asterisk/keys


add at the end of this file:
# 1. Create a private key for your local Certificate Authority (CA)
openssl genrsa -des3 -out ca.key 4096


icesupport=yes
# 2. Create a root CA certificate
stunaddr=stun.l.google.com:19302
openssl req -new -x509 -days 3650 -key ca.key -out ca.crt


== pjsip.conf ==
# 3. Create a private key for the Asterisk server
openssl genrsa -out key.pem 2048


[general]
# 4. Create a certificate signing request (CSR) for the Asterisk server
allowguest = no
openssl req -new -key key.pem -out req-sip_server.csr
  [global]
type = global
user_agent = VoIPsun PBX
realm=192.168.2.107
bindport=5060
transport=udp,ws,wss


[transport-udp]
# 5. Sign the server certificate with your CA
type = transport
openssl x509 -req -days 3650 -in req-sip_server.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out cert-sip_server.crt
protocol = udp
bind = 192.168.2.107:5060
tos = cs3
cos = 3


[transport-ws]
# 6. Combine the private key and signed certificate into a single .pem file for Asterisk
type=transport
cat key.pem > asterisk.pem
protocol=ws
cat cert-sip_server.crt >> asterisk.pem
bind=192.168.2.107
</pre>


[transport-wss]
=== Step 2: Configure Asterisk's HTTP Server for WSS ===
type=transport
Edit `/etc/asterisk/http.conf` to enable the built-in web server and activate TLS for the WebSocket transport.
protocol=wss
bind=192.168.2.107
cipher=0x002f
method=tlsv1_2
  [101]
type=aor
max_contacts=1
remove_existing=yes


<pre>
; /etc/asterisk/http.conf


[101]
[general]
type=auth
enabled = yes
auth_type=userpass
bindaddr = 0.0.0.0
username=101
bindport = 8088 ; Port for unencrypted WS
password=1234


[101]
tlsenable = yes
type=endpoint
tlsbindaddr = 0.0.0.0:8089 ; Port for encrypted WSS
disallow=all
tlscertfile = /etc/asterisk/keys/asterisk.pem
allow=opus
tlscipher = AES128-SHA
allow=alaw
</pre>
allow=ulaw
context=from101
auth=101
aors=101
media_encryption=dtls
dtls_verify=fingerprint
dtls_cert_file=/etc/asterisk/keys/asterisk.pem
dtls_ca_file=/etc/asterisk/keys/ca.crt
dtls_setup=actpass
use_avpf=yes
ice_support=yes
media_use_received_transport=yes
rtcp_mux=yes


[102]
=== Step 3: Configure RTP Settings ===
type=aor
Edit `/etc/asterisk/rtp.conf` and ensure ICE support is enabled, which is essential for WebRTC clients to traverse NAT.
max_contacts=1
remove_existing=yes


[102]
<pre>
type=auth
; /etc/asterisk/rtp.conf
auth_type=userpass
username=102
password=1234


[102]
[general]
type=endpoint
icesupport = yes
disallow=all
; You can optionally configure a public STUN server
allow=opus
; stunaddr = stun.l.google.com:19302
allow=alaw
</pre>
allow=ulaw
context=from102
auth=102
aors=102
media_encryption=dtls
dtls_verify=fingerprint
dtls_cert_file=/etc/asterisk/keys/asterisk.pem
dtls_ca_file=/etc/asterisk/keys/ca.crt
dtls_setup=actpass
use_avpf=yes
ice_support=yes
media_use_received_transport=yes
rtcp_mux=yes


== extensions.conf ==
=== Step 4: Configure PJSIP for WebRTC ===
[from101] exten => _X.,1,NooP(Call from 101 to ${EXTEN}) same => n,Dial(PJSIP/102/${EXTEN})
This is the core configuration. We will set up UDP, WS, and WSS transports, and then create endpoints that require DTLS encryption.
exten => i,1,Goto(other,${EXTEN},1)
 
[from102]
;First, disable the old chan_sip module in `/etc/asterisk/modules.conf` to avoid conflicts:
exten => _X.,1,NooP(Call from 102 to ${EXTEN})
<pre>
same => n,Dial(PJSIP/101/${EXTEN})
; /etc/asterisk/modules.conf
noload => chan_sip.so
exten => i,1,Goto(other,${EXTEN},1)
</pre>
[other]
exten => X,1,NooP(Call from ${CALLERID(num)} to ${EXTEN})
same => n,DumpChan()
same => n,Ringing()
same => n,Wait(3)
same => n,Playback(/var/lib/asterisk/sounds/cz/queue-periodic-announce)
same => n,Hangup()


== modules.conf ==
;Next, configure `/etc/asterisk/pjsip.conf`:
noload => chan_sip.so
<pre>
; /etc/asterisk/pjsip.conf


== keys ==
[global]
type = global
user_agent = MyAsteriskPBX
realm = 192.168.2.107 ; Use your Asterisk server's IP or domain


mkdir /etc/asterisk/keys
; --- Transports ---
cd /etc/asterisk/keys
[transport-udp]
openssl genrsa -des3 -out ca.key 4096
type = transport
openssl req -new -x509 -days 365 -key ca.key -out ca.crt
protocol = udp
openssl genrsa -out key.pem 1024
bind = 0.0.0.0:5060
openssl req -new -key key.pem -out req-sip_server.csr
openssl x509 -req -days 365 -in req-sip_server.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out cert-sip_server.crt
cat key.pem > asterisk.pem
cat cert-sip_server.crt >> asterisk.pem


= Sipml5 =
[transport-ws]
type = transport
protocol = ws
bind = 0.0.0.0:8088


[transport-wss]
type = transport
protocol = wss
bind = 0.0.0.0:8089


https://www.doubango.org/sipml5/call.htm?svn=170#
; --- WebRTC Endpoint Template ---
; We create a template to avoid repeating settings
[webrtc-endpoint-template](!)
type = endpoint
disallow = all
allow = opus,ulaw,alaw
context = internal-webrtc
auth = webrtc-auth
aors = webrtc-aor


; Require DTLS encryption for media
media_encryption = dtls
dtls_verify = fingerprint
dtls_cert_file = /etc/asterisk/keys/asterisk.pem
dtls_ca_file = /etc/asterisk/keys/ca.crt
dtls_setup = actpass
use_avpf = yes
ice_support = yes
media_use_received_transport = yes
rtcp_mux = yes


; --- Define Users (101 and 102) ---
[101](webrtc-endpoint-template) ; Inherits from the template
[webrtc-auth](+)
type = auth
auth_type = userpass
username = 101
password = your_strong_password_101
[webrtc-aor](+)
type = aor
max_contacts = 1


Display name: 102  
[102](webrtc-endpoint-template) ; Inherits from the template
Private Identity: 102  
[webrtc-auth](+)
Public Identity: sip:102@192.168.2.107
type = auth
Password: 1234Realm: 192.168.2.107
auth_type = userpass
username = 102
password = your_strong_password_102
[webrtc-aor](+)
type = aor
max_contacts = 1
</pre>


=== Step 5: Create a Basic Dialplan ===
Edit `/etc/asterisk/extensions.conf` to allow the two users to call each other.


<pre>
; /etc/asterisk/extensions.conf


click on expert mode:
[internal-webrtc]
exten => 101,1,NoOp(Call to 101)
same => n,Dial(PJSIP/101)
same => n,Hangup()
 
exten => 102,1,NoOp(Call to 102)
same => n,Dial(PJSIP/102)
same => n,Hangup()
</pre>


== Part 3: Configuring the WebRTC Client (sipML5) ==
Now, configure your WebRTC softphone to connect to Asterisk. This example uses the popular [https://www.doubango.org/sipml5/call.htm sipML5 online client].


Disable video: on
=== Step 1: Basic Settings ===
Enable RTCWeb breaker
Enter your user credentials on the main registration screen.
WebSocket Server URL: wss://192.168.2.107:8089/ws
* '''Display Name:''' `101`
ICE servers: [{ url: 'stun:stun.l.google.com:19302'}]  (this can be maybe empty)
* '''Private Identity:''' `101`
Disable 3GPP Early IMS: on
* '''Public Identity:''' `sip:101@192.168.2.107`
Disable debug messages: on
* '''Password:''' `your_strong_password_101`
Cache media stream: on
* '''Realm:''' `192.168.2.107`
Disable Call button options: on


=== Step 2: Expert Mode Settings ===
Click "Expert Mode" and configure the following:
* '''Disable Video:''' Checked (unless you need video).
* '''Enable RTCWeb Breaker:''' Checked.
* '''WebSocket Server URL:''' `wss://192.168.2.107:8089/ws` (Note the '''wss://''' prefix and the correct port).
* '''ICE Servers:''' `[]` (Leave empty or use `[{ "url": "stun:stun.l.google.com:19302" }]`)
* '''Disable 3GPP Early IMS:''' Checked.


=== Step 3: Trust the Certificate ===
Before attempting to register, you '''must''' open a new browser tab and navigate to `https://192.168.2.107:8089/ws`. Your browser will show a security warning because the certificate is self-signed. You must accept the risk and proceed. This action adds a temporary security exception, allowing the WebSocket connection to be established.


* after settings go back to first tab and click login
After completing these steps, you can return to the sipML5 tab and click "Login". Your client should register successfully, and calls will be encrypted and monitored by VoIPmonitor.


* open https://192.168.2.107:8089/ws  in browser and accept the certificate - otherwise the webrtc will not login.
== AI Summary for RAG ==
'''Summary:''' This guide provides a comprehensive tutorial on configuring VoIPmonitor to sniff encrypted WebRTC traffic, specifically SIP over Secure WebSockets (WSS) and DTLS-SRTP. It details the full setup process for an Asterisk PBX. Part 1 explains how to configure VoIPmonitor itself by enabling `ssl` and setting `ssl_ipport` with the correct private key. Part 2 provides a detailed, step-by-step guide for Asterisk, including: generating a self-signed CA and server certificate using OpenSSL; configuring Asterisk's HTTP server for WSS in `http.conf`; enabling ICE support in `rtp.conf`; and setting up PJSIP transports (`wss`) and endpoints with mandatory DTLS media encryption. Part 3 concludes with instructions for configuring a WebRTC client (sipML5) to connect to the secure Asterisk setup, emphasizing the need to manually trust the self-signed certificate in the browser.
'''Keywords:''' webrtc, wss, secure websocket, dtls, srtp, encrypted, tls, ssl, asterisk, pjsip, http.conf, rtp.conf, sipml5, freeeswitch, decryption, `ssl_ipport`, openssl, certificate, self-signed
'''Key Questions:'''
* How can I monitor encrypted WebRTC calls?
* How do I configure VoIPmonitor to decrypt WSS and DTLS-SRTP traffic?
* What Asterisk configuration is needed for secure WebRTC?
* How do I set up a PJSIP endpoint for a WebRTC client?
* How do I generate a self-signed certificate for Asterisk?
* Why is my WebRTC client not connecting over WSS?
* What is the purpose of `dtls_cert_file` in `pjsip.conf`?
* How to configure sipML5 for a secure connection to Asterisk?

Latest revision as of 16:55, 30 June 2025


This guide provides a complete, step-by-step tutorial for configuring Asterisk to support secure WebRTC clients and enabling VoIPmonitor to capture and decrypt the associated SIP over Secure WebSocket (WSS) and SRTP traffic.

Overview

WebRTC (Web Real-Time Communication) requires encrypted transport for both signaling and media. This is achieved using:

  • WSS (Secure WebSocket): For the SIP signaling, encrypting it with TLS.
  • DTLS-SRTP: For the media (RTP) stream, encrypting it with DTLS negotiation to establish SRTP keys.

VoIPmonitor can sniff and decrypt both layers, provided it has access to the private TLS key used by the PBX. This guide will walk through the full setup for Asterisk.

Part 1: Configuring VoIPmonitor to Decrypt TLS

First, ensure your sensor is configured to decrypt TLS traffic. In `/etc/voipmonitor.conf`, you must enable the SSL module and provide the path to the same private key your PBX will use.

# /etc/voipmonitor.conf

ssl = yes

# Point to the private key used by your PBX.
# Format: <IP of PBX> : <WSS Port> /path/to/private.key
#
# Example for this guide:
ssl_ipport = 192.168.2.107 : 8089 /etc/asterisk/keys/asterisk.pem

Note: This configuration is also applicable for FreeSWITCH. You would just need to point to the key file used by FreeSWITCH.

Part 2: Configuring Asterisk for Secure WebRTC

This section details the full configuration for Asterisk, from generating keys to setting up PJSIP endpoints.

Step 1: Generate TLS Certificates

First, we need to create a Certificate Authority (CA) and a server certificate that Asterisk will use for its HTTPS and WSS interfaces.

# Create a directory for your keys
mkdir -p /etc/asterisk/keys
cd /etc/asterisk/keys

# 1. Create a private key for your local Certificate Authority (CA)
openssl genrsa -des3 -out ca.key 4096

# 2. Create a root CA certificate
openssl req -new -x509 -days 3650 -key ca.key -out ca.crt

# 3. Create a private key for the Asterisk server
openssl genrsa -out key.pem 2048

# 4. Create a certificate signing request (CSR) for the Asterisk server
openssl req -new -key key.pem -out req-sip_server.csr

# 5. Sign the server certificate with your CA
openssl x509 -req -days 3650 -in req-sip_server.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out cert-sip_server.crt

# 6. Combine the private key and signed certificate into a single .pem file for Asterisk
cat key.pem > asterisk.pem
cat cert-sip_server.crt >> asterisk.pem

Step 2: Configure Asterisk's HTTP Server for WSS

Edit `/etc/asterisk/http.conf` to enable the built-in web server and activate TLS for the WebSocket transport.

; /etc/asterisk/http.conf

[general]
enabled = yes
bindaddr = 0.0.0.0
bindport = 8088 ; Port for unencrypted WS

tlsenable = yes
tlsbindaddr = 0.0.0.0:8089 ; Port for encrypted WSS
tlscertfile = /etc/asterisk/keys/asterisk.pem
tlscipher = AES128-SHA

Step 3: Configure RTP Settings

Edit `/etc/asterisk/rtp.conf` and ensure ICE support is enabled, which is essential for WebRTC clients to traverse NAT.

; /etc/asterisk/rtp.conf

[general]
icesupport = yes
; You can optionally configure a public STUN server
; stunaddr = stun.l.google.com:19302

Step 4: Configure PJSIP for WebRTC

This is the core configuration. We will set up UDP, WS, and WSS transports, and then create endpoints that require DTLS encryption.

First, disable the old chan_sip module in `/etc/asterisk/modules.conf` to avoid conflicts
; /etc/asterisk/modules.conf
noload => chan_sip.so
Next, configure `/etc/asterisk/pjsip.conf`
; /etc/asterisk/pjsip.conf

[global]
type = global
user_agent = MyAsteriskPBX
realm = 192.168.2.107 ; Use your Asterisk server's IP or domain

; --- Transports ---
[transport-udp]
type = transport
protocol = udp
bind = 0.0.0.0:5060

[transport-ws]
type = transport
protocol = ws
bind = 0.0.0.0:8088

[transport-wss]
type = transport
protocol = wss
bind = 0.0.0.0:8089

; --- WebRTC Endpoint Template ---
; We create a template to avoid repeating settings
[webrtc-endpoint-template](!)
type = endpoint
disallow = all
allow = opus,ulaw,alaw
context = internal-webrtc
auth = webrtc-auth
aors = webrtc-aor

; Require DTLS encryption for media
media_encryption = dtls
dtls_verify = fingerprint
dtls_cert_file = /etc/asterisk/keys/asterisk.pem
dtls_ca_file = /etc/asterisk/keys/ca.crt
dtls_setup = actpass
use_avpf = yes
ice_support = yes
media_use_received_transport = yes
rtcp_mux = yes

; --- Define Users (101 and 102) ---
[101](webrtc-endpoint-template) ; Inherits from the template
[webrtc-auth](+)
type = auth
auth_type = userpass
username = 101
password = your_strong_password_101
[webrtc-aor](+)
type = aor
max_contacts = 1

[102](webrtc-endpoint-template) ; Inherits from the template
[webrtc-auth](+)
type = auth
auth_type = userpass
username = 102
password = your_strong_password_102
[webrtc-aor](+)
type = aor
max_contacts = 1

Step 5: Create a Basic Dialplan

Edit `/etc/asterisk/extensions.conf` to allow the two users to call each other.

; /etc/asterisk/extensions.conf

[internal-webrtc]
exten => 101,1,NoOp(Call to 101)
 same => n,Dial(PJSIP/101)
 same => n,Hangup()

exten => 102,1,NoOp(Call to 102)
 same => n,Dial(PJSIP/102)
 same => n,Hangup()

Part 3: Configuring the WebRTC Client (sipML5)

Now, configure your WebRTC softphone to connect to Asterisk. This example uses the popular sipML5 online client.

Step 1: Basic Settings

Enter your user credentials on the main registration screen.

  • Display Name: `101`
  • Private Identity: `101`
  • Public Identity: `sip:101@192.168.2.107`
  • Password: `your_strong_password_101`
  • Realm: `192.168.2.107`

Step 2: Expert Mode Settings

Click "Expert Mode" and configure the following:

  • Disable Video: Checked (unless you need video).
  • Enable RTCWeb Breaker: Checked.
  • WebSocket Server URL: `wss://192.168.2.107:8089/ws` (Note the wss:// prefix and the correct port).
  • ICE Servers: `[]` (Leave empty or use `[{ "url": "stun:stun.l.google.com:19302" }]`)
  • Disable 3GPP Early IMS: Checked.

Step 3: Trust the Certificate

Before attempting to register, you must open a new browser tab and navigate to `https://192.168.2.107:8089/ws`. Your browser will show a security warning because the certificate is self-signed. You must accept the risk and proceed. This action adds a temporary security exception, allowing the WebSocket connection to be established.

After completing these steps, you can return to the sipML5 tab and click "Login". Your client should register successfully, and calls will be encrypted and monitored by VoIPmonitor.

AI Summary for RAG

Summary: This guide provides a comprehensive tutorial on configuring VoIPmonitor to sniff encrypted WebRTC traffic, specifically SIP over Secure WebSockets (WSS) and DTLS-SRTP. It details the full setup process for an Asterisk PBX. Part 1 explains how to configure VoIPmonitor itself by enabling `ssl` and setting `ssl_ipport` with the correct private key. Part 2 provides a detailed, step-by-step guide for Asterisk, including: generating a self-signed CA and server certificate using OpenSSL; configuring Asterisk's HTTP server for WSS in `http.conf`; enabling ICE support in `rtp.conf`; and setting up PJSIP transports (`wss`) and endpoints with mandatory DTLS media encryption. Part 3 concludes with instructions for configuring a WebRTC client (sipML5) to connect to the secure Asterisk setup, emphasizing the need to manually trust the self-signed certificate in the browser. Keywords: webrtc, wss, secure websocket, dtls, srtp, encrypted, tls, ssl, asterisk, pjsip, http.conf, rtp.conf, sipml5, freeeswitch, decryption, `ssl_ipport`, openssl, certificate, self-signed Key Questions:

  • How can I monitor encrypted WebRTC calls?
  • How do I configure VoIPmonitor to decrypt WSS and DTLS-SRTP traffic?
  • What Asterisk configuration is needed for secure WebRTC?
  • How do I set up a PJSIP endpoint for a WebRTC client?
  • How do I generate a self-signed certificate for Asterisk?
  • Why is my WebRTC client not connecting over WSS?
  • What is the purpose of `dtls_cert_file` in `pjsip.conf`?
  • How to configure sipML5 for a secure connection to Asterisk?