TLS چیست؟
TLS مخفف Transport Layer Security و به معنای پروتکل امنیتی لایه انتقال می باشد.TLS تکامل یافته پروتکل SSL هست که تا حد زیادی جایگزین اون شده.TLS یک پروتکل امنیتی جهت ایجاد ارتباط امن بین کلاینت یا کاربر با اپلیکیشنها در شبکه های بزرگ از جمله اینترنت می باشد.
در پروتکل TLS احراز هویت با استفاده از Certificate صورت می گیرد که به دو روش یک طرفه و دوطرفه انجام می شود.
در حالت یکطرفه سرور تنها سرور احراز هویت می شود و کلاینت از اصالت سرور اطمینان حاصل می کند.
در حالت دوم سرور certificate دستگاه کلاینت را بررسی و از اصالت آن اطمینان حاصل می کند. سپس از جابجایی packet به صورت encrypted آغاز می شود.
کاربردهای TLS در دنیای VOIP
با قرار دادن Certificate TLS بر روی سرور های تلفنی و گوشی ها ارتباط بین سرور ها و ارتباط گوشی ها با سرور ها ایمن سازی می شود. از قابلیت های مهم TLS ایمن سازی ارتباط بدون نیاز به ورود اطلاعات کاربری (نام کاربری و رمز عبور) است.
انتقال بر روی TLS در Asterisk
برای استفاده از TLS دستگاه خدمات گیرنده (CLIENT ) ، معتبر بودن certifiacate را چک خواهد کرد که در این صورت می بایست توسط یک CA اصلی امضا شود و یا باید CA Certificate بر روی دستگاه کلاینت قرار گیرد.

تنظیمات مرتبط با TLS در فایل sip.conf

tlsenable=yes - Enable TLS server, default is no
tlsbindaddr= ip address- Specify IP address to bind TLS server to, default is 0.0.0.0
tlscertfile=path/to/certificate - The server's certificate file. Should include the key and certificate. This is mandatory if you're going to run a TLS server
tlscafile= path/to/certificate- If the server you're connecting to uses a self signed certificate you should have their certificate installed here so the code can verify the authenticity of their certificate
tlscapath=path/to/ca/dir - A directory full of CA certificates. The files must be named with the CA subject name hash value. (see man SSL_CTX_load_verify_locations for more info
tlsdontverifyserver=yes - If set to yes, don't verify the servers certificate when acting as a client. If you don't have the server's CA certificate you can set this and it will connect without requiring tlscafile to be set. Default is no
tlscipher= - A string specifying which SSL ciphers to use or not use. A list of valid SSL cipher strings can be found at http://www.openssl.org/docs/apps/ciphers.html#CIPHER_STRINGS


برای ایجاد کلید استریسک میتونید از کامند زیر استفاده کنید:
openssl genrsa -out key.pem 1024
در این قسمت ایجاد SSL Certificate را خواهیم داشت:
openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -keyout key.pem -out asterisk.pem

در ادامه، تنظیمات دو سرور Asterisk برای اتصال به یکدیگر با پروتکل TLS توضیح داده شده است.

سرور اول:

[general]
tlsenable=yes
tlscertfile=/etc/asterisk/asterisk.pem
tlscafile=/etc/ssl/ca.pem ; This is the CA file used to generate both certificates
register => tls://100:test@192.168.0.100:5061

[101]
type=friend
context=internal
host=192.168.0.100 ; The host should be either IP or hostname and should
; match the 'common name' field in the servers certificate
secret=test
dtmfmode=rfc2833
disallow=all
allow=ulaw
transport=tls
port=5061

سرور دوم:
[general]
tlsenable=yes
tlscertfile=/etc/asterisk/asterisk.pem

[100]
type=friend
context=internal
host=dynamic
secret=test
dtmfmode=rfc2833
disallow=all
allow=ulaw
;You can specify transport= and port=5061 for TLS, but its not necessary in
;the server configuration, any type of SIP transport will work
;transport=tls
;port=5061