Gergely
Kovacs
Iptel.org

    		    gergo@iptel.org

2007
Iptel.org

# Auth Identity Module

## Overview

Auth Identity module provides functionalities for securely identifying originators of SIP messages. This module has two basic service:

- authorizer - authorizes a message and adds Identity and Identity-Info headers

- verifier - verifies an authorized message

Known limitations in this version:

- authorizer and verifier support only SIP requests except for CANCEL and REGISTER

- verifier does not support the subjectAltName extension of certificates

## Dependencies

This module does not depend any other module.

## Compilation

This module needs the following headers and libraries:

- OpenSSL (version 0.9.8 or higher) for cryptographic functions

- libcURL for HTTP, HTTPS functions

If you'd like to use TLS module too then use the corresponding LIB line in auth_identity's Makefile

## Installation And Running

Authorizer service needs an opportunity to make the public key, which conveyed in a certificate, available over HTTPS or HTTP for verifiers. The domain the authorizer is responsible for and the domain part of the URL of the certificate must be the same. This service needs its private key too.

## Authorizer service parameters

### `privatekey_path` (string)

The path of private key of the authentication service. The key must be in PEM format.

This parameter is required by authentication service.

#### Set `privatekey_path` parameter

    ...
    modparam("auth_identity","privatekey_path","/etc/ssl/private/key.pem")
    ...

### `certificate_path` (string)

The path of certificate of the authentication service. The certificate must be in PEM format.

This parameter is required by authentication service.

#### Set `certificate_path` parameter

    ...
    modparam("auth_identity","certificate_path","/var/www/ssl/mycert.pem")
    ...

### `certificate_url` (string)

The url where certificate is available for other verifier services. (value of Identity-info header) The certificate should be in DER format.

This parameter is required by authentication service.

#### Set `certificate_url` parameter

    ...
    modparam("auth_identity","certificate_url","https://foo.bar/mycert.der")
    ...

### `msg_timeout` (integer)

If the Date header of message which is needed to be authenticated contains a time different by more than this seconds from the current time noted by the authentication service then it rejects the message.

This parameter is optional. The default value is "600".

#### Set `msg_timeout` parameter

    ...
    modparam("auth_identity","msg_timeout",600)
    ...

## Authorizer service functions

### `auth_date_proc()`

If a message, the auth service should authorize, contains Date header then this function checks whether it falls in message timeout (set by msg_timeout parameter). If there is not any Date header then adds one. This function also checks whether the certificate of auth service (set by certificate_path parameter) has not been expired.

#### Dependencies

No dependencies

### `auth_add_identity()`

Assembles digest-string from the message, calculates its SHA1 hash, encrypt it with the private key (set by privatekey_path parameter) of authorizer service, base64 encodes it and adds to the outgoing message as the value of Identity header. This function also adds Identity-Info header which contains an URI (set by certificate_url parameter) from which the certificate of auth service can be acquired.

Note: this function needs the final outgoing message for authorization, so no module may modify any digest string related headers (From, To, Call-ID, CSeq, Date, Contact) and body after auth_add_identity()'s been called

#### Dependencies

auth_date_proc() must be called before

## Authorizer service examples

    ...
    route[INIT]
    {
    	# we process new transactions only
    	if (!t_newtran()) {
    		sl_reply("500", "Internal error newtran");
    		drop;
    	}
    ...
    route[OUTBOUND]
    {
    	# If we are responsible for the domain of the sender of this message
    	if ($f.did && !$t.did) {
    		# Authentication service
    		if (method=="INVITE" || method=="BYE"
    			|| method=="OPTION" || method=="ACK") {
    			# Identity and Identity-info headers must not exist
    			if (@identity) {
    				t_reply("403", "Invalid Identity header");
    				drop;
    			}
    			if (@identity_info) {
    				t_reply("403", "Invalid Identity-info header");
    				drop;
    			}

    			if (!auth_date_proc()) {
    				t_reply("403", "Invalid Date value");
    				drop;
    			}

    			if (!auth_add_identity()) {
    				t_reply("480", "Authentication error");
    				drop;
    			}
    		}
    		route(FORWARD);
    	}
    }
    ...

## Verifier service parameters

### `auth_validity_time` (integer)

The validity time of an authenticated message. The message will be refused if it contains a time different by more than this seconds from the current time noted by the verification service.

This parameter is optional. The default value is "3600".

#### Set `auth_validity_time` parameter

    ...
    modparam("auth_identity","auth_validity_time",3600)
    ...

### `callid_cache_limit` (integer)

The number of Call-IDs stored in order to recognize call replay attacks. A Call-ID is stored `auth_validity_time` long and uses approximately 100 bytes memory.

This parameter is optional. The default value is "32768". (you should increase the size of shared memory with -m command line switch if you liked to store more callid than 10000)

#### Set `auth_validity_time` parameter

    ...
    modparam("auth_identity","callid_cache_limit",32768)
    ...

### `certificate_cache_limit` (integer)

The number of certificates stored in order to avoid needless download. A certificate is stored until its expiration date and uses approximately 600 bytes memory.

This parameter is optional. The default value is "4096".

#### Set `certificate_cache_limit` parameter

    ...
    modparam("auth_identity","certificate_cache_limit",4096)
    ...

### `cainfo_path` (string)

A file of trusted certificates. The file should contain multiple certificates in PEM format concatenated together. It could be useful for verifying a certificate not signed by a trusted CA.

This parameter is optional. It has not got default value.

#### Set `cainfo_path` parameter

    ...
    modparam("auth_identity","cainfo_path","/etc/ssl/certs/ca-certificates.crt")
    ...

### `accept_pem_certs` ([0|1])

Enables the acquired certificate processing if it is in PEM format.

This parameter is optional. The default value is "0".

#### Set `accept_pem_certs` parameter

    ...
    modparam("auth_identity","accept_pem_certs",1)
    ...

## Verifier service functions

### `vrfy_check_date()`

Checks Date header of the incoming message whether falls in validity time (set by auth_validity_time parameter)

#### Dependencies

No dependencies

### `vrfy_get_certificate()`

Tries to get certificate defined by the value of Identity-info header from certificate table (which size is set by certificate_cache_limit parameter). If the required certificate is not found there then this function downloads it.

#### Dependencies

No dependencies

### `vrfy_check_certificate()`

Checks whether the downloaded certificate is valid (is not expired, its subject and the domain part of the URL are the same) and adds it to certificate table.

#### Dependencies

vrfy_get_certificate() must be called before

### `vrfy_check_msgvalidity()`

Assembles digest-string from the message, create SHA1 hash and compares it with the decrypted value of Identity header.

#### Dependencies

vrfy_get_certificate() must be called before and vrfy_check_certificate() should be called before

### `vrfy_check_callid()`

Checks whether the current call's been already processed in validity time (set by auth_validity_time) to recognize call replay attacks. If this call (identified by Call-id, Cseq, and tag of From header triple) has not been replayed then adds it to callid table (which size is set by callid_cache_limit parameter).

#### Dependencies

This function should be called for the last time.

## Verifier service examples

    ...
    route[INIT]
    {
    	# we process new transactions only
    	if (!t_newtran()) {
    		sl_reply("500", "Internal error newtran");
    		drop;
    	}
    ...
    route[VERIFY]
    {
    	# if we've already processed this message then we drop it
    	if (!t_newtran()) {
    		sl_reply("500", "Internal error newtran");
    		drop;
    	}

    	if (method=="INVITE" || method=="BYE"
    		|| method=="OPTION" || method=="ACK") {
    		# Identity and Identity-info are required for verification
    		if (!@identity) {
    			t_reply("428", "Use Identity Header");
    			drop;
    		}
    		if (!@identity_info) {
    			t_reply("436", "Bad Identity-Info");
    			drop;
    		}

    		if (!vrfy_check_date()) {
    			t_reply("403", "Outdated Date header value");
    			drop;
    		}

    		if (!vrfy_get_certificate()) {
    			t_reply("436", "Bad Identity-Info");
    			drop;
    		}

    		if (!vrfy_check_certificate()) {
    			t_reply("437", "Unsupported Certificate");
    			drop;
    		}

    		if (!vrfy_check_msgvalidity()) {
    			t_reply("438", "Invalid Identity Header");
    			drop;
    		}

    		if (!vrfy_check_callid()) {
    			t_reply("403", "Message is replayed");
    			drop;
    		}
    	}
    }
    ...