Andrei
Pelinescu-Onciul
iptelorg GmbH

    			andrei@iptel.org

2007
iptelorg GmbH
$Revision: 1.3 $
$Date: 2007/02/28 01:38:48 $

# TLS Module

## Overview

This module implements the TLS transport for ser using the openssl library (http://www.openssl.org). To enable the TLS support this module must be loaded and enable_tls=yes must be added to the ser config file

## Quick Start

Make sure you have a proper certificate and private key and either use the certificate and private_key module parameters, or make sure the certificate and key are in the same PEM file, named cert.pem an placed in [your-cfg-install-prefix]/etc/ser/. Don't forget to load the tls module and to enable tls (add enable_tls=yes to your config).

### quick start config

    #...
    loadmodule "modules/tls/tls.so"

    modparam("tls", "private_key", "./andrei-test.pem")
    modparam("tls", "certificate", "./andrei-test.pem")
    modparam("tls", "ca_list", "./calist.pem")

    enable_tls=yes

    route{
    	# ....
    }

## Important Notes

The tls module needs some special options enabled when compiling ser. These options are enabled by default, however in case you're using a modified ser version or Makefile, make sure that you enable -DUSE_TLS and -DTLS_HOOKS (or compile with make TLS_HOOKS=1 which will take care of both options). To quickly check if your ser version was compiled with these options, run ser -V and look for USE_TLS and TLS_HOOKS among the flags.

This module includes several workarounds for various openssl bugs (like compression and kerberos using the wrong memory allocations functions, low memory problems a.s.o). On startup it will try to enable the needed workarounds based on the openssl library version. Each time a known problem is detected and a workaround is enabled, a message will be logged. In general it is recommended to compile this module on the same machine or a similar machine to where ser will be run or to link it statically with libssl. For example if on the compile machine openssl does not have the kerberos support enabled, but on the target machine a kerberos enabled openssl library is installed, ser cannot apply the needed workarounds and will refuse to start. The same thing will happen if the openssl versions are too different (to force ser startup anyway, see the `tls_force_run` module parameter).

Try to avoid using keys larger then 1024 bytes. Large keys significantly slow down the TLS connection handshake, thus limiting the maximum ser TLS connection rate.

Compression is fully supported and used by default, if you have a new enough openssl version (starting with 0.9.8). Although there are some problems with zlib compression in currently deployed openssl versions (up to and including 0.9.8d, see openssl bug #1468), the tls module will automatically switch to its own fixed version. There's no need to force-disable the compression.

The tls module includes workarounds for the following known openssl bugs: openssl #1204 (disable SS_OP_TLS_BLOCK_PADDING_BUG if compression is enabled, for versions between 0.9.8 and 0.9.8c), openssl #1468 (fix zlib compression memory allocation), openssl #1467 (kerberos support will be disabled if the openssl version is less than 0.9.8e-beta1) and openssl #1491 (stop using tls in low memory situations due to the very high risk of openssl crashing or leaking memory). The bug reports can be viewed at http://rt.openssl.org/.

## Compiling the TLS Module

In most case compiling the TLS module is as simple as:

    make modules modules=modules/tls

or

    cd modules/tls
    make

or (compiling whole ser and the tls module)

    make all include_modules=tls

.

However in some cases the openssl library requires linking with other libraries. For example compiling the openssl library with kerberos and zlib-shared support will require linking the tls module with libkrb5 and libz. In this case just add TLS_EXTRA_LIBS="library list" to make's command line. E.g.:

    make TLS_EXTRA_LIBS="-lkrb5 -lz" all include_modules=tls

In general, if ser fails to start with a symbol not found error when trying to load the tls module (check the log), it means some needed library was not linked and it must be added to TLS_EXTRA_LIBS

## TLS and Low Memory

The openssl library doesn't handle very well low memory situations. If memory allocations start to fail (due to memory shortage), openssl can crash or cause memory leaks (making the memory shortage even worse). As of this writing all openssl versions were affected (includind 0.9.8e), see openssl bug #1491. The tls module has some workarounds for preventing this problem (see `low_mem_treshold1` and `low_mem_threshold2`), however starting ser with enough shared memory is higly recommended. When this is not possible a quick way to significantly reduce openssl memory usage it to disable compression (see `tls_disable_compression`).

## Known Limitations

The private key must not encrypted (ser cannot ask you for a password on startup).

The tls certificate verifications ignores the certificate name, altname and ip extensions, it just checks if the certificate is signed by a recognized CA. One can use the select framework to try to overcome this limitation (check in the script for the contents of various certificate fields), but this is not only slow, but also not exactly standard conforming (the verification should happen during TLS connection establishment and not after).

TLS specific config reloading is not safe, so for now better don't use it, especially under heavy traffic.

This documentation is incomplete. The select framework and rpc sections are completely missing.