# Parameters

## `tls_method` (string)

Sets the TLS protocol method. Possible values are:

- TLSv1.3+ - TLSv1.3 or newer (TLSv1.3, ...) connections are accepted (available starting with openssl/libssl v1.1.1)

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

- TLSv1.2+ - TLSv1.2 or newer (TLSv1.3, ...) connections are accepted (available starting with openssl/libssl v1.1.1)

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

- TLSv1.1+ - TLSv1.1 or newer (TLSv1.2, ...) connections are accepted (available starting with openssl/libssl v1.0.1)

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

- TLSv1+ - TLSv1.0 or newer (TLSv1.1, TLSv1.2, ...) connections are accepted.

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

- SSLv3 - only SSLv3 connections are accepted. Note: you shouldn't use SSLv3 for anything which should be secure.

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

- SSLv23 - any of the SSLv2, SSLv3 and TLSv1 or newer methods will be accepted.

  From the OpenSSL manual: "A TLS/SSL connection established with these methods may understand the SSLv3, TLSv1, TLSv1.1 and TLSv1.2 protocols. If extensions are required (for example server name) a client will send out TLSv1 client hello messages including extensions and will indicate that it also understands TLSv1.1, TLSv1.2 and permits a fallback to SSLv3. A server will support SSLv3, TLSv1, TLSv1.1 and TLSv1.2 protocols. This is the best choice when compatibility is a concern."

  Note: For older OpenSSL library versions, this option allows SSLv2, with hello messages done over SSLv2. You shouldn't use SSLv2 or SSLv3 for anything which should be secure.

If RFC 3261 conformance is desired, at least TLSv1 must be used. For compatibility with older clients SSLv23 is the option, but again, be aware of security concerns, SSLv2/3 as well as TLS v1.0 and v1.1 are being considered very insecure and are therefore deprecated since March 2021 (RFC 8996). For current information about what's considered secure, please consult, IETF BCP 195, currently RFC 9325 - "Recommendations for Secure Use of Transport Layer Security (TLS) and Datagram Transport Layer Security (DTLS)"

### 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/).

The default value is &kamailioconfdir;/cert.pem

### Set `certificate` parameter

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

## `private_key` (string)

Sets the private key file name. The private key can be in the same file as the certificate or in a separate file, specified by this configuration parameter.

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 &kamailioconfdir;/cert.pem

### Set `private_key` parameter

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

## `private_key_password` (string)

The password for the private key.

The default value is empty.

### Set `private_key_password` parameter

    ...
    modparam("tls", "private_key_password", "secret")
    ...

## `key_password_mode` (int)

The mode to get the password for the private key. If 0, take it from the config "private_key_password". If 1, promt for it at start up.

The default value is 0.

### Set `key_password_mode` parameter

    ...
    modparam("tls", "key_password_mode", 0)
    ...

## `ca_list` (string)

Sets the CA list file name. This file contains a list of all the trusted CAs certificates used when connecting to other SIP implementations. If a signature in a certificate chain belongs to one of the listed CAs, the verification of that certificate 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")
    ...

## `ca_path` (str)

Sets the path with the trusted CA files, to be given as parameter SSL_CTX_load_verify_locations(). The certificates in ca_path are only looked up when required, e.g. when building the certificate chain or when actually performing the verification of a peer certificate. They are not given to the client (not loaded to be provided to SSL_CTX_set_client_CA_list()), only the ones in ca_list files are sent to the client. It requires to use c_rehash to generate the hash map for certificate search, for more see the manual of libssl for SSL_CTX_load_verify_locations() function.

By default it is not set.

### Set `ca_path` parameter

    ...
    modparam("tls", "ca_path", "/usr/local/etc/kamailio/ca")
    ...

## `crl` (string)

Sets the certificate revocation list (CRL) 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 name 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 TLS 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 when connecting to other SIP servers.. 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 &kamailio; will require a certificate from a client connecting to the TLS port. If the client does not offer a certificate and `verify_certificate` is on, 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")
    ...

## `server_name` (string)

Sets the Server Name Indication (SNI) value.

This is a TLS extension enabling one TLS server to serve multiple host names with unique certificates.

The default value is empty (not set).

### Set `server_name` parameter

    ...
    modparam("tls", "server_name", "kamailio.org")
    ...

## `connection_timeout` (int)

Sets the amount of time after which an idle TLS connection will be closed, if no I/O ever occurred 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.

This setting 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 TLS will be disabled. Note that compression uses a lot of memory (about 10x more than with the compression disabled), so if you want to minimize memory usage is a good idea to disable it. TLS compression also expose you for the CRIME security vulnerability.

By default TLS 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_freelist_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 &kamailio; 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_freelist_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 record. Valid values are between 512 and 16384. Note however that even valid low values might not be big enough to allow a successful handshake (try minimum 1024).

Lower values would lead to less memory usage, but values lower than the typical &kamailio; write size would incur a slight performance penalty. Good values are bigger than 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 successful initial handshake. This happens if the certificate does not fit inside one send fragment. Values lower than 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 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 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 tuning). 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 low memory situations in a good way (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 chosen, 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 `tls.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 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 chosen, 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 `tls.low_mem_threshold1`.

### Set `tls.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).

If any of the following sanity checks fail, Kamailio will not 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 "kamailio-tls-5.x.y".

### 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)
    ...

## `init_mode` (int)

Allow setting flags that control how the module is initialized and works at runtime. Many flags (bits) can be set at the same time (set the parameter to the sum of corresponding values). The flags are refered with 0-indexing.

If flag (bit) at index 0 is set (value 1), the memory management operations registered for TLS are wrapped within a pthread mutex lock. It can be useful with newer versions of libssl and libcrypto, which have a more pthread multi-threading oriented design.

If flag (bit) at index 1 is set (value 2), the module executes openssl fork prepare API functions (see https://www.openssl.org/docs/man1.1.1/man3/OPENSSL_fork_prepare.html). It is done only for openssl version greater or equal with 1.1.1.

Default value is 0.

### Set `init_mode` parameter

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

## `config` (string)

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

If set the TLS module will load a special configuration file or configuration files from configuration 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 a separate configuration file is used.

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 TLS configuration file is specified.

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

- tls_method - (str) - TLS methods

- verify_certificate - (bool) - see modparam

- require_certificate - (bool) - see modparam

- verify_client - (str) - see modparam

- private_key - (str) - see modparam

- certificate - (str) - see modparam

- verify_depth - (int) - see modparam

- ca_list - (str) - see modparam

- crl - (str) - see modparam

- cipher_list - (str) - see modparam

- server_name - (str) - SNI (server name identification)

- server_name_mode - (int) - how to match server_name

- server_id - (str) - server id

The value for server_name_mode specifies how to match the server_name (SNI). If set to 1, match the domain and all its subdomains. If set to 2, match only the subdomains. If set to 0 (or anything else), match only the domain given in server_name.

The value for server_id can be any string, being used to match TLS client config profile, overriding the match on ip:port and server_name. This is the recommended way for selecting a specific TLS client config profile, because the local or remote port is hard to predict for a stream connection - see parameter `xavp_cfg` to learn how to enable it.

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).

The tls.cfg consists on a set of server and client TLS domain profiles. A server TLS domain profile starts with [server:domain]. A client TLS domain profile starts with [client:domain]. The tokens 'server' and 'client' are static values. The 'domain' part can be: 'ip:port' - the IP address and port to match with the TLS connection; 'default' - (static string) for client and server profiles to be used when no other profile is matched; 'any' - (static string) for client and server profiles to be matched based on 'server_name', no matter of IP and port of the TLS connection.

There can be only one of each [server:default] and [client:default] profile definitions. Other profiles can be defined many times with the same domain ('ip:port' or 'any'), but in that case they must have 'server_name' set for matching SNI.

It is highly recommended to have [server:default] and [client:default] profile definitions. They are needed when SNI is not yet available. If SNI is provided, then the profile definition is searched again to match on 'server_name'.

### Sample TLS 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 = TLSv1
    verify_certificate = yes
    require_certificate = no
    private_key = local_kamailio_org_key.pem
    certificate = local_kamailio_org_cert.pem
    verify_depth = 3
    ca_list = local_ca.pem
    server_name = kamailio.org

    [client:127.0.0.1:5061]
    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
    server_name = kamailio.org
    server_id = kamailio.org

    # server profile on any address
    [server:any]
    method = TLSv1
    verify_certificate = yes
    require_certificate = no
    private_key = kamailio_net_key.pem
    certificate = kamailio_net_cert.pem
    verify_depth = 3
    ca_list = local_ca.pem
    server_name = kamailio.net
    server_name_mode = 1
    ...

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")
    ...

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

### Change and reload the TLS configuration at runtime

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

## `xavp_cfg` (string)

Sets the name of XAVP that stores attributes for TLS connections.

The following (inner) attributes can be set:

- server_name - SNI to be used for outbound connections

- server_id - string value to be used to match TLS config profile for client (outbound) connections. If it is set, matching the TLS config profile is done first on server_id and then on ip:port and server_name. This is the recommended way for selecting a specific TLS client config profile as the local or remote port is hard to predict for a stream connection.

The default value is empty (not set).

### Set `xavp_cfg` parameter

    ...
      modparam("tls", "xavp_cfg", "tls")
     ...
      $xavp(tls=>server_name) = "kamailio.org";
      $xavp(tls[0]=>server_id) = "kamailio.org";
      $du = "sip:kamailio.org:5061;transport=tls";
      route(RELAY);
    ...

## `event_callback` (str)

The name of the function in the kemi configuration file (embedded scripting language such as Lua, Python, ...) to be executed instead of event_route[...] blocks specific for tls module.

The function has one string parameter, the value is the name of the event_route block, respectively "tls:connection-out".

Default value is 'empty' (no function is executed for events).

### Set `event_callback` parameter

    ...
    modparam("tls", "event_callback", "ksr_tls_event")
    ...
    -- event callback function implemented in Lua
    function ksr_tls_event(evname)
    	KSR.info("===== tls module triggered event: " .. evname .. "\n");
    	return 1;
    end
    ...

## `rand_engine` (str)

Set the random number generator engine for libssl.

Note: the default random number generator (PRNG) engine of libssl v1.1.x is not designed for multi-process applications and can result in a crash. Therefore set the PRNG engine to one of the options listed in this section. If libssl 1.1.x (or newer) is detected at compile time, then the PRNG engine is set to "cryptorand".

The following options are available:

- krand - use internal kam_rand() function

- fastrand - use internal fastrand (ISAAC) function

- cryptorand - use internal cryptorand (Fortuna) function

- kxlibssl - default libssl rand engine wrapped by a &kamailio; mutex

Note: the krand and fastrand engines are not recommended for use on systems requiring strong security, as they may not generate numbers with enough randomness and are not cryptographically secure.

The default value is empty (not set) for libssl v1.0.x or older, and "cryptorand" for libssl v1.1.x or newer.

### Set `rand_engine` parameter

    ...
    modparam("tls", "rand_engine", "fastrand")
    ...

## `engine` (string)

If OpenSSL is compiled with engine support this will allow algorithms to be offloaded and private keys from HSM to be used. Currently only a single global engine is supported. However, private keys can be specified per_domain.

To use private keys from the HSM, the name is the HSM key label prefixed by `/engine:`.

    ...
    ## example for the Gem engine
    modparam("tls", "engine", "gem")
    # can also be set per-domain in tls.cfg
    modparam("tls", "private_key", "/engine:my_HSM_key_label")

    ## example for engine_pkcs11
    modparam("tls", "engine", "pkcs11")
    modparam("tls", "private_key", "/engine:pkcs11:token=MYTOKEN;object=MYKEYLABEL")

    modparam("tls", "engine_config", "/usr/local/etc/kamailio/openssl.cnf")
    modparam("tls", "engine_algorithms", "ALL")
    ...

By default OpenSSL engine support is disabled (NONE). This global param is not supported in the tls config file.

## `engine_config` (string)

An OpenSSL configuration file to initialize the engine. Typically used to send PIN to HSMs to unlock private keys. See the HSM howto for an example. This global param is not supported in the tls config file.

## `engine_algorithms` (string)

A list of cryptographic methods to be set as default in the engine. This is a comma-separated list of values from ALL RSA DSA DH EC RAND CIPHERS DIGESTS PKEY PKEY_CRYPTO PKEY_ASN1. Not all methods are supported by every engine.

The default is not to set any methods as default. This global param is not supported in the tls config file.

## `verify_client` (string)

Provides an alternative to verify_certificate and require_certificate modparam and tls.cfg parameters, and creates an additional opportunistic connection establishment option for connections with with unverifiable certificates (optional_no_ca).

This is useful for allowing connections from SIP phones with self-signed certificates, signed by unrecognized root CAs, expired certificates, etc.

The following values have respective behaviors:

- off - no client certificate request performed.

- on - require a verified certificate from the client.

- optional - ask client for certificate. If one is provided, it must be verified. Allowing missing certificate.

- optional_no_ca - ask client for certificate. Opportunistically try to verify certificate. Allow connection regardless of whether there is no certificate or whether certificate is present (verified or not). Note that verification status can be retrieved via $tls_peer_verified.

Default value is 'off' (no client certificate request performed).

Recommendation: when using this parameter, do not use verify_certificate or require_certificate parameters. Conversion table is as follows:

- verify_certificate=0, require_certificate=0 => verify_client="off"

- verify_certificate=1, require_certificate=0 => verify_client="optional"

- verify_certificate=1, require_certificate=1 => verify_client="on"

### Set `verify_client` modparam parameter

    ...
    modparam("tls", "verify_client", "on")
    ...

### Set `verify_client` tls.cfg parameter

    ...
    [server:1.2.3.4:5061]
    method = TLSv1
    verify_client = on
    ...

    [server:5.6.7.8:5061]
    method = TLSv1.2
    verify_client = optional_no_ca
    ...

## `provider_quirks` (integer)

Reload a provider in the child - needed in MP-mode only (tcp_main_threads = 0) for some providers. The configuration file for the provider is provided in the `provider_quirks_config` parameter. Should be 0 in MT-mode.

- 0 - no reload (default)

- 1 - reloads a provider in a new library context in the child. pkcs11-provider is known to require this.

### Set `provider_quirks` modparam parameter

    ...
    modparam("tls", "provider_quirks", 1)
    # 1: provider_quirks_config parameter must be set
    ...

## `provider_quirks_config` (string)

A file name of a OpenSSL configuration snippet that contains the provider configuration. The file must contain two mandatory keys: `quirks_sect` - section to load, `quirks_provider` - the provider to load.

### Set `provider_quirks_config` modparam parameter

    ...
    modparam("tls", "provider_quirks_config", "/etc/kamailio/tls/pkcs11-provider.cnf")
    ...

A provider example:

    # /etc/kamailio/tls/pkcs11-provider.cnf
    quirks_sect = pkcs11_sect
    quirks_provider = pkcs11

    [pkcs11_sect]
    module = pkcs11.so
    pkcs11-module-path = /usr/lib64/libsoftokn3.so
    pkcs11-module-init-args = configDir=/etc/kamailio/certs/tokens
    pkcs11-module-token-pin = file:/etc/kamailio/certs/pinfile-softoken.txt
    pkcs11-module-quirks = no-deinit no-operation-state
    activate = 1

## `keylog_mode` (int)

Control the TLS key logging functionality, available for libssl version greater than 1.1.0. Its value is composed from bitwise values (can be made as sum of them):

- 0 - keys logging not enabled

- 1 (bit 1) - initialise keys logging

- 2 (bit 2) - keys logging active

- 4 (bit 3) - write keys to NOTICE log

- 8 (bit 4) - write keys to file

- 16 (bit 5) - send keys to udp peer

- 1024 (bit 11) - enable filtering of keys logging. When set, filtering is done on: "CLIENT_RANDOM", "CLIENT_HANDSHAKE_TRAFFIC_SECRET", "SERVER_HANDSHAKE_TRAFFIC_SECRET", "EXPORTER_SECRET", "CLIENT_TRAFFIC_SECRET_0", "SERVER_TRAFFIC_SECRET_0"

Bit position is the index starting from 1 (practically a non-zero value is (2 power (bitpos - 1)) ).

The default value: 0.

### Set `keylog_mode` parameter

    ...
    modparam("tls", "keylog_mode", 15)
    ...

## `keylog_file` (str)

Path to the file where to write the TLS keys. The values are appended to the content of the file. The value 8 (bit 4) has to be set to keylog_mode parameter.

The default value: NULL.

### Set `keylog_file` parameter

    ...
    modparam("tls", "keylog_file", "/tmp/kamailio-tls-keylog.txt")
    ...

## `keylog_peer` (str)

Address of the peer where to send the keys log. It has to be in the format "proto:ip:port". Only "udp" protocol (proto) is supported. The value 16 (bit 5) has to be set to keylog_mode parameter.

The default value: NULL.

### Set `keylog_peer` parameter

    ...
    modparam("tls", "keylog_peer", "udp:127.0.0.1:8020")
    ...