A wee Asterisk self-signed certificate sharing
Tags: asterisk, websocket, webrtc, beginners
Published: 2021-06-04 02:36:20

## Weekly sharing

Hi everyone, I am Ekim, a fresh Bootcamp graduate and an IT helper (I don't dare to call myself a programmer yet). Every Friday, I will share some of the work that I've done over the last week in a bid to get feedbacks from you guys and record my journey to become a programmer. 


### Previously
<a href="https://dev.to/ekim34351855/basic-ivr-with-asterisk-4elj">Basic IVR with Asterisk</a>


### Introduction

Last week, I was doing something related to WebRTC, which was an amazing experience. However, there's one thing I got stuck for a pretty long time related to web socket. It turns out I had to manually permit access for different ports I used even though I had created a self-signed certificate. Today, I would like to share how to create a self-signed certificate on Asterisk and import that into your browser. 



### Create your self-signed certificate

- It is not difficult to create a self-signed certificate. 

```bash
cd /asterisk-18.3.0/contrib/scripts			# go to /contrib/script

# -C = DNS name or our IP address, -O = organizational name, -d = output directory of the keys
# use the same pass phrase you want for the whole registration
sudo ./ast_tls_cert -C <server-ip> -O "<organizational name>" -d /etc/asterisk/keys

# check if the 'keys' file exists
ls -w 1 /etc/asterisk/keys

sudo service asterisk restart
```



### Import your certificate to let waive manual permission access

- Now, we are going to import our `ca.crt` into our browser. I will use Firefox and Chrome as examples. 
- You may wonder why you need to import the certificate. The reason is that once you import your certificate, you don't need to permit access for browser to go to your web every time. 
- More importantly, when you play around with WebRTC, you need to enable the web socket every time if you don't do so, which is absolutely annoying. 



#### Firefox browser set-up

If you are using **Firefox browser**, please:

- `Go to "Options"`

   <img src="https://drive.google.com/uc?export=view&id=1saVuuyxWjG6bzpWkec2GeITZjs6rPgUT" alt="microsip-set-up" style="zoom: 65%;" />

- `Select "Privacy & Security" `

   <img src="https://drive.google.com/uc?export=view&id=18yybvBIaZ4CC3j5QRamWbsAGoKPptBFi" alt="microsip-set-up" style="zoom: 65%;" />

- `Scroll to the bottom of the page under "Security" and "Certificates"`

- `Select "View Certificates" `

   <img src="https://drive.google.com/uc?export=view&id=19EEiZ26P7Rh7tPfnGrjlOnmvZNIY8srl" alt="microsip-set-up" style="zoom: 65%;" />

- `Make sure "Authorities is selected"`

   <img src="https://drive.google.com/uc?export=view&id=1vwQ9x-k75v_8ytpK3ZkQa77tUkbPLmc_" alt="microsip-set-up" style="zoom: 65%;" />

- `Import "ca.crt", the self-signed certificate we have just created, which is located at /etc/asterisk/keys` 

- `Check "Trust this CA to identify websites" and "Trust this CA to identify email users"`

   <img src="https://drive.google.com/uc?export=view&id=1F68cRGC-pLSiT9Ct15Gxnxwo-3KZRHtN" alt="microsip-set-up" style="zoom: 30%;" />

- `Then click "ok"`



### Conclusion

If you also face the web socket granting permission problem like I did, I hope you would find this article helpful to you. Or if you are interested in WebRTC, please check out this guide: https://github.com/paneru-rajan/asterisk-jssip. A big shoutout to [paneru-rajan](https://github.com/paneru-rajan) who provides the WebRTC set-up guide. In the meantime, please take care and stay healthy, and I will see you next week.