Debian Codegraph @

src/modules/auth_xkeys/README

raw
1 AUTH_XKEYS Module
2
3 Daniel-Constantin Mierla
4
5 <[email protected]>
6
7 Edited by
8
9 Daniel-Constantin Mierla
10
11 <[email protected]>
12
13 Copyright © 2015 asipto.com
14 __________________________________________________________________
15
16 Table of Contents
17
18 1. Admin Guide
19
20 1. Overview
21 2. Dependencies
22
23 2.1. Kamailio Modules
24 2.2. External Libraries or Applications
25
26 3. Parameters
27
28 3.1. xkey (str)
29
30 4. Functions
31
32 4.1. auth_xkeys_add(hdr, kid, alg, data)
33 4.2. auth_xkeys_check(hdr, kid, alg, data)
34
35 List of Examples
36
37 1.1. Set xkey parameter
38 1.2. auth_xkeys_add usage
39 1.3. auth_xkeys_check usage
40
41 Chapter 1. Admin Guide
42
43 Table of Contents
44
45 1. Overview
46 2. Dependencies
47
48 2.1. Kamailio Modules
49 2.2. External Libraries or Applications
50
51 3. Parameters
52
53 3.1. xkey (str)
54
55 4. Functions
56
57 4.1. auth_xkeys_add(hdr, kid, alg, data)
58 4.2. auth_xkeys_check(hdr, kid, alg, data)
59
60 1. Overview
61
62 This module provides a custom mechanism to authenticate a SIP entity
63 using a list of shared keys.
64
65 It is similar to the API key based authentication used by many web
66 services. In short, the sender adds a particular header with a hash
67 token computed with the shared key and some values from the SIP request
68 (e.g., local IP, From/To/R-URI username, Call-ID, CSeq). The receiver
69 will check the hash value and decide whether the SIP message is
70 authenticated or not. The sender and receiver have to agree beforehand
71 on the name of the server, shared secret, algorithm to be used and what
72 data is going to be hashed.
73
74 The module is designed to work with many shared keys on the same group,
75 for more flexibility in adding/removing keys. The last added key in the
76 group is used to add the header, but older ones are used for matching
77 the hash value. That allows to change the active shared key without
78 affecting ongoing traffic. If one decides to use a new share key, add
79 it first to receiver (it will still authenticate with older key) and
80 then to the sender. Once both nodes are provisioned with the new key,
81 the older one can be removed.
82
83 For proper protection, it is recommended to use this authentication
84 mechanism over a secure channel (e.g., TLS, VPN, private network).
85
86 The benefit is avoiding the extra traffic and processing required by
87 WWW-Digest authentication schema (no more 401/407 and a follow up
88 request with credentials).
89
90 Another goal is to provide more elasticity for scalability needs of the
91 core SIP network nodes. Most of the nodes in the core network or the
92 interconnecting peers trust each other based on IP address. But adding
93 a new node requires updates to the exiting ones to trust the IP address
94 of the new node. On large deployments, that can become rather complex.
95 For example, as a replacement for IP trust relationships, the sender
96 can hash the local IP with the secret shared key, add it in the header
97 and the receiver will check if the source ip hashed with the key
98 results in the same value.
99
100 Not being a challenge-reply mechanism, this can be used to authenticate
101 SIP responses from trusted peers.
102
103 2. Dependencies
104
105 2.1. Kamailio Modules
106 2.2. External Libraries or Applications
107
108 2.1. Kamailio Modules
109
110 The following modules must be loaded before this module:
111 * none.
112
113 2.2. External Libraries or Applications
114
115 The following libraries or applications must be installed before
116 running Kamailio with this module loaded:
117 * none
118
119 3. Parameters
120
121 3.1. xkey (str)
122
123 3.1. xkey (str)
124
125 Specify the attributes for a shared secret. The value is in the format
126 'name1=value1;name2=value2;...'. The attributes can be:
127 * id - the id of the group for keys
128 * name - the name of the key within group
129 * value - the value of the key
130 * expires - expiration time (seconds)
131
132 Default value is empty.
133
134 Example 1.1. Set xkey parameter
135 ...
136 modparam("auth_xkeys", "xkey", "id=abc;name=xyz;value=secret;expires=72000")
137 ...
138
139 4. Functions
140
141 4.1. auth_xkeys_add(hdr, kid, alg, data)
142 4.2. auth_xkeys_check(hdr, kid, alg, data)
143
144 4.1. auth_xkeys_add(hdr, kid, alg, data)
145
146 Add a header computed with the first key in the group kid, hashing with
147 algorithm alg over the content of parameter data. The parameters can
148 include variables.
149
150 The algorithm can be: sha256, sha384, sha512.
151
152 This function can be used from ANY_ROUTE.
153
154 Example 1.2. auth_xkeys_add usage
155 ...
156 auth_xkeys_add("X-My-Key", "abc", "sha256", "$Ri:$fu:$ru:$hdr(CSeq)");
157 ...
158
159 4.2. auth_xkeys_check(hdr, kid, alg, data)
160
161 Check if the value of header hdr matches the value computed with the
162 first key in the group kid, hashing with algorithm alg over the content
163 of parameter data. The parameters can include variables.
164
165 The algorithm can be: sha256, sha384, sha512.
166
167 Note that the header is not removed by the function, it is recommended
168 to remove it if sending to untrusted destination.
169
170 This function can be used from ANY_ROUTE.
171
172 Example 1.3. auth_xkeys_check usage
173 ...
174 if(!auth_xkeys_check("X-My-Key", "abc", "sha256", "$si:$fu:$ru:$hdr(CSeq)")) {
175 send_reply("403", "Forbidden");
176 exit;
177 }
178 remove_hf("X-My-Key");
179 ...