Skip to content

Instantly share code, notes, and snippets.

@bigyan
Forked from paneru-rajan/asterisk_webrtc.md
Created October 17, 2017 09:49
Show Gist options
  • Save bigyan/ce2763cf53a3d3e7d2803e03835b18ad to your computer and use it in GitHub Desktop.
Save bigyan/ce2763cf53a3d3e7d2803e03835b18ad to your computer and use it in GitHub Desktop.
[Configure Asterisk with webrtc support] Setting up asterisk for webrtc #asterisk #webrtc #sipml5 #configuration

Setting up Asterisk for webrtc

To set up with sipml5 I had been through the asterisk offiial site and I do recommand you to visit it.

We need to update several config file which are located on /etc/asterisk. Those filename are listed below

  1. modules.conf
  2. extensions.conf
  3. http.conf
  4. pjsip.conf
  5. rtp.conf

I have posted how these file looks below with breif explaination.

  1. modules.conf: Since we are using pjsip, we need to stop loading sip. As both of them cannot be used simultaneously. You can update manually or use the bash script below:

    sudo sh -c "echo 'noload => chan_sip.so' >> /etc/asterisk/modules.conf"
  2. extension.conf:Add these things to the extension.conf at the end of the file. If you have just installed a fresh copy of asterisk you can even override the existing code.

    I have added two extensions, which are in fact dial plans.

    • Where helloworld just plays the hello-world music when we call in any number
    • Whereas the helloworld2, first plays the hello-world and then calls to another number, it also waits for the dtmf and plays its name based on whether the called number is registered one or not.
    [helloworld]
    exten => _X.,1,NoOp(${EXTEN})
    same => n,Playback(hello-world)
    same => n,Hangup()
    
    [helloworld2]
    exten => _X.,1,NoOp(${EXTEN})
    same => n,Playback(hello-world)
    same => n,Dial(PJSIP/${EXTEN},20)
    same => n,Read(Digits,,)
    same => n,Playback(you-entered)
    same => n,SayNumber(${Digits})
    
  3. http.conf: Please update the file accordingly, or replace if you want.

    [general]
    enabled=yes
    bindaddr=0.0.0.0
    bindport=8088
    tlsenable=yes
    tlsbindaddr=0.0.0.0:8089
    tlscertfile=/etc/asterisk/keys/asterisk.pem
    
  4. pjsip.conf: 199 is for web based phone 3002 and 3001 for sip clients: (like Linphone for desktop and CSipSimle for mobile)

    This file need to have:

    [transport-wss]
    type=transport
    protocol=wss
    bind=0.0.0.0
    
    [199]
    type=endpoint
    aors=199
    auth=199
    use_avpf=yes
    media_encryption=dtls
    dtls_ca_file=/etc/asterisk/keys/ca.crt
    dtls_cert_file=/etc/asterisk/keys/asterisk.pem
    dtls_verify=fingerprint
    dtls_setup=actpass
    ice_support=yes
    media_use_received_transport=yes
    rtcp_mux=yes
    context=helloworld2
    disallow=all
    allow=ulaw
    allow=opus
    
    [199]
    type=auth
    auth_type=userpass
    username=199
    password=199@pass1 
    
    [199]
    type=aor
    max_contacts=1
    remove_existing=yes
    
    
    [transport-udp]
    type=transport
    protocol=udp
    bind=0.0.0.0
    
    [3001]
    type=endpoint
    context=helloworld2
    disallow=all
    allow=ulaw
    auth=3001
    aors=3001
    
    [3001]
    type=auth
    auth_type=userpass
    password=3001pass
    username=3001
    
    [3001]
    type=aor
    max_contacts=1
    remove_existing=yes
    
    [3002]
    type=endpoint
    context=helloworld2
    disallow=all
    allow=ulaw
    auth=3002
    aors=3002
    
    [3002]
    type=auth
    auth_type=userpass
    password=3002pass
    username=3002
    
    [3002]
    type=aor
    max_contacts=1
    remove_existing=yes
    
  5. rtp.conf: Need to have these on rtp.conf.

    [general]
    rtpstart=10000
    rtpend=20000
    icesupport=true
    stunaddr=stun.l.google.com:19302
    

###Create Certificates Call the script as such:

cd /usr/local/src/asterisk-13.17.2/contrib/scripts
sudo ./ast_tls_cert -C pbx.example.com -O "My Super Company" -d /etc/asterisk/keys
  • The "-C" option is used to define our host - DNS name or our IP address.
  • The "-O" option defines our organizational name.
  • The "-d" option is the output directory of the keys.
  1. You'll be asked to enter a pass phrase for /etc/asterisk/keys/ca.key, put in something that you'll remember for later.
  2. This will create the /etc/asterisk/keys/ca.crt file.
  3. You'll be asked to enter the pass phrase again, and then the /etc/asterisk/keys/asterisk.key file will be created.
  4. The /etc/asterisk/keys/asterisk.crt file will be automatically generated.
  5. You'll be asked to enter the pass phrase a third time, and the /etc/asterisk/keys/asterisk.pem, a combination of the asterisk.key and asterisk.crt files, will be created.
  6. You can then check your /etc/asterisk/keys directory to verify the new files were created, as such:
ls -w 1 /etc/asterisk/keys

And you should see:

asterisk.crt
asterisk.csr
asterisk.key
asterisk.pem
ca.cfg
ca.crt
ca.key
tmp.cfg

You can reload the asterisk by:

asterisk -rvvvvvv

or simply typing reload on Asterisk's cli.

To verify the web server is running, perform:

netstat -an | grep 8089

And you should see:

tcp        0      0 0.0.0.0:8089            0.0.0.0:*               LISTEN  

Next, to ensure these modules are loaded by Asterisk, you can perform:

asterisk -rx "module show like crypto"
asterisk -rx "module show like websocket"
asterisk -rx "module show like opus"

You should see something similar to:

# asterisk -rx "module show like crypto"
Module                         Description                              Use Count  Status      Support Level
res_crypto.so                  Cryptographic Digital Signatures         1          Running              core
1 modules loaded

# asterisk -rx "module show like websocket"
Module                         Description                              Use Count  Status      Support Level
res_http_websocket.so          HTTP WebSocket Support                   3          Running          extended
res_pjsip_transport_websocket.so PJSIP WebSocket Transport Support        0          Running              core
2 modules loaded
 
# asterisk -rx "module show like opus"
Module                         Description                              Use Count  Status      Support Level
codec_opus.so                  OPUS Coder/Decoder                       0          Running          extended
res_format_attr_opus.so        Opus Format Attribute Module             1          Running              core
@oxygen
Copy link

oxygen commented Jun 30, 2018

Thank you for publishing this

It works to call 3001 (SIP) from the 199 WebRTC user.

However there is a long pause after placing the call in WebRTC until it gets the HelloWorld message.
Any idea why there is a long pause and what can I do to hurry it up?

Also, I can't place calls from 3001 (SIP) to the 199 WebRTC user, the SIP phone says Unsupported media, I guess SIP negotiation fails?

@abdullahaldouis
Copy link

please help
i enter https://my server ip:8089/wss in browser
Not Found
The requested URL was not found on this server.

@abdullahaldouis
Copy link

[May 27 22:11:10] ERROR[59367]: iostream.c:663 ast_iostream_start_tls: Problem setting up ssl connection: error:00000001:lib(0):func(0):reason(1), Internal SSL error
[May 27 22:11:10] ERROR[59367]: tcptls.c:179 handle_tcptls_connection: Unable to set up ssl connection with peer '192.168.0.169:57313'
[May 27 22:11:10] ERROR[59367]: iostream.c:563 ast_iostream_close: SSL_shutdown() failed: error:00000001:lib(0):func(0):reason(1), Internal SSL error

@RizeKishimaro
Copy link

[May 27 22:11:10] ERROR[59367]: iostream.c:663 ast_iostream_start_tls: Problem setting up ssl connection: error:00000001:lib(0):func(0):reason(1), Internal SSL error [May 27 22:11:10] ERROR[59367]: tcptls.c:179 handle_tcptls_connection: Unable to set up ssl connection with peer '192.168.0.169:57313' [May 27 22:11:10] ERROR[59367]: iostream.c:563 ast_iostream_close: SSL_shutdown() failed: error:00000001:lib(0):func(0):reason(1), Internal SSL error

you should give your self signed certificate to browser you are using

@MusicaFM
Copy link

[27 de mayo 22:11:10] ERROR[59367]: iostream.c:663 ast_iostream_start_tls: Problema al configurar la conexión SSL: error:00000001:lib(0):func(0):reason(1), Error interno de SSL [27 de mayo 22:11:10] ERROR[59367]: tcptls.c:179 handle_tcptls_connection: No se puede configurar la conexión SSL con el peer '192.168.0.169:57313' [27 de mayo 22:11:10] ERROR[59367]: iostream.c:563 ast_iostream_close: SSL_shutdown() falló: error:00000001:lib(0):func(0):reason(1), Error interno de SSL

Debes proporcionar tu certificado autofirmado al navegador que estés utilizando.

¿En Android como importo el certificado?

@RizeKishimaro
Copy link

[27 de mayo 22:11:10] ERROR[59367]: iostream.c:663 ast_iostream_start_tls: Problema al configurar la conexión SSL: error:00000001:lib(0):func(0):reason(1), Error interno de SSL [27 de mayo 22:11:10] ERROR[59367]: tcptls.c:179 handle_tcptls_connection: No se puede configurar la conexión SSL con el peer '192.168.0.169:57313' [27 de mayo 22:11:10] ERROR[59367]: iostream.c:563 ast_iostream_close: SSL_shutdown() falló: error:00000001:lib(0):func(0):reason(1), Error interno de SSL

Debes proporcionar tu certificado autofirmado al navegador que estés utilizando.

¿En Android como importo el certificado?

go to https://yourserverip:8089/ws

you should see the security warning if you used self signed certificate,press Advenced then press Proceed to go yourserverip unsafe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment