# Parameters

## `tls_method` (string)

Sets the SSL/TLS protocol method. Possible values are:

- TLSv1.2 - only TLSv1.2 connections are accepted (available starting with openssl/libssl v1.0.1e)

- TLSv1.1 - only TLSv1.1 connections are accepted (available starting with openssl/libssl v1.0.1)

- TLSv1 - only TLSv1 connections are accepted. This is the default value.

- SSLv3 - only SSLv3 connections are accepted

- SSLv2 - only SSLv2 connections, for old clients. Note: you shouldn't use SSLv2 for anything which should be highly secure. Newer versions of libssl don't include support for it anymore.

- SSLv23 - any of the SSLv2, SSLv3 and TLSv1 methods will be accepted, with the following limitation: the initial SSL hello message must be V2 (in the initial hello all the supported protocols are advertised enabling switching to a higher and more secure version). This means connections from SSLv3 or TLSv1 clients will be accepted.

If rfc3261 conformance is desired, TLSv1 must be used. For compatibility with older clients SSLv23 is a good option.

### Set `tls_method` parameter

    ...
    modparam("tls", "tls_method", "TLSv1")
    ...

## `certificate` (string)

Sets the certificate file name. The certificate file can also contain the private key in PEM format.

If the file name starts with a '.' the path will be relative to the working directory (at runtime). If it starts with a '/' it will be an absolute path and if it starts with anything else the path will be relative to the main config file directory (e.g.: for kamailio -f /etc/kamailio/kamailio.cfg it will be relative to /etc/kamailio/).

Warning: try not to use certificate with keys longer then 1024 bytes. Longer keys will severely impact performance, in particular the TLS connection rate.

The default value is [SER_CFG_DIR]/cert.pem.

### Set `certificate` parameter

    ...
    modparam("tls", "certificate", "/usr/local/etc/kamailio/my_certificate.pem")
    ...

## `private_key` (string)

Sets the private key file name.

If the file name starts with a '.' the path will be relative to the working directory (at runtime). If it starts with a '/' it will be an absolute path and if it starts with anything else the path will be relative to the main config file directory (e.g.: for kamailio -f /etc/kamailio/kamailio.cfg it will be relative to /etc/kamailio/).

Note: the private key can be contained in the same file as the certificate (just append it to the certificate file, e.g.: cat pkey.pem >> cert.pem)

The default value is [SER_CFG_DIR]/cert.pem.

### Set `private_key` parameter

    ...
    modparam("tls", "private", "/usr/local/etc/kamailio/my_pkey.pem")
    ...

## `ca_list` (string)

Sets the CA list file name. This file contains a list of all the trusted CAs certificates. If a signature in a certificate chain belongs to one of the listed CAs, the authentication will succeed.

If the file name starts with a '.' the path will be relative to the working directory (at runtime). If it starts with a '/' it will be an absolute path and if it starts with anything else the path will be relative to the main config file directory (e.g.: for kamailio -f /etc/kamailio/kamailio.cfg it will be relative to /etc/kamailio/).

By default the CA file is not set.

An easy way to create the CA list is to append each trusted trusted CA certificate in the PEM format to one file, e.g.: for f in trusted_cas/*.pem ; do cat "$f" >> ca_list.pem ; done .

See also verify_certificate, verify_depth, require_certificate and crl.

### Set `ca_list` parameter

    ...
    modparam("tls", "ca_list", "/usr/local/etc/kamailio/ca_list.pem")
    ...

## `crl` (string)

Sets the certificate revocation list file name. This file contains a list of revoked certificates. Any attempt to verify a revoked certificate will fail.

If not set, no crl list will be used.

If the file name starts with a '.' the path will be relative to the working directory (at runtime). If it starts with a '/' it will be an absolute path and if it starts with anything else the path will be relative to the main config file directory (e.g.: for kamailio -f /etc/kamailio/kamailio.cfg it will be relative to /etc/kamailio/).

If set, `require_certificate` should also be set or it will not have any effect.

By default the crl file is not set.

To update the crl in a running &kamailio;, make sure you configure tls via a separate tls config file (the `config` modparam) and issue a tls.reload RPC call, e.g.:

     $ &sercmd; tls.reload

A quick way to create the CRL in PEM format, using openssl is:

     $ openssl ca -gencrl -keyfile cacert.key -cert cacert.pem -out my_crl.pem

my_crl.pem will contain the signed list of the revoked certificates.

To revoke a certificate use something like:

     $ openssl ca -revoke bad_cert.pem -keyfile cacert.key -cert cacert.pem

and then refresh the crl file using the command above.

To display the CRL contents use:

     $ openssl crl -in crl.pem -noout -text

See also ca_list, verify_certificate, verify_depth and require_certificate.

### Set `crl` parameter

    ...
    modparam("tls", "crl", "/usr/local/etc/kamailio/crl.pem")
    ...

## `verify_certificate` (boolean)

If enabled it will force certificate verification. For more information see the verify(1) openssl man page.

Note: the certificate verification will always fail if the ca_list is empty.

See also: `ca_list`, `require_certificate`, `verify_depth`.

By default the certificate verification is off.

### Set `verify_certificate` parameter

    ...
    modparam("tls", "verify_certificate", 1)
    ...

## `verify_depth` (integer)

Sets how far up the certificate chain will the certificate verification go in the search for a trusted CA.

See also: `ca_list`, `require_certificate`, `verify_certificate`,

The default value is 9.

### Set `verify_depth` parameter

    ...
    modparam("tls", "verify_depth", 9)
    ...

## `require_certificate` (boolean)

When enabled it will require a certificate from a client. If the client does not offer a certificate and `verify_certificate` is on, the certificate verification will fail.

The default value is off.

### Set `require_certificate` parameter

    ...
    modparam("tls", "require_certificate", 1)
    ...

## `cipher_list` (string)

Sets the list of accepted ciphers. The list consists of cipher strings separated by colons. For more information on the cipher list format see the cipher(1) openssl man page.

The default value is not set (all the Openssl supported ciphers are enabled).

### Set `cipher_list` parameter

    ...
    modparam("tls", "cipher_list", "HIGH")
    ...

## `send_timeout` (int)

This parameter is obsolete and cannot be used in newer TLS versions (> &kamailio; 3.0). In these versions the send_timeout is replaced by `tcp_send_timeout` (common with all the tcp connections).

## `handshake_timeout` (int)

This parameter is obsolete and cannot be used in newer TLS versions (> &kamailio; 3.0). In these versions the handshake_timeout is replaced by `tcp_connect_timeout` (common with all the tcp connections).

## `connection_timeout` (int)

Sets the amount of time after which an idle TLS connection will be closed, if no I/O ever occured after the initial open. If an I/O event occurs, the timeout will be extended with tcp_connection_lifetime. The value is expressed in seconds.

The default value is 10 min.

If the value set is -1, the connection will never be close on idle.

It can be changed also at runtime, via the RPC interface and config framework. The config variable name is tls.connection_timeout.

### Set `connection_timeout` parameter

    ...
    modparam("tls", "connection_timeout", 60)
    ...

### Set `tls.connection_timeout` at runtime

     $ &sercmd; cfg.set_now_int tls connection_timeout 180

## `tls_disable_compression` (boolean)

If set compression over SSL/TLS will be disabled. Note that compression uses a lot of memory (about 10x more then with the compression disabled), so if you want to minimize memory usage is a good idea to disable it.

By default compression is disabled.

### Set `tls_disable_compression` parameter

    ...
    modparam("tls", "tls_disable_compression", 0) # enable
    ...

## `ssl_release_buffers` (integer)

Release internal OpenSSL read or write buffers as soon as they are no longer needed. Combined with `ssl_free_list_max_len` has the potential of saving a lot of memory ( ~ 32k per connection in the default configuration, or 16k + `ssl_max_send_fragment`). For sr versions > 3.0 it makes little sense to disable it (0) since the tls module already has its own internal buffering.

A value of -1 would not change this option from its openssl default. Use 0 or 1 for enable/disable.

By default the value is 1 (enabled).

This option is supported only for OpenSSL versions >= 1.0.0. On all the other versions attempting to change the default will trigger an error.

### Set `ssl_release_buffers` parameter

    modparam("tls", "ssl_release_buffers", 1)

## `ssl_free_list_max_len` (integer)

Sets the maximum number of free memory chunks, that OpenSSL will keep per connection. Setting it to 0 would cause any unused memory chunk to be immediately freed, reducing the memory footprint. A too large value would result in extra memory consumption.

Should be combined with `ssl_release_buffers`.

A value of -1 has a special meaning: the OpenSSL default will be used (no attempt on changing the value will be made). For OpenSSL 1.0 the internal default is 32.

By default the value is 0 (no freelist).

This option is supported only for OpenSSL versions >= 1.0.0. On all the other versions attempting to change the default will trigger an error.

### Set `ssl_freelist_max_len` parameter

    modparam("tls", "ssl_freelist_max_len", 0)

## `ssl_max_send_fragment` (integer)

Sets the maximum number of bytes (from the clear text) sent into one TLS or SSL record. Valid values are between 512 and 16384. Note however that even valid low values might not be big enough to allow a succesfull handshake (try minimum 1024).

Lower values would lead to less memory usage, but values lower then the typical &kamailio; write size would incur a slight performance penalty. Good values are bigger then the size of the biggest SIP packet one normally expects to forward. For example in most setups 2048 would be a good value.

Values on the lower side, even if valid (> 512), might not allow for a succesfull initial handshake. This happens if the certificate does not fit inside one send fragment. Values lower then 1024 should not be used. Even with higher values, if the handshake fails, try increasing the value.

A value of -1 has a special meaning: the OpenSSL default will be used (no attempt on changing the value will be made).

By default the value is -1 (the OpenSSL default, which at least in OpenSSL 1.0.0 is ~ 16k).

This option is supported only for OpenSSL versions >= 0.9.9. On all the other versions attempting to change the default will trigger an error.

### Set `ssl_max_send_fragment` parameter

    modparam("tls", "ssl_max_send_fragment", 4096)

## `ssl_read_ahead` (boolean)

Enables read ahead, reducing the number of internal OpenSSL BIO read() calls. This option has only debugging value, in normal circumstances it should not be changed from the default.

When disabled OpenSSL will make at least 2 BIO read() calls per received record: one to get the record header and one to get the rest of the record.

The TLS module buffers internally all read()s and defines its own fast BIO so enabling this option would only cause more memory consumption and a minor slow-down (extra memcpy).

A value of -1 has a special meaning: the OpenSSL default will be used (no attempt on changing the value will be made).

By default the value is 0 (disabled).

### Set `ssl_read_ahead` parameter

    modparam("tls", "ssl_read_ahead", 1)

## `send_close_notify` (boolean)

Enables/disables sending close notify alerts prior to closing the corresponding TCP connection. Sending the close notify prior to tcp shutdown is "nicer" from a TLS point of view, but it has a measurable performance impact. Default: off. Can be set at runtime (tls.send_close_notify).

The default value is 0 (off).

It can be changed also at runtime, via the RPC interface and config framework. The config variable name is tls.send_close_notify.

### Set `send_close_notify` parameter

    ...
    modparam("tls", "send_close_notify", 1)
    ...

### Set `tls.send_close_notify` at runtime

     $ &sercmd; cfg.set_now_int tls send_close_notify 1

## `con_ct_wq_max` (integer)

Sets the maximum allowed per connection clear-text send queue size in bytes. This queue is used when data cannot be encrypted and sent immediately because of an ongoing TLS/SSL level renegotiation.

The default value is 65536 (64 Kb).

It can be changed also at runtime, via the RPC interface and config framework. The config variable name is tls.con_ct_wq_max.

### Set `con_ct_wq_max` parameter

    ...
    modparam("tls", "con_ct_wq_max", 1048576)
    ...

### Set `tls.con_ct_wq_max` at runtime

     $ &sercmd; cfg.set_now_int tls con_ct_wq_max 1048576

## `ct_wq_max` (integer)

Sets the maximum total number of bytes queued in all the clear-text send queues. These queues are used when data cannot be encrypted and sent immediately because of an ongoing TLS/SSL level renegotiation.

The default value is 10485760 (10 Mb).

It can be changed also at runtime, via the RPC interface and config framework. The config variable name is tls.ct_wq_max.

### Set `ct_wq_max` parameter

    ...
    modparam("tls", "ct_wq_max", 4194304)
    ...

### Set `tls.ct_wq_max` at runtime

     $ &sercmd; cfg.set_now_int tls ct_wq_max 4194304

## `ct_wq_blk_size` (integer)

Minimum block size for the internal clear-text send queues (debugging / advanced tunning). Good values are multiple of typical datagram sizes.

The default value is 4096.

It can be changed also at runtime, via the RPC interface and config framework. The config variable name is tls.ct_wq_blk_size.

### Set `ct_wq_blk_size` parameter

    ...
    modparam("tls", "ct_wq_blk_size", 2048)
    ...

### Set `tls.ct_wq_max` at runtime

     $ &sercmd; cfg.set_now_int tls ct_wq_blk_size 2048

## `tls_log` (int)

Sets the log level at which TLS related messages will be logged.

The default value is 3 (L_DBG).

It can be changed also at runtime, via the RPC interface and config framework. The config variable name is tls.log.

### Set `tls_log` parameter

    ...
    # ignore TLS messages if Kamailio is started with debug less than 10
    modparam("tls", "tls_log", 10)
    ...

### Set `tls.log` at runtime

     $ &sercmd; cfg.set_now_int tls log 10

## `tls_debug` (int)

Sets the log level at which TLS debug messages will be logged. Note that TLS debug messages are enabled only if the TLS module is compiled with debugging enabled (e.g. -DTLS_WR_DEBUG, -DTLS_RD_DEBUG or -DTLS_BIO_DEBUG).

The default value is 3 (L_DBG).

It can be changed also at runtime, via the RPC interface and config framework. The config variable name is tls.debug.

### Set `tls_debug` parameter

    ...
    # ignore TLS debug messages if Kamailio is started with debug less than 10
    modparam("tls", "tls_debug", 10)
    ...

### Set `tls.debug` at runtime

     $ &sercmd; cfg.set_now_int tls debug 10

## `low_mem_threshold1` (integer)

Sets the minimal free memory from which attempts to open or accept new TLS connections will start to fail. The value is expressed in KB.

The default value depends on whether the openssl library used handles well low memory situations (openssl bug #1491). As of this writing this is not true for any openssl version (including 0.9.8e).

If an ill-behaved openssl version is detected, a very conservative value is choosed, which depends on the maximum possible number of simultaneously created TLS connections (and hence on the process number).

The following values have a special meaning:

- -1 - use the default value

- 0 - disable (TLS connections will not fail preemptively)

It can be changed also at runtime, via the RPC interface and config framework. The config variable name is tls.low_mem_threshold1.

See also `low_mem_threshold2`.

### Set `low_mem_threshold1` parameter

    ...
    modparam("tls", "low_mem_threshold1", -1)
    ...

### Set `tls.low_mem_threshold1` at runtime

     $ &sercmd; cfg.set_now_int tls low_mem_threshold1 2048

## `low_mem_threshold2` (integer)

Sets the minimal free memory from which TLS operations on already established TLS connections will start to fail preemptively. The value is expressed in KB.

The default value depends on whether the openssl library used handles well low memory situations (openssl bug #1491). As of this writing this is not true for any openssl version (including 0.9.8e).

If an ill-behaved openssl version is detected, a very conservative value is choosed, which depends on the maximum possible number of simultaneously created TLS connections (and hence on the process number).

The following values have a special meaning:

- -1 - use the default value

- 0 - disable (TLS operations will not fail preemptively)

It can be changed also at runtime, via the RPC interface and config framework. The config variable name is tls.low_mem_threshold2.

See also `low_mem_threshold1`.

### Set `low_mem_threshold2` parameter

    ...
    modparam("tls", "low_mem_threshold2", -1)
    ...

### Set `tls.low_mem_threshold2` at runtime

     $ &sercmd; cfg.set_now_int tls low_mem_threshold2 1024

## `tls_force_run` (boolean)

If enabled Kamailio will start even if some of the openssl sanity checks fail (turn it on at your own risk).

Currently failing any of the following sanity checks will not allow Kamailio to start:

- the version of the library the TLS module was compiled with is "too different" from the library used at runtime. The versions should have the same major, minor and fix level (e.g.: 0.9.8a and 0.9.8c are ok, but 0.9.8 and 0.9.9 are not)

- the openssl library used at compile time and the one used at runtime have different kerberos options

By default tls_force_run is disabled.

### Set `tls_force_run` parameter

    ...
    modparam("tls", "tls_force_run", 11)
    ...

## `session_cache` (boolean)

If enabled &kamailio; will do caching of the TLS sessions data, generation a session_id and sending it back to client.

By default TLS session caching is disabled (0).

### Set `session_cache` parameter

    ...
    modparam("tls", "session_cache", 1)
    ...

## `session_id` (str)

The value for session ID context, making sense when session caching is enabled.

By default TLS session_id is "sip-router-tls-3.1".

### Set `session_id` parameter

    ...
    modparam("tls", "session_id", "my-session-id-context")
    ...

## `renegotiation` (boolean)

If enabled &kamailio; will allow renegotiations of TLS connection initiated by the client. This may expose to a security risk if the client is not a trusted peer and keeps renegotiating, consuming CPU and bandwidth resources.

By default TLS renegotiation is disabled (0).

### Set `renegotiation` parameter

    ...
    modparam("tls", "renegotiation", 1)
    ...

## `config` (string)

Sets the name of the TLS specific config file or config directory.

If set the TLS module will load a special config file or config files from config directory, in which different TLS parameters can be specified on a per role (server or client) and domain basis (for now only IPs). The corresponding module parameters will be ignored.

If the file or directory name starts with a '.' the path will be relative to the working directory (at runtime). If it starts with a '/' it will be an absolute path and if it starts with anything else the path will be relative to the main config file directory (e.g.: for kamailio -f /etc/kamailio/kamailio.cfg it will be relative to /etc/kamailio/).

By default no config file is specified.

The following parameters can be set in the config file, for each domain:

- tls_method

- verify_certificate

- require_certificate

- private_key

- certificate

- verify_depth

- ca_list

- crl

- cipher_list

All the parameters that take filenames as values will be resolved using the same rules as for the tls config filename itself: starting with a '.' means relative to the working directory, a '/' means an absolute path and anything else a path relative to the directory of the current &kamailio; main config file.

Kamailio acts as a server when it accepts a connection and as a client when it initiates a new connection by itself (it connects to something).

### Short config file

    [server:default]
    method = TLSv1
    verify_certificate = yes
    require_certificate = yes
    private_key = default_key.pem
    certificate = default_cert.pem
    ca_list = default_ca.pem
    crl = default_crl.pem

    [client:default]
    verify_certificate = yes
    require_certificate = yes

    #more relaxed for connection on the loopback interface
    [server:127.0.0.1:5061]
    method = SSLv23
    verify_certificate = yes
    require_certificate = no
    private_key = local_key.pem
    certificate = local_cert.pem
    verify_depth = 3
    ca_list = local_ca.pem

For a more complete example check the tls.cfg distributed with the Kamailio source (kamailio/modules/tls/tls.cfg).

### Set `config` parameter

    ...
    modparam("tls", "config", "/usr/local/etc/kamailio/tls.cfg")
    ...

It can be changed also at runtime. The new config will not be loaded immediately, but after the first tls.reload RPC call.

### Change and reload tls config at runtime

     $ &sercmd; cfg.set_now_string tls config "/usr/local/etc/kamailio/new_tls.cfg"
     $ &sercmd; tls.reload