Debian Codegraph @

src/modules/secsipid/README

raw
1 SecSIPId Module
2
3 Daniel-Constantin Mierla
4
5 asipto.com
6 <[email protected]>
7
8 Edited by
9
10 Daniel-Constantin Mierla
11
12 <[email protected]>
13
14 Copyright © 2020 http://www.asipto.com
15 __________________________________________________________________
16
17 Table of Contents
18
19 1. Admin Guide
20
21 1. Overview
22 2. Dependencies
23
24 2.1. Kamailio Modules
25 2.2. External Libraries or Applications
26
27 3. Parameters
28
29 3.1. expire (int)
30 3.2. timeout (int)
31 3.3. cache_dir (str)
32 3.4. cache_expire (int)
33 3.5. modproc (str)
34 3.6. libopt (str)
35
36 4. Functions
37
38 4.1. secsipid_check_identity(keyPath)
39 4.2. secsipid_check_identity_pubkey(pubkeyVal)
40 4.3. secsipid_check(sIdentity, keyPath)
41 4.4. secsipid_verify(sIdentity, keyVal, opts)
42 4.5. secsipid_get_url(url, ovar)
43 4.6. secsipid_add_identity(origTN, destTN, attest, origID,
44 x5u, keyPath)
45
46 4.7. secsipid_build_identity(origTN, destTN, attest, origID,
47 x5u, keyPath)
48
49 4.8. secsipid_build_identity_prvkey(origTN, destTN, attest,
50 origID, x5u, keyData)
51
52 4.9. secsipid_sign(sheaders, spaypload, keyPath)
53 4.10. secsipid_sign_prvkey(sheaders, spaypload, keyData)
54
55 5. Installation
56
57 List of Examples
58
59 1.1. Set expire parameter
60 1.2. Set timeout parameter
61 1.3. Set cache_dir parameter
62 1.4. Set cache_expire parameter
63 1.5. Set modproc parameter
64 1.6. Set libopt parameter
65 1.7. secsipid_check_identity usage
66 1.8. secsipid_check_identity_pubkey usage
67 1.9. secsipid_check usage
68 1.10. secsipid_verify usage
69 1.11. secsipid_get_url usage
70 1.12. secsipid_add_identity usage
71 1.13. secsipid_build_identity usage
72 1.14. secsipid_build_identity_prvkey usage
73 1.15. secsipid_sign usage
74 1.16. secsipid_sign_prvkey usage
75 1.17. Libsecsipid Usage
76
77 Chapter 1. Admin Guide
78
79 Table of Contents
80
81 1. Overview
82 2. Dependencies
83
84 2.1. Kamailio Modules
85 2.2. External Libraries or Applications
86
87 3. Parameters
88
89 3.1. expire (int)
90 3.2. timeout (int)
91 3.3. cache_dir (str)
92 3.4. cache_expire (int)
93 3.5. modproc (str)
94 3.6. libopt (str)
95
96 4. Functions
97
98 4.1. secsipid_check_identity(keyPath)
99 4.2. secsipid_check_identity_pubkey(pubkeyVal)
100 4.3. secsipid_check(sIdentity, keyPath)
101 4.4. secsipid_verify(sIdentity, keyVal, opts)
102 4.5. secsipid_get_url(url, ovar)
103 4.6. secsipid_add_identity(origTN, destTN, attest, origID, x5u,
104 keyPath)
105
106 4.7. secsipid_build_identity(origTN, destTN, attest, origID, x5u,
107 keyPath)
108
109 4.8. secsipid_build_identity_prvkey(origTN, destTN, attest,
110 origID, x5u, keyData)
111
112 4.9. secsipid_sign(sheaders, spaypload, keyPath)
113 4.10. secsipid_sign_prvkey(sheaders, spaypload, keyData)
114
115 5. Installation
116
117 1. Overview
118
119 The module implements secure SIP identity specifications - STIR (Secure
120 Telephony Identity Revisited) and SHAKEN (Signature-based Handling of
121 Asserted information using toKENs) IETF extensions for SIP (RFC8224,
122 RFC8588), known together as STIR/SHAKEN.
123
124 It exports the functions to check and generate SIP Identity header.
125
126 Note that this module needs "secsipid_proc.so" module to be installed,
127 but without loading the "secsipid_proc.so" via "loadmodule". This
128 module loads "secsipid_proc.so" in child init callback in order to
129 initialize the "libsecsipid" per child process.
130
131 The libsecsipid is provided by secsipidx project:
132 https://github.com/asipto/secsipidx.
133
134 In case of failure, the functions in this module return error codes
135 (the negative values) listed in the code of libsecsipid, pretty much at
136 the top of:
137 https://github.com/asipto/secsipidx/blob/main/secsipid/secsipid.go.
138
139 2. Dependencies
140
141 2.1. Kamailio Modules
142 2.2. External Libraries or Applications
143
144 2.1. Kamailio Modules
145
146 The following modules must be installed (but not loaded) to use this
147 module:
148 * secsipid_proc.
149
150 2.2. External Libraries or Applications
151
152 The following libraries or applications must be installed before
153 running Kamailio with this module loaded:
154 * none.
155
156 3. Parameters
157
158 3.1. expire (int)
159 3.2. timeout (int)
160 3.3. cache_dir (str)
161 3.4. cache_expire (int)
162 3.5. modproc (str)
163 3.6. libopt (str)
164
165 3.1. expire (int)
166
167 The interval in seconds after which the Identity header JWT is
168 considered to be expired.
169
170 Default value is 300.
171
172 Example 1.1. Set expire parameter
173 ...
174 modparam("secsipid", "expire", 600)
175 ...
176
177 3.2. timeout (int)
178
179 The interval in seconds after which the HTTP GET operation to download
180 the public key times out.
181
182 Default value is 5.
183
184 Example 1.2. Set timeout parameter
185 ...
186 modparam("secsipid", "timeout", 2)
187 ...
188
189 3.3. cache_dir (str)
190
191 The path to the directory where to save cached public keys. If set, it
192 activates the public key file caching in the libsecsipid library.
193
194 Default value is "".
195
196 Example 1.3. Set cache_dir parameter
197 ...
198 modparam("secsipid", "cache_dir", "/tmp/kamailio/secsipid")
199 ...
200
201 3.4. cache_expire (int)
202
203 The interval in seconds after which a cached public key is considered
204 expired. This value is passed to the libsecsipid library.
205
206 Default value is 3600.
207
208 Example 1.4. Set cache_expire parameter
209 ...
210 modparam("secsipid", "cache_expire", 7200)
211 ...
212
213 3.5. modproc (str)
214
215 The name of or the path to the required per-process API module.
216
217 Default value is "secsipid_proc.so".
218
219 Example 1.5. Set modproc parameter
220 ...
221 modparam("secsipid", "modproc", "secsipid_proc2.so")
222 ...
223
224 3.6. libopt (str)
225
226 Set a libsecsipid option. The value has to be name=value. The parameter
227 can be set many times.
228
229 Default value is "" (not set).
230
231 Example 1.6. Set libopt parameter
232 ...
233 modparam("secsipid", "libopt", "CacheExpires=0")
234 ...
235
236 4. Functions
237
238 4.1. secsipid_check_identity(keyPath)
239 4.2. secsipid_check_identity_pubkey(pubkeyVal)
240 4.3. secsipid_check(sIdentity, keyPath)
241 4.4. secsipid_verify(sIdentity, keyVal, opts)
242 4.5. secsipid_get_url(url, ovar)
243 4.6. secsipid_add_identity(origTN, destTN, attest, origID, x5u,
244 keyPath)
245
246 4.7. secsipid_build_identity(origTN, destTN, attest, origID, x5u,
247 keyPath)
248
249 4.8. secsipid_build_identity_prvkey(origTN, destTN, attest, origID,
250 x5u, keyData)
251
252 4.9. secsipid_sign(sheaders, spaypload, keyPath)
253 4.10. secsipid_sign_prvkey(sheaders, spaypload, keyData)
254
255 4.1. secsipid_check_identity(keyPath)
256
257 Check the validity of the Identity header using the public keys stored
258 in the file specified by "keyPath". If the parameter is empty, the
259 function is downloading the public key using the URL from "info"
260 parameter of the Identity header, using the value of "timeout"
261 parameter to limit the download time. The validity of the JWT body in
262 the Identity header is also checked against the "expire" parameter.
263
264 The parameters can contain pseudo-variables.
265
266 This function can be used from ANY_ROUTE.
267
268 Example 1.7. secsipid_check_identity usage
269 ...
270 request_route {
271 ...
272 if(secsipid_check_identity("/secsipid/$si/cert.pem")) { ... }
273 ...
274 if(secsipid_check_identity("")) { ... }
275 ...
276 }
277 ...
278
279 Further checks can be done with config operations, decoding the JWT
280 header and payload using {s.select} and {s.decode.base64t}
281 transformations together with jansson module.
282
283 4.2. secsipid_check_identity_pubkey(pubkeyVal)
284
285 Similar to secsipid_check_identity() with the public key value provided
286 in the parameter.
287
288 The parameters can contain pseudo-variables.
289
290 This function can be used from ANY_ROUTE.
291
292 Example 1.8. secsipid_check_identity_pubkey usage
293 ...
294 request_route {
295 ...
296 http_client_query("https://provider.com/stir-shaken/cert.pem", "$var(pubkey)")
297 ;
298 ...
299 if(secsipid_check_identity_pubkey("$var(pubkey)")) { ... }
300 ...
301 }
302 ...
303
304 4.3. secsipid_check(sIdentity, keyPath)
305
306 Check the validity of the "sIdentity" parameter using the public keys
307 stored in the file specified by "keyPath". If the keyPath parameter is
308 empty, the function is downloading the public key using the URL from
309 "info" parameter of the sIdentity, using the value of "timeout"
310 parameter to limit the download time. The validity of the JWT in the
311 sIdentity value is also checked against the "expire" parameter.
312
313 The parameters can contain pseudo-variables.
314
315 This function can be used from ANY_ROUTE.
316
317 Example 1.9. secsipid_check usage
318 ...
319 request_route {
320 ...
321 if(secsipid_check("...", "/secsipid/$si/cert.pem")) { ... }
322 ...
323 if(secsipid_check("...", "")) { ... }
324 ...
325 }
326 ...
327
328 Further checks can be done with config operations, decoding the JWT
329 header and payload using {s.select} and {s.decode.base64t}
330 transformations together with jansson module.
331
332 4.4. secsipid_verify(sIdentity, keyVal, opts)
333
334 Check the validity of the "sIdentity" parameter using the key value
335 given in the parameter "keyVal". The validity of the JWT in the
336 sIdentity value is also checked against the "expire" parameter.
337
338 The "opts" parameter provides the verify options:
339 * A (uppercase) - skip verifying the attributes in the JWT header.
340
341 The parameters can contain pseudo-variables.
342
343 This function can be used from ANY_ROUTE.
344
345 Example 1.10. secsipid_verify usage
346 ...
347 request_route {
348 ...
349 secsipid_get_url("https://provider.com/stir-shaken/cert.pem", "$var(pubkey)"
350 );
351 if(secsipid_verify("$hdr(Identity)", "$var(pubkey)", "A")) { ... }
352 ...
353 }
354 ...
355
356 Further checks can be done with config operations, decoding the JWT
357 header and payload using {s.select} and {s.decode.base64t}
358 transformations together with jansson module.
359
360 4.5. secsipid_get_url(url, ovar)
361
362 Get the content of a URL and store the result in a variable. The result
363 is cached by libsecsipid, if caching is enabled.
364
365 The url parameters can contain pseudo-variables and ovar has to be the
366 name of a writable pseudo-variable.
367
368 This function can be used from ANY_ROUTE.
369
370 Example 1.11. secsipid_get_url usage
371 ...
372 request_route {
373 ...
374 if(secsipid_get_url("https://$fd/stirshaken/cert.pem", "$var(pubkey)")) { ...
375 }
376 ...
377 }
378 ...
379
380 4.6. secsipid_add_identity(origTN, destTN, attest, origID, x5u, keyPath)
381
382 Add Identity header using the private key specified by "keyPath" to
383 sign the JWT body. If origID is empty, a UUID string is generated to
384 fill the field. The origTN represents the origination telephone number;
385 destTN represents the destination telephone number; x5u is the HTTP URL
386 referencing to the public key that should be used to verify the
387 signature; attest represents the attestation level (should be "A", "B"
388 or "C").
389
390 The parameters can contain pseudo-variables.
391
392 This function can be used from ANY_ROUTE.
393
394 Example 1.12. secsipid_add_identity usage
395 ...
396 request_route {
397 ...
398 secsipid_add_identity("$fU", "$rU", "A", "",
399 "https://kamailio.org/stir/$rd/cert.pem", "/secsipid/$rd/key.pem");
400 ...
401 }
402 ...
403
404 4.7. secsipid_build_identity(origTN, destTN, attest, origID, x5u, keyPath)
405
406 Build Identity value using the key specified by private "keyPath" to
407 sign the JWT body. If origID is empty, a UUID string is generated to
408 fill the field. The origTN represents the origination telephone number;
409 destTN represents the destination telephone number; x5u is the HTTP URL
410 referencing to the public key that should be used to verify the
411 signature; attest represents the attestation level (should be "A", "B"
412 or "C"). On success, the Indentity value is stored in variable
413 $secsipid(val). It also sets $secsipid(ret) to the return value of the
414 libsecsipid functions.
415
416 The parameters can contain pseudo-variables.
417
418 This function can be used from ANY_ROUTE.
419
420 Example 1.13. secsipid_build_identity usage
421 ...
422 request_route {
423 ...
424 if(secsipid_build_identity("$fU", "$rU", "A", "",
425 "https://kamailio.org/stir/$rd/cert.pem", "/secsipid/$rd/key.pem"))
426 {
427 xinfo("Identity value: $secsipid(val)\n");
428 }
429 ...
430 }
431 ...
432
433 4.8. secsipid_build_identity_prvkey(origTN, destTN, attest, origID, x5u,
434 keyData)
435
436 Similar to secsipid_build_identity(), but the private key data is
437 provided as parameter instead to the file path.
438
439 The parameters can contain pseudo-variables.
440
441 This function can be used from ANY_ROUTE.
442
443 Example 1.14. secsipid_build_identity_prvkey usage
444 ...
445 request_route {
446 ...
447 if(secsipid_build_identity_prvkey("$fU", "$rU", "A", "",
448 "https://kamailio.org/stir/$rd/cert.pem", "$var(prvkey)")) {
449 xinfo("Identity value: $secsipid(val)\n");
450 }
451 ...
452 }
453 ...
454
455 4.9. secsipid_sign(sheaders, spaypload, keyPath)
456
457 Build Identity value using the private key specified by "keyPath" to
458 sign the JWT body. The sheaders and spayload have to be string
459 representation of JSON headers and payload to be signed. On success,
460 the Indentity value is stored in variable $secsipid(val). It also sets
461 $secsipid(ret) to the return value of the libsecsipid functions.
462
463 The parameters can contain pseudo-variables.
464
465 This function can be used from ANY_ROUTE.
466
467 Example 1.15. secsipid_sign usage
468 ...
469 request_route {
470 ...
471 if(secsipid_sign("_JSON_HEADERS_", "_JSON_PAYLOAD_",
472 "/secsipid/$rd/key.pem")) {
473 xinfo("Identity value: $secsipid(val)\n");
474 }
475 ...
476 }
477 ...
478
479 4.10. secsipid_sign_prvkey(sheaders, spaypload, keyData)
480
481 Build Identity value using the private key given by "keyData" to sign
482 the JWT body. The sheaders and spayload have to be string
483 representation of JSON headers and payload to be signed. On success,
484 the Indentity value is stored in variable $secsipid(val). It also sets
485 $secsipid(ret) to the return value of the libsecsipid functions.
486
487 The parameters can contain pseudo-variables.
488
489 This function can be used from ANY_ROUTE.
490
491 Example 1.16. secsipid_sign_prvkey usage
492 ...
493 request_route {
494 ...
495 if(secsipid_sign_prvkey("_JSON_HEADERS_", "_JSON_PAYLOAD_",
496 "_PRIVATE_KEY_")) {
497 xinfo("Identity value: $secsipid(val)\n");
498 }
499 ...
500 }
501 ...
502
503 5. Installation
504
505 The module needs "secsipdi_proc.so" module that depends on
506 "libsecsipid", which is a component of "sipsecidx" project from
507 https://github.com/asipto/secsipidx/. The library is implemented in Go
508 language, with generated C API and library.
509
510 To generate the libsecsipid files, it requires to have Go language
511 installed and its environment configured, then run the following
512 commands:
513
514 Example 1.17. Libsecsipid Usage
515 ...
516 export GO111MODULE=off
517 go get https://github.com/asipto/secsipidx
518 cd $GOPATH/src/github.com/asipto/secsipidx/csecsipid/
519 make all
520 make install
521
522 cd /path/to/kamailio/
523 make include_modules="secsipid secsipid_proc ..." cfg
524 make all
525 make install
526
527 ## or compiling individual modules for use inside source tree
528 # make modules modules=src/modules/secsipid_proc
529 # make modules modules=src/modules/secsipid
530 ...
531
532 For more details about compilation and installation of libsecsipid,
533 see: https://github.com/asipto/secsipidx.