Debian Codegraph @

src/modules/auth_ephemeral/README

raw
1 Auth_ephemeral Module
2
3 Peter Dunkley
4
5 Crocodile RCS Ltd
6 <[email protected]>
7
8 Carsten Bock
9
10 ng-voice GmbH
11 <[email protected]>
12
13 Copyright © 2013 Crocodile RCS Ltd
14
15 Copyright © 2017 ng-voice GmbH
16 __________________________________________________________________
17
18 Table of Contents
19
20 1. Admin Guide
21
22 1. Overview
23
24 1.1. How ephemeral credentials work
25
26 1.1.1. Request
27 1.1.2. Response
28
29 2. Dependencies
30
31 2.1. Kamailio Modules
32 2.2. External Libraries or Applications
33
34 3. Parameters
35
36 3.1. secret (string)
37 3.2. username_format (integer)
38 3.3. sha_algorithm (integer)
39
40 4. Functions
41
42 4.1. autheph_proxy(realm)
43 4.2. autheph_www(realm[, method])
44 4.3. autheph_check(realm)
45 4.4. autheph_authenticate(username, password)
46 4.5. autheph_check_from([username])
47 4.6. autheph_check_to([username])
48 4.7. autheph_check_timestamp(username)
49
50 5. RPC Commands
51
52 5.1. autheph.add_secret
53 5.2. autheph.dump_secrets
54 5.3. autheph.rm_secret
55
56 List of Examples
57
58 1.1. Request example
59 1.2. Response example
60 1.3. secret parameter usage
61 1.4. username_format parameter usage
62 1.5. sha_algorithm parameter usage
63 1.6. autheph_proxy usage
64 1.7. autheph_www usage
65 1.8. autheph_check usage
66 1.9. autheph_authenticate usage
67 1.10. autheph_check_from usage
68 1.11. autheph_check_to usage
69 1.12. autheph_check_timestamp usage
70
71 Chapter 1. Admin Guide
72
73 Table of Contents
74
75 1. Overview
76
77 1.1. How ephemeral credentials work
78
79 1.1.1. Request
80 1.1.2. Response
81
82 2. Dependencies
83
84 2.1. Kamailio Modules
85 2.2. External Libraries or Applications
86
87 3. Parameters
88
89 3.1. secret (string)
90 3.2. username_format (integer)
91 3.3. sha_algorithm (integer)
92
93 4. Functions
94
95 4.1. autheph_proxy(realm)
96 4.2. autheph_www(realm[, method])
97 4.3. autheph_check(realm)
98 4.4. autheph_authenticate(username, password)
99 4.5. autheph_check_from([username])
100 4.6. autheph_check_to([username])
101 4.7. autheph_check_timestamp(username)
102
103 5. RPC Commands
104
105 5.1. autheph.add_secret
106 5.2. autheph.dump_secrets
107 5.3. autheph.rm_secret
108
109 1. Overview
110
111 1.1. How ephemeral credentials work
112
113 1.1.1. Request
114 1.1.2. Response
115
116 This module contains all authentication related functions that can work
117 with ephemeral credentials. This module can be used together with the
118 auth module for digest authentication. Use this module if you want to
119 use ephemeral credentials instead of ordinary usernames and passwords.
120
121 1.1. How ephemeral credentials work
122
123 Ephemeral credentials are generated by a web-service and enforced on
124 Kamailio. This use of ephemeral credentials ensures that access to
125 Kamailio is controlled even if the credentials cannot be kept secret,
126 as can be the case in WebRTC where the credentials may be specified in
127 Javascript.
128
129 The only interaction needed between the web-service and Kamailio is to
130 share a secret key.
131
132 Credentials will typically be requested from the web-service using an
133 HTTP POST and provided in a HTTP response with a content-type of
134 "application/json". To prevent unauthorised use the HTTP requests can
135 be ACLd by various means.
136
137 This mechanism is based on draft-uberti-rtcweb-turn-rest.
138
139 1.1.1. Request
140
141 The request to the web-service should contain the following parameters:
142 * service - specifies the desired service (msrp, sip, etc)
143 * username - an optional user identifier for the service (as would
144 normally be found in the username parameter of an Authorization: or
145 Proxy-Authorization: header)
146 * key - an optional API key used for authentication
147
148 Example 1.1. Request example
149 POST /?service=sip&[email protected]
150
151 1.1.2. Response
152
153 The response should include the following parameters:
154 * username - the username to use, which is a colon-delimited
155 combination of the expiration timestamp and the username parameter
156 from the request (if specified). When used with this module the
157 timestamp must be a UNIX timestamp.
158 * password - the password to use; this value is computed from the
159 secret key and the returned username value, by performing
160 base64(hmac-sha1(secret key, returned username)).
161 * ttl - the duration for which the username and password are valid,
162 in seconds.
163 * uris - an array of URIs indicating servers that the username and
164 password are valid for.
165
166 Example 1.2. Response example
167 {
168 "username" : "1234567890:[email protected]",
169 "password" : "asdfghjklauio=",
170 "ttl" : 86400,
171 "uris" : [
172 "sip:1.2.3.4;transport=ws",
173 "sip:5.6.7.8;transport=ws"
174 ]
175 }
176
177 2. Dependencies
178
179 2.1. Kamailio Modules
180 2.2. External Libraries or Applications
181
182 2.1. Kamailio Modules
183
184 The module must be loaded before this module:
185 * auth (optional).
186
187 2.2. External Libraries or Applications
188
189 The following libraries must be installed before running Kamailio with
190 this module loaded:
191 * OpenSSL.
192
193 3. Parameters
194
195 3.1. secret (string)
196 3.2. username_format (integer)
197 3.3. sha_algorithm (integer)
198
199 3.1. secret (string)
200
201 The shared secret to use for generating credentials. This parameter can
202 be set multiple times - this enables the secret used for new
203 credentials to be changed without causing existing credentials to stop
204 working. The last secret set is the first that will be tried.
205
206 Example 1.3. secret parameter usage
207 ...
208 modparam("auth_ephemeral", "secret", "kamailio_rules")
209 ...
210
211 3.2. username_format (integer)
212
213 The format of the username in the web-service response.
214
215 * 0 (deprecated - pre IETF draft format) - <username parameter from
216 the request>:<timestamp>
217 * 1 (default - IETF draft format) - <timestamp>:<username parameter
218 from the request>
219
220 Example 1.4. username_format parameter usage
221 ...
222 modparam("auth_ephemeral", "username_format", 0)
223 ...
224
225 3.3. sha_algorithm (integer)
226
227 The SHA algorithm to be used for the Hash.
228
229 * 0 - SHA1 (default, as per IETF/RFC)
230 * 1 - SHA256
231 * 2 - SHA384
232 * 3 - SHA512
233
234 Example 1.5. sha_algorithm parameter usage
235 ...
236 modparam("auth_ephemeral", "sha_algorithm", 2)
237 ...
238
239 4. Functions
240
241 4.1. autheph_proxy(realm)
242 4.2. autheph_www(realm[, method])
243 4.3. autheph_check(realm)
244 4.4. autheph_authenticate(username, password)
245 4.5. autheph_check_from([username])
246 4.6. autheph_check_to([username])
247 4.7. autheph_check_timestamp(username)
248
249 4.1. autheph_proxy(realm)
250
251 This function performs proxy authentication.
252
253 Note
254
255 This function can only be used when the auth module is loaded before
256 this module.
257
258 The meaning of the parameters are as follows:
259 * realm - realm is an opaque string that the user agent should
260 present to the user so that he can decide what username and
261 password to use. Usually this is domain of the host the server is
262 running on.
263 It must not be an empty string “”. Apart from a static string, a
264 typical value is the From-URI domain (i.e., $fd).
265 The string may contain pseudo variables.
266
267 This function can be used from REQUEST_ROUTE.
268
269 Example 1.6. autheph_proxy usage
270 ...
271 if (!autheph_proxy("$fd")) {
272 auth_challenge("$fd", "1");
273 exit;
274 }
275 ...
276
277 4.2. autheph_www(realm[, method])
278
279 This function performs WWW digest authentication.
280
281 Note
282
283 This function can only be used when the auth module is loaded before
284 this module.
285
286 The meaning of the parameters are as follows:
287 * realm - realm is an opaque string that the user agent should
288 present to the user so that he can decide what username and
289 password to use. Usually this is domain of the host the server is
290 running on.
291 It must not be an empty string “”. Apart from a static string, a
292 typical value is the From-URI domain (i.e., $fd).
293 The string may contain pseudo variables.
294 * method - the method to be used for authentication. This parameter
295 is optional and if not set the first "word" on the request-line is
296 used.
297
298 This function can be used from REQUEST_ROUTE.
299
300 Example 1.7. autheph_www usage
301 ...
302 if (!autheph_www("$fd")) {
303 auth_challenge("$fd", "1");
304 exit;
305 }
306 ...
307
308 4.3. autheph_check(realm)
309
310 This function combines the functionalities of autheph_www and
311 autheph_proxy, the first being executed if the SIP request is a
312 REGISTER, the second for the rest.
313
314 Note
315
316 This function can only be used when the auth module is loaded before
317 this module.
318
319 The meaning of the parameters are as follows:
320 * realm - realm is an opaque string that the user agent should
321 present to the user so that he can decide what username and
322 password to use. Usually this is domain of the host the server is
323 running on.
324 It must not be an empty string “”. Apart from a static string, a
325 typical value is the From-URI domain (i.e., $fd).
326 The string may contain pseudo variables.
327
328 This function can be used from REQUEST_ROUTE.
329
330 Example 1.8. autheph_check usage
331 ...
332 if (!autheph_check("$fd")) {
333 auth_challenge("$fd", "1");
334 exit;
335 }
336 ...
337
338 4.4. autheph_authenticate(username, password)
339
340 This function performs non-digest ephemeral authentication. This may be
341 used when digest authentication cannot. For example, during WebSocket
342 handshake the username may be part of the requested URI and the
343 password presented in a Cookie: header.
344
345 Note
346
347 This function may be used without loading the auth module.
348
349 The meaning of the parameters are as follows:
350 * username - the username returned in the response from the
351 web-service.
352 * password - the password returned in the response from the
353 web-service.
354
355 This function can be used from REQUEST_ROUTE.
356
357 Example 1.9. autheph_authenticate usage
358 ...
359 if (!autheph_authenticate("$var(username)", "$var(password)")) {
360 sl_send_reply("403", "Forbidden");
361 exit;
362 }
363 ...
364
365 4.5. autheph_check_from([username])
366
367 This function checks that the username (or username and domain) in the
368 From: URI matches the credentials.
369
370 When used without the username parameter it compares the From: URI with
371 the credentials used to authenticate the request (in the Authorization:
372 or Proxy-Authorization: headers).
373
374 The username parameter can be used to check the From: when individual
375 SIP requests are not authenticated (for example, when they are over
376 WebSockets and the connection was authenticated during the handshake).
377 In this scenario the username should be cached (perhaps in a
378 hash-table) at the point the authentication occurs.
379
380 Note
381
382 This function must have the optional username parameter specified to
383 use it without loading the auth module before this module.
384
385 The meaning of the parameters are as follows:
386 * username (optional) - the username returned in the response from
387 the web-service.
388
389 This function can be used from REQUEST_ROUTE.
390
391 Example 1.10. autheph_check_from usage
392 ...
393 if (!autheph_check_from()) {
394 sl_send_reply("403", "Forbidden");
395 exit;
396 }
397 ...
398
399 4.6. autheph_check_to([username])
400
401 This function checks that the username (or username and domain) in the
402 To: URI matches the credentials.
403
404 When used without the username parameter it compares the To: URI with
405 the credentials used to authenticate the request (in the Authorization:
406 or Proxy-Authorization: headers).
407
408 The username parameter can be used to check the From: when individual
409 SIP requests are not authenticated (for example, when they are over
410 WebSockets and the connection was authenticated during the handshake).
411 In this scenario the username should be cached (perhaps in a
412 hash-table) at the point the authentication occurs.
413
414 Note
415
416 This function must have the optional username parameter specified to
417 use it without loading the auth module before this module.
418
419 The meaning of the parameters are as follows:
420 * username (optional) - the username returned in the response from
421 the web-service.
422
423 This function can be used from REQUEST_ROUTE.
424
425 Example 1.11. autheph_check_to usage
426 ...
427 if (!autheph_check_to()) {
428 sl_send_reply("403", "Forbidden");
429 exit;
430 }
431 ...
432
433 4.7. autheph_check_timestamp(username)
434
435 This function checks that the timestamp in the username parameter has
436 not expired. The autheph_(check|proxy|www) functions all do this
437 automatically, but in a scenario when individual SIP requests are not
438 authenticated (for example, when they are over WebSockets and the
439 connection was authenticated during the handshake) you may want to
440 re-check for each new out-of-dialog request. In this scenario the
441 username should be cached (perhaps in a hash-table) at the point
442 authentication occurs.
443
444 Note
445
446 This function may be used without loading the auth module.
447
448 The meaning of the parameters are as follows:
449 * username - the username returned in the response from the
450 web-service.
451
452 This function can be used from REQUEST_ROUTE.
453
454 Example 1.12. autheph_check_timestamp usage
455 ...
456 if (!autheph_check_timestamp("$var(username)")) {
457 sl_send_reply("403", "Forbidden");
458 exit;
459 }
460 ...
461
462 5. RPC Commands
463
464 5.1. autheph.add_secret
465 5.2. autheph.dump_secrets
466 5.3. autheph.rm_secret
467
468 5.1. autheph.add_secret
469
470 Add a secret to the head of the shared secret list. The secret will be
471 the first one tried during future authentication attempts. This command
472 allows you to update the shared secret list without having to restart
473 Kamailio.
474
475 Note
476
477 If you want your new shared secret list to persist across restarts you
478 must add it to your Kamailio configuration file.
479
480 Name: autheph.add_secret
481
482 Parameters:
483 * secret
484
485 RPC Command Example:
486 ...
487 kamctl rpc autheph.add_secret mysecret
488
489 5.2. autheph.dump_secrets
490
491 Dump the set of shared secrets.
492
493 Name: autheph.dump_secrets
494
495 Parameters:
496 * none
497
498 RPC Command Example:
499 ...
500 kamctl rpc autheph.dump_secrets
501 ...
502
503 5.3. autheph.rm_secret
504
505 Remove the secret with the specified integer ID. This command allows
506 you to update the shared secret list without having to restart
507 Kamailio.
508
509 Note
510
511 If you want your new shared secret list to persist across restarts you
512 must add it to your Kamailio configuration file.
513
514 Name: autheph.rm_secret
515
516 Parameters:
517 * ID - the ID of the secret to remove
518
519 RPC Command Example:
520 ...
521 kamctl rpc autheph.rm_secret 0
522 ...