Encrypting Voice Calls in Elastix and Fail2ban
Encrypting Voice Calls in Elastix and Fail2ban
In Elastix/Asterisk, the SIP calls can be encrypted in two ways: encrypting the SIP protocol
signaling and encrypting the RTP voice low. To encrypt the SIP protocol signal, we will use the
Transport Layer Security (TLS) protocol.
HOW TO DO IT
1. Create security keys and certificates. For this example, we will store our keys and
certificates in the /etc/asterisk/keys folder.
3. Change the owner of the folder from the user root to the user asterisk:
cd /usr/share/doc/asterisk-11.20.0/contrib/scripts/
./ast_tls_cert -C chat.goldenoiltd.com -O "Goldenoil LTD" -d
/etc/asterisk/keys
5. Generate a pair of keys for a pair of extensions (extension 7002 and extension 7003,
for example):
where:
-m client: This option sets the program to create a client certificate.
-c /etc/asterisk/keys/ca.crt: This option specifies the Certificate Authority
to use (our IP-PBX).
-k /etc/asterisk/keys/ca.key: Provides the key file to the *.crt file.
-C: This option defines the hostname or IP address of our SIP device.
-O: This option defines the organizational name (same as above).
-d: This option specifies the directory where the keys and certificates will
be stored.
-o: This is the name of the key and certificate we are creating.
These lines are in charge of enabling the TLS support in our IP-PBX. They
also specify the folder where the certificates and the keys are stored and set
the ciphering option and client method to use.
8. Add the line transport=tls to the extensions we would like to use TLS in the sip_
custom.conf file located at /etc/asterisk/. This file should look like:
[7002](+)
encryption=yes
transport=tls
[7003](+)
encryption=yes
transport=tls
9. Reload the SIP module in the Asterisk service. This can be done by using the
command: asterisk -rx 'sip reload'
10. Configure our TLS-supporting IP phones. This configuration varies from model to
model. It is important to mention that the port used for TLS and SIP is port 5061;
therefore, our devices must use TCP/UDP port 5061. After our devices are registered
and we can call each other, we can be sure this configuration is working.
11. If we issue the command asterisk -rx 'sip show peer 7003', we will see
that the encryption is enabled. At this point, we've just enabled the encryption at
the SIP signaling level. With this, we can block any unauthorized user depending on
which port the media (voice or/and video) is being transported or steal a username
or password or eavesdrop a conversation.
12. Now, we will proceed to enable the audio/video (RTP) encryption. This term is also
known as Secure Real Time Protocol (SRTP). To do this, we only enable on the SIP
peers the encryption=yes option.
13. The screenshot after this shows an SRTP call between peers 7002 and 7003. This
information can be displayed with the command: asterisk -rx 'sip show
channel [the SIP channel of our call]
14. The line RTP/SAVP informs us that the call is secure, and the call in the softphone
shows an icon with the form of a lock confirming that the call is secure.
Fail2ban is a program that examines specific system logs in order to ban suspicious activity
from IP addresses, which could potentially lead to a failure or attack. It searches for regular
expressions declared in the *.conf files under the /etc/fail2ban/filter.d/ folder.
If a condition is matched, it will add the suspicious IP address to the Linux kernel's firewall
(iptables) and block it after a certain number of retries and for a certain period of time,
sending an e-mail address to the administrator. These actions are defined in the jail.conf
file, which is situated in the /etc/fail2ban/ folder. Fail2ban and iptables come installed in
Elastix by default. In case it is not installed, we can simply do it by typing yum -y install
fail2ban.
If we look at this file in the [DEFAULT] section, we can also use the following options:
[DEFAULT]
# "ignoreip" can be an IP address, a CIDR mask or a DNS host.
Fail2ban will not
# ban a host which matches an address in this list. Several
addresses can be
# defined using space separator.
ignoreip = 127.0.0.1
# "bantime" is the number of seconds that a host is banned.
bantime = 600
# A host is banned if it has generated "maxretry" during the last
"findtime"
# seconds.
findtime = 600
# "maxretry" is the number of failures before a host get banned.
Maxretry = 3
If we scroll down, we can see the services' logs that will be monitored by Fail2ban and
the actions to perform when a condition is met. For example, for the ssh service, we
can see that it's enabled by default, and it will add the suspicious IP address to the
firewall and block it for 600 seconds after 5 retries and send an e-mail to the address
[email protected] with a report of this incident.
# Asterisk jail
[asterisk]
enabled =true
filter =asterisk
action =iptables-multiport[name="asterisk", port="5060,4569",
protocol="udp"]
sendmail-whois[name="SIP", dest="root", sender="[email protected]"]
logpath =/var/log/asterisk/full
bantime =172800 # Elastix web interface
[elastix]
enabled = true
filter = elastix
action = iptables-multiport[name="elastix", port="http,https",
protocol="tcp"]
sendmail-whois[name="ELASTIX", dest="root", sender="[email protected]"]
logpath = /var/log/elastix/audit.log
bantime =172800
[ssh-iptables]
enabled = true
filter = sshd
action = iptables[name=SSH, port=ssh, protocol=tcp]
sendmail-whois[name=SSH, dest=root, sender = [email protected]]
logpath = /var/log/secure
maxretry = 5
/etc/fail2ban/jail.conf
/etc/fail2ban/jail.d/*.conf, alphabetically
/etc/fail2ban/jail.local
/etc/fail2ban/jail.d/*.local, alphabetically
Any file may contain a [DEFAULT] section, executed first, and may also contain sections for
individual jails. The last value set for a given parameter takes precedence.
Let's begin by writing a very simple version of jail.local. Open a new file using nano (or your
editor of choice):
[DEFAULT]
ignoreip = 192.168.1.0/24
bantime = 3600
findtime = 3600
Maxretry = 3
# Asterisk jail
[asterisk]
enabled =true
filter =asterisk
action =iptables-multiport[name="asterisk", port="5060,4569",
protocol="udp"]
sendmail-whois[name="SIP", dest="root", sender="[email protected]"]
logpath =/var/log/asterisk/full
bantime =172800 # Elastix web interface
[elastix]
enabled = true
filter = elastix
action = iptables-multiport[name="elastix", port="http,https",
protocol="tcp"]
sendmail-whois[name="ELASTIX", dest="root", sender="[email protected]"]
logpath = /var/log/elastix/audit.log
bantime =172800
[ssh-iptables]
enabled = true
filter = sshd
action = iptables[name=SSH, port=ssh, protocol=tcp]
sendmail-whois[name=SSH, dest=root, sender = [email protected]]
logpath = /var/log/secure
elastix.local
fail2ban-client status
Output
Status
|- Number of jail: 1
`- Jail list: sshd
You can also get more detailed information about a specific jail: