TL;DR
The insecure=very setting in your Asterisk trunk configuration disables important security checks. This guide shows you how to remove it and configure secure trunks using TLS (Transport Layer Security) for safe voice communication.
Step-by-step Guide
- Understand the Risk:
insecure=verytells Asterisk to ignore certificate validation errors. This means a malicious actor could potentially intercept your calls and eavesdrop on sensitive information. It’s strongly recommended to avoid this setting in production environments.- Why it exists: Often used for testing or with providers who haven’t issued proper certificates, but should be replaced with secure configurations as soon as possible.
- Check Your Current Configuration: Examine your
pjsip.conffile (usually located in/etc/asterisk/). Look for the trunk definition that usesinsecure=very.grep "insecure=very" /etc/asterisk/pjsip.conf - Obtain TLS Certificates from Your Provider: Contact your VoIP provider to get their TLS certificates (usually a CA certificate and potentially client certificates). They will provide instructions on how to download them.
- Configure the Trunk with TLS: Replace
insecure=verywith proper TLS settings in yourpjsip.conffile. Here’s an example:[your_trunk_name] type=endpoint context=from-internal sock=tls callerid=username= password= host= port=5061 ca=/etc/asterisk/certs/provider_ca.pem type=endpoint: Defines this as a PJSIP endpoint (trunk).sock=tls: Specifies TLS transport.ca=/etc/asterisk/certs/provider_ca.pem: Points to the CA certificate file provided by your provider. Important: Replace this path with the actual location of your certificate!
- If Your Provider Requires Client Certificates (Optional): If your provider also requires a client certificate, add these lines:
client_cert=/etc/asterisk/certs/your_client.pem client_key=/etc/asterisk/certs/your_private.key - Reload Asterisk: After making changes to
pjsip.conf, reload the PJSIP module.asterisk -rx "pjsip reload" - Verify the Configuration: Check the Asterisk logs (usually in
/var/log/asterisk/full) for any TLS-related errors. Look for messages indicating successful certificate validation.tail -f /var/log/asterisk/full | grep tls - Test the Trunk: Make a test call through the trunk to ensure it’s working correctly. Monitor call quality and check for any issues.

