bridge_native_rtp: Fix T.38 issues with remote bridges
[asterisk/asterisk.git] / tests / test_security_events.c
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2012, Digium, Inc.
5  *
6  * Russell Bryant <russell@digium.com>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18
19 /*! \file
20  *
21  * \brief Test security event generation
22  *
23  * \author Russell Bryant <russell@digium.com>
24  */
25
26 /*** MODULEINFO
27         <depend>TEST_FRAMEWORK</depend>
28         <support_level>core</support_level>
29  ***/
30
31 #include "asterisk.h"
32
33 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
34
35 #include "asterisk/module.h"
36 #include "asterisk/cli.h"
37 #include "asterisk/utils.h"
38 #include "asterisk/security_events.h"
39 #include "asterisk/netsock2.h"
40
41 static void evt_gen_failed_acl(void);
42 static void evt_gen_inval_acct_id(void);
43 static void evt_gen_session_limit(void);
44 static void evt_gen_mem_limit(void);
45 static void evt_gen_load_avg(void);
46 static void evt_gen_req_no_support(void);
47 static void evt_gen_req_not_allowed(void);
48 static void evt_gen_auth_method_not_allowed(void);
49 static void evt_gen_req_bad_format(void);
50 static void evt_gen_successful_auth(void);
51 static void evt_gen_unexpected_addr(void);
52 static void evt_gen_chal_resp_failed(void);
53 static void evt_gen_inval_password(void);
54 static void evt_gen_chal_sent(void);
55 static void evt_gen_inval_transport(void);
56
57 typedef void (*evt_generator)(void);
58 static const evt_generator evt_generators[AST_SECURITY_EVENT_NUM_TYPES] = {
59         [AST_SECURITY_EVENT_FAILED_ACL]              = evt_gen_failed_acl,
60         [AST_SECURITY_EVENT_INVAL_ACCT_ID]           = evt_gen_inval_acct_id,
61         [AST_SECURITY_EVENT_SESSION_LIMIT]           = evt_gen_session_limit,
62         [AST_SECURITY_EVENT_MEM_LIMIT]               = evt_gen_mem_limit,
63         [AST_SECURITY_EVENT_LOAD_AVG]                = evt_gen_load_avg,
64         [AST_SECURITY_EVENT_REQ_NO_SUPPORT]          = evt_gen_req_no_support,
65         [AST_SECURITY_EVENT_REQ_NOT_ALLOWED]         = evt_gen_req_not_allowed,
66         [AST_SECURITY_EVENT_AUTH_METHOD_NOT_ALLOWED] = evt_gen_auth_method_not_allowed,
67         [AST_SECURITY_EVENT_REQ_BAD_FORMAT]          = evt_gen_req_bad_format,
68         [AST_SECURITY_EVENT_SUCCESSFUL_AUTH]         = evt_gen_successful_auth,
69         [AST_SECURITY_EVENT_UNEXPECTED_ADDR]         = evt_gen_unexpected_addr,
70         [AST_SECURITY_EVENT_CHAL_RESP_FAILED]        = evt_gen_chal_resp_failed,
71         [AST_SECURITY_EVENT_INVAL_PASSWORD]          = evt_gen_inval_password,
72         [AST_SECURITY_EVENT_CHAL_SENT]               = evt_gen_chal_sent,
73         [AST_SECURITY_EVENT_INVAL_TRANSPORT]         = evt_gen_inval_transport,
74 };
75
76 static void evt_gen_failed_acl(void)
77 {
78         struct ast_sockaddr addr_local = { {0,} };
79         struct ast_sockaddr addr_remote = { {0,} };
80
81         struct timeval session_tv = ast_tvnow();
82         struct ast_security_event_failed_acl failed_acl_event = {
83                 .common.event_type = AST_SECURITY_EVENT_FAILED_ACL,
84                 .common.version    = AST_SECURITY_EVENT_FAILED_ACL_VERSION,
85                 .common.service    = "TEST",
86                 .common.module     = AST_MODULE,
87                 .common.account_id = "Username",
88                 .common.session_id = "Session123",
89                 .common.session_tv = &session_tv,
90                 .common.local_addr = {
91                         .addr  = &addr_local,
92                         .transport  = AST_TRANSPORT_UDP,
93                 },
94                 .common.remote_addr = {
95                         .addr = &addr_remote,
96                         .transport  = AST_TRANSPORT_UDP,
97                 },
98
99                 .acl_name   = "TEST_ACL",
100         };
101
102         char localaddr[53];
103         char remoteaddr[53];
104
105         ast_copy_string(localaddr, "192.168.1.1:12121", sizeof(localaddr));
106         ast_copy_string(remoteaddr, "192.168.1.2:12345", sizeof(remoteaddr));
107
108         ast_sockaddr_parse(&addr_local, localaddr, 0);
109         ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
110
111         ast_security_event_report(AST_SEC_EVT(&failed_acl_event));
112 }
113
114 static void evt_gen_inval_acct_id(void)
115 {
116         struct ast_sockaddr addr_local = { {0,} };
117         struct ast_sockaddr addr_remote = { {0,} };
118
119         struct timeval session_tv = ast_tvnow();
120         struct ast_security_event_inval_acct_id inval_acct_id = {
121                 .common.event_type = AST_SECURITY_EVENT_INVAL_ACCT_ID,
122                 .common.version    = AST_SECURITY_EVENT_INVAL_ACCT_ID_VERSION,
123                 .common.service    = "TEST",
124                 .common.module     = AST_MODULE,
125                 .common.account_id = "FakeUser",
126                 .common.session_id = "Session456",
127                 .common.session_tv = &session_tv,
128                 .common.local_addr = {
129                         .addr  = &addr_local,
130                         .transport  = AST_TRANSPORT_TCP,
131                 },
132                 .common.remote_addr = {
133                         .addr = &addr_remote,
134                         .transport  = AST_TRANSPORT_TCP,
135                 },
136         };
137
138         char localaddr[53];
139         char remoteaddr[53];
140
141         ast_copy_string(localaddr, "10.1.2.3:4321", sizeof(localaddr));
142         ast_copy_string(remoteaddr, "10.1.2.4:123", sizeof(remoteaddr));
143
144         ast_sockaddr_parse(&addr_local, localaddr, 0);
145         ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
146
147         ast_security_event_report(AST_SEC_EVT(&inval_acct_id));
148 }
149
150 static void evt_gen_session_limit(void)
151 {
152         struct ast_sockaddr addr_local = { {0,} };
153         struct ast_sockaddr addr_remote = { {0,} };
154
155         struct timeval session_tv = ast_tvnow();
156         struct ast_security_event_session_limit session_limit = {
157                 .common.event_type = AST_SECURITY_EVENT_SESSION_LIMIT,
158                 .common.version    = AST_SECURITY_EVENT_SESSION_LIMIT_VERSION,
159                 .common.service    = "TEST",
160                 .common.module     = AST_MODULE,
161                 .common.account_id = "Jenny",
162                 .common.session_id = "8675309",
163                 .common.session_tv = &session_tv,
164                 .common.local_addr = {
165                         .addr  = &addr_local,
166                         .transport  = AST_TRANSPORT_TLS,
167                 },
168                 .common.remote_addr = {
169                         .addr = &addr_remote,
170                         .transport  = AST_TRANSPORT_TLS,
171                 },
172         };
173
174         char localaddr[53];
175         char remoteaddr[53];
176
177         ast_copy_string(localaddr, "10.5.4.3:4444", sizeof(localaddr));
178         ast_copy_string(remoteaddr, "10.5.4.2:3333", sizeof(remoteaddr));
179
180         ast_sockaddr_parse(&addr_local, localaddr, 0);
181         ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
182
183         ast_security_event_report(AST_SEC_EVT(&session_limit));
184 }
185
186 static void evt_gen_mem_limit(void)
187 {
188         struct ast_sockaddr addr_local = { {0,} };
189         struct ast_sockaddr addr_remote = { {0,} };
190
191         struct timeval session_tv = ast_tvnow();
192         struct ast_security_event_mem_limit mem_limit = {
193                 .common.event_type = AST_SECURITY_EVENT_MEM_LIMIT,
194                 .common.version    = AST_SECURITY_EVENT_MEM_LIMIT_VERSION,
195                 .common.service    = "TEST",
196                 .common.module     = AST_MODULE,
197                 .common.account_id = "Felix",
198                 .common.session_id = "Session2604",
199                 .common.session_tv = &session_tv,
200                 .common.local_addr = {
201                         .addr  = &addr_local,
202                         .transport  = AST_TRANSPORT_UDP,
203                 },
204                 .common.remote_addr = {
205                         .addr = &addr_remote,
206                         .transport  = AST_TRANSPORT_UDP,
207                 },
208         };
209
210         char localaddr[53];
211         char remoteaddr[53];
212
213         ast_copy_string(localaddr, "10.10.10.10:555", sizeof(localaddr));
214         ast_copy_string(remoteaddr, "10.10.10.12:5656", sizeof(remoteaddr));
215
216         ast_sockaddr_parse(&addr_local, localaddr, 0);
217         ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
218
219         ast_security_event_report(AST_SEC_EVT(&mem_limit));
220 }
221
222 static void evt_gen_load_avg(void)
223 {
224         struct ast_sockaddr addr_local = { {0,} };
225         struct ast_sockaddr addr_remote = { {0,} };
226
227         struct timeval session_tv = ast_tvnow();
228         struct ast_security_event_load_avg load_avg = {
229                 .common.event_type = AST_SECURITY_EVENT_LOAD_AVG,
230                 .common.version    = AST_SECURITY_EVENT_LOAD_AVG_VERSION,
231                 .common.service    = "TEST",
232                 .common.module     = AST_MODULE,
233                 .common.account_id = "GuestAccount",
234                 .common.session_id = "XYZ123",
235                 .common.session_tv = &session_tv,
236                 .common.local_addr = {
237                         .addr  = &addr_local,
238                         .transport  = AST_TRANSPORT_UDP,
239                 },
240                 .common.remote_addr = {
241                         .addr = &addr_remote,
242                         .transport  = AST_TRANSPORT_UDP,
243                 },
244         };
245
246         char localaddr[53];
247         char remoteaddr[53];
248
249         ast_copy_string(localaddr, "10.11.12.13:9876", sizeof(localaddr));
250         ast_copy_string(remoteaddr, "10.12.11.10:9825", sizeof(remoteaddr));
251
252         ast_sockaddr_parse(&addr_local, localaddr, 0);
253         ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
254
255         ast_security_event_report(AST_SEC_EVT(&load_avg));
256 }
257
258 static void evt_gen_req_no_support(void)
259 {
260         struct ast_sockaddr addr_local = { {0,} };
261         struct ast_sockaddr addr_remote = { {0,} };
262
263         struct timeval session_tv = ast_tvnow();
264         struct ast_security_event_req_no_support req_no_support = {
265                 .common.event_type = AST_SECURITY_EVENT_REQ_NO_SUPPORT,
266                 .common.version    = AST_SECURITY_EVENT_REQ_NO_SUPPORT_VERSION,
267                 .common.service    = "TEST",
268                 .common.module     = AST_MODULE,
269                 .common.account_id = "George",
270                 .common.session_id = "asdkl23478289lasdkf",
271                 .common.session_tv = &session_tv,
272                 .common.local_addr = {
273                         .addr  = &addr_local,
274                         .transport  = AST_TRANSPORT_UDP,
275                 },
276                 .common.remote_addr = {
277                         .addr = &addr_remote,
278                         .transport  = AST_TRANSPORT_UDP,
279                 },
280
281                 .request_type = "MakeMeDinner",
282         };
283
284         char localaddr[53];
285         char remoteaddr[53];
286
287         ast_copy_string(localaddr, "10.110.120.130:9888", sizeof(localaddr));
288         ast_copy_string(remoteaddr, "10.120.110.100:9777", sizeof(remoteaddr));
289
290         ast_sockaddr_parse(&addr_local, localaddr, 0);
291         ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
292
293         ast_security_event_report(AST_SEC_EVT(&req_no_support));
294 }
295
296 static void evt_gen_req_not_allowed(void)
297 {
298         struct ast_sockaddr addr_local = { {0,} };
299         struct ast_sockaddr addr_remote = { {0,} };
300
301         struct timeval session_tv = ast_tvnow();
302         struct ast_security_event_req_not_allowed req_not_allowed = {
303                 .common.event_type = AST_SECURITY_EVENT_REQ_NOT_ALLOWED,
304                 .common.version    = AST_SECURITY_EVENT_REQ_NOT_ALLOWED_VERSION,
305                 .common.service    = "TEST",
306                 .common.module     = AST_MODULE,
307                 .common.account_id = "George",
308                 .common.session_id = "alksdjf023423h4lka0df",
309                 .common.session_tv = &session_tv,
310                 .common.local_addr = {
311                         .addr  = &addr_local,
312                         .transport  = AST_TRANSPORT_UDP,
313                 },
314                 .common.remote_addr = {
315                         .addr = &addr_remote,
316                         .transport  = AST_TRANSPORT_UDP,
317                 },
318
319                 .request_type = "MakeMeBreakfast",
320                 .request_params = "BACONNNN!",
321         };
322
323         char localaddr[53];
324         char remoteaddr[53];
325
326         ast_copy_string(localaddr, "10.110.120.130:9888", sizeof(localaddr));
327         ast_copy_string(remoteaddr, "10.120.110.100:9777", sizeof(remoteaddr));
328
329         ast_sockaddr_parse(&addr_local, localaddr, 0);
330         ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
331
332         ast_security_event_report(AST_SEC_EVT(&req_not_allowed));
333 }
334
335 static void evt_gen_auth_method_not_allowed(void)
336 {
337         struct ast_sockaddr addr_local = { {0,} };
338         struct ast_sockaddr addr_remote = { {0,} };
339
340         struct timeval session_tv = ast_tvnow();
341         struct ast_security_event_auth_method_not_allowed auth_method_not_allowed = {
342                 .common.event_type = AST_SECURITY_EVENT_AUTH_METHOD_NOT_ALLOWED,
343                 .common.version    = AST_SECURITY_EVENT_AUTH_METHOD_NOT_ALLOWED_VERSION,
344                 .common.service    = "TEST",
345                 .common.module     = AST_MODULE,
346                 .common.account_id = "Bob",
347                 .common.session_id = "010101010101",
348                 .common.session_tv = &session_tv,
349                 .common.local_addr = {
350                         .addr  = &addr_local,
351                         .transport  = AST_TRANSPORT_TCP,
352                 },
353                 .common.remote_addr = {
354                         .addr = &addr_remote,
355                         .transport  = AST_TRANSPORT_TCP,
356                 },
357
358                 .auth_method = "PlainText"
359         };
360
361         char localaddr[53];
362         char remoteaddr[53];
363
364         ast_copy_string(localaddr, "10.110.120.135:8754", sizeof(localaddr));
365         ast_copy_string(remoteaddr, "10.120.110.105:8745", sizeof(remoteaddr));
366
367         ast_sockaddr_parse(&addr_local, localaddr, 0);
368         ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
369
370         ast_security_event_report(AST_SEC_EVT(&auth_method_not_allowed));
371 }
372
373 static void evt_gen_req_bad_format(void)
374 {
375         struct ast_sockaddr addr_local = { {0,} };
376         struct ast_sockaddr addr_remote = { {0,} };
377
378         struct timeval session_tv = ast_tvnow();
379         struct ast_security_event_req_bad_format req_bad_format = {
380                 .common.event_type = AST_SECURITY_EVENT_REQ_BAD_FORMAT,
381                 .common.version    = AST_SECURITY_EVENT_REQ_BAD_FORMAT_VERSION,
382                 .common.service    = "TEST",
383                 .common.module     = AST_MODULE,
384                 .common.account_id = "Larry",
385                 .common.session_id = "838383fhfhf83hf8h3f8h",
386                 .common.session_tv = &session_tv,
387                 .common.local_addr = {
388                         .addr  = &addr_local,
389                         .transport  = AST_TRANSPORT_TCP,
390                 },
391                 .common.remote_addr = {
392                         .addr = &addr_remote,
393                         .transport  = AST_TRANSPORT_TCP,
394                 },
395
396                 .request_type = "CheeseBurger",
397                 .request_params = "Onions,Swiss,MotorOil",
398         };
399
400         char localaddr[53];
401         char remoteaddr[53];
402
403         ast_copy_string(localaddr, "10.110.220.230:1212", sizeof(localaddr));
404         ast_copy_string(remoteaddr, "10.120.210.200:2121", sizeof(remoteaddr));
405
406         ast_sockaddr_parse(&addr_local, localaddr, 0);
407         ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
408
409         ast_security_event_report(AST_SEC_EVT(&req_bad_format));
410 }
411
412 static void evt_gen_successful_auth(void)
413 {
414         struct ast_sockaddr addr_local = { {0,} };
415         struct ast_sockaddr addr_remote = { {0,} };
416
417         struct timeval session_tv = ast_tvnow();
418         struct ast_security_event_successful_auth successful_auth = {
419                 .common.event_type = AST_SECURITY_EVENT_SUCCESSFUL_AUTH,
420                 .common.version    = AST_SECURITY_EVENT_SUCCESSFUL_AUTH_VERSION,
421                 .common.service    = "TEST",
422                 .common.module     = AST_MODULE,
423                 .common.account_id = "ValidUser",
424                 .common.session_id = "Session456",
425                 .common.session_tv = &session_tv,
426                 .common.local_addr = {
427                         .addr  = &addr_local,
428                         .transport  = AST_TRANSPORT_TCP,
429                 },
430                 .common.remote_addr = {
431                         .addr = &addr_remote,
432                         .transport  = AST_TRANSPORT_TCP,
433                 },
434         };
435
436         char localaddr[53];
437         char remoteaddr[53];
438
439         ast_copy_string(localaddr, "10.1.2.3:4321", sizeof(localaddr));
440         ast_copy_string(remoteaddr, "10.1.2.4:1234", sizeof(remoteaddr));
441
442         ast_sockaddr_parse(&addr_local, localaddr, 0);
443         ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
444
445         ast_security_event_report(AST_SEC_EVT(&successful_auth));
446 }
447
448 static void evt_gen_unexpected_addr(void)
449 {
450         struct ast_sockaddr addr_local = { {0,} };
451         struct ast_sockaddr addr_remote = { {0,} };
452         struct ast_sockaddr addr_expected = { {0,} };
453
454         struct timeval session_tv = ast_tvnow();
455         struct ast_security_event_unexpected_addr unexpected_addr = {
456                 .common.event_type = AST_SECURITY_EVENT_UNEXPECTED_ADDR,
457                 .common.version    = AST_SECURITY_EVENT_UNEXPECTED_ADDR_VERSION,
458                 .common.service    = "TEST",
459                 .common.module     = AST_MODULE,
460                 .common.account_id = "CoolUser",
461                 .common.session_id = "Session789",
462                 .common.session_tv = &session_tv,
463                 .common.local_addr = {
464                         .addr  = &addr_local,
465                         .transport  = AST_TRANSPORT_UDP,
466                 },
467                 .common.remote_addr = {
468                         .addr = &addr_remote,
469                         .transport  = AST_TRANSPORT_UDP,
470                 },
471
472                 .expected_addr = {
473                         .addr = &addr_expected,
474                         .transport  = AST_TRANSPORT_UDP,
475                 },
476         };
477
478         char localaddr[53];
479         char remoteaddr[53];
480         char expectedaddr[53];
481
482         ast_copy_string(localaddr, "10.1.2.3:4321", sizeof(localaddr));
483         ast_copy_string(remoteaddr, "10.1.2.4:1234", sizeof(remoteaddr));
484         ast_copy_string(expectedaddr, "10.1.2.5:2343", sizeof(expectedaddr));
485
486         ast_sockaddr_parse(&addr_local, localaddr, 0);
487         ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
488         ast_sockaddr_parse(&addr_expected, expectedaddr, 0);
489
490         ast_security_event_report(AST_SEC_EVT(&unexpected_addr));
491 }
492
493 static void evt_gen_chal_resp_failed(void)
494 {
495         struct ast_sockaddr addr_local = { {0,} };
496         struct ast_sockaddr addr_remote = { {0,} };
497
498         struct timeval session_tv = ast_tvnow();
499         struct ast_security_event_chal_resp_failed chal_resp_failed = {
500                 .common.event_type = AST_SECURITY_EVENT_CHAL_RESP_FAILED,
501                 .common.version    = AST_SECURITY_EVENT_CHAL_RESP_FAILED_VERSION,
502                 .common.service    = "TEST",
503                 .common.module     = AST_MODULE,
504                 .common.account_id = "SuperDuperUser",
505                 .common.session_id = "Session1231231231",
506                 .common.session_tv = &session_tv,
507                 .common.local_addr = {
508                         .addr  = &addr_local,
509                         .transport  = AST_TRANSPORT_TCP,
510                 },
511                 .common.remote_addr = {
512                         .addr = &addr_remote,
513                         .transport  = AST_TRANSPORT_TCP,
514                 },
515
516                 .challenge         = "8adf8a9sd8fas9df23ljk4",
517                 .response          = "9u3jlaksdjflakjsdfoi23",
518                 .expected_response = "oiafaljhadf9834luahk3k",
519         };
520
521         char localaddr[53];
522         char remoteaddr[53];
523
524         ast_copy_string(localaddr, "10.1.2.3:4321", sizeof(localaddr));
525         ast_copy_string(remoteaddr, "10.1.2.4:1234", sizeof(remoteaddr));
526
527         ast_sockaddr_parse(&addr_local, localaddr, 0);
528         ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
529
530         ast_security_event_report(AST_SEC_EVT(&chal_resp_failed));
531 }
532
533 static void evt_gen_inval_password(void)
534 {
535         struct ast_sockaddr addr_local = { {0,} };
536         struct ast_sockaddr addr_remote = { {0,} };
537
538         struct timeval session_tv = ast_tvnow();
539         struct ast_security_event_inval_password inval_password = {
540                 .common.event_type = AST_SECURITY_EVENT_INVAL_PASSWORD,
541                 .common.version    = AST_SECURITY_EVENT_INVAL_PASSWORD_VERSION,
542                 .common.service    = "TEST",
543                 .common.module     = AST_MODULE,
544                 .common.account_id = "AccountIDGoesHere",
545                 .common.session_id = "SessionIDGoesHere",
546                 .common.session_tv = &session_tv,
547                 .common.local_addr = {
548                         .addr  = &addr_local,
549                         .transport  = AST_TRANSPORT_TCP,
550                 },
551                 .common.remote_addr = {
552                         .addr = &addr_remote,
553                         .transport  = AST_TRANSPORT_TCP,
554                 },
555                 .challenge          = "GoOdChAlLeNgE",
556                 .received_challenge = "BaDcHaLlEnGe",
557                 .received_hash      = "3ad9023adf309",
558         };
559
560         char localaddr[53];
561         char remoteaddr[53];
562
563         ast_copy_string(localaddr, "10.200.100.30:4321", sizeof(localaddr));
564         ast_copy_string(remoteaddr, "10.200.100.40:1234", sizeof(remoteaddr));
565
566         ast_sockaddr_parse(&addr_local, localaddr, 0);
567         ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
568
569         ast_security_event_report(AST_SEC_EVT(&inval_password));
570 }
571
572 static void evt_gen_chal_sent(void)
573 {
574         struct ast_sockaddr addr_local = { {0,} };
575         struct ast_sockaddr addr_remote = { {0,} };
576
577         struct timeval session_tv = ast_tvnow();
578         struct ast_security_event_chal_sent chal_sent = {
579                 .common.event_type = AST_SECURITY_EVENT_CHAL_SENT,
580                 .common.version    = AST_SECURITY_EVENT_CHAL_SENT_VERSION,
581                 .common.service    = "TEST",
582                 .common.module     = AST_MODULE,
583                 .common.account_id = "AccountIDGoesHere",
584                 .common.session_id = "SessionIDGoesHere",
585                 .common.session_tv = &session_tv,
586                 .common.local_addr = {
587                         .addr  = &addr_local,
588                         .transport  = AST_TRANSPORT_TCP,
589                 },
590                 .common.remote_addr = {
591                         .addr = &addr_remote,
592                         .transport  = AST_TRANSPORT_TCP,
593                 },
594                 .challenge         = "IcHaLlEnGeYoU",
595         };
596
597         char localaddr[53];
598         char remoteaddr[53];
599
600         ast_copy_string(localaddr, "10.200.10.30:5392", sizeof(localaddr));
601         ast_copy_string(remoteaddr, "10.200.10.31:1443", sizeof(remoteaddr));
602
603         ast_sockaddr_parse(&addr_local, localaddr, 0);
604         ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
605
606         ast_security_event_report(AST_SEC_EVT(&chal_sent));
607 }
608
609 static void evt_gen_inval_transport(void)
610 {
611         struct ast_sockaddr addr_local = { {0,} };
612         struct ast_sockaddr addr_remote = { {0,} };
613
614         struct timeval session_tv = ast_tvnow();
615         struct ast_security_event_inval_transport inval_transport = {
616                 .common.event_type = AST_SECURITY_EVENT_INVAL_TRANSPORT,
617                 .common.version    = AST_SECURITY_EVENT_INVAL_TRANSPORT_VERSION,
618                 .common.service    = "TEST",
619                 .common.module     = AST_MODULE,
620                 .common.account_id = "AccountIDGoesHere",
621                 .common.session_id = "SessionIDGoesHere",
622                 .common.session_tv = &session_tv,
623                 .common.local_addr = {
624                         .addr  = &addr_local,
625                         .transport  = AST_TRANSPORT_TCP,
626                 },
627                 .common.remote_addr = {
628                         .addr = &addr_remote,
629                         .transport  = AST_TRANSPORT_TCP,
630                 },
631                 .transport          = "UDP",
632         };
633
634         char localaddr[53];
635         char remoteaddr[53];
636
637         ast_copy_string(localaddr, "10.200.103.45:8223", sizeof(localaddr));
638         ast_copy_string(remoteaddr, "10.200.103.44:1039", sizeof(remoteaddr));
639
640         ast_sockaddr_parse(&addr_local, localaddr, 0);
641         ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
642
643         ast_security_event_report(AST_SEC_EVT(&inval_transport));
644 }
645
646 static void gen_events(struct ast_cli_args *a)
647 {
648         unsigned int i;
649
650         ast_cli(a->fd, "Generating some security events ...\n");
651
652         for (i = 0; i < ARRAY_LEN(evt_generators); i++) {
653                 const char *event_type = ast_security_event_get_name(i);
654
655                 if (!evt_generators[i]) {
656                         ast_cli(a->fd, "*** No event generator for event type '%s' ***\n",
657                                         event_type);
658                         continue;
659                 }
660
661                 ast_cli(a->fd, "Generating a '%s' security event ...\n", event_type);
662
663                 evt_generators[i]();
664         }
665
666         ast_cli(a->fd, "Security event generation complete.\n");
667 }
668
669 static char *handle_cli_sec_evt_test(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
670 {
671         switch (cmd) {
672         case CLI_INIT:
673                 e->command = "securityevents test generation";
674                 e->usage = ""
675                         "Usage: securityevents test generation"
676                         "";
677                 return NULL;
678         case CLI_GENERATE:
679                 return NULL;
680         case CLI_HANDLER:
681                 gen_events(a);
682                 return CLI_SUCCESS;
683         }
684
685         return CLI_FAILURE;
686 }
687
688 static struct ast_cli_entry cli_sec_evt[] = {
689         AST_CLI_DEFINE(handle_cli_sec_evt_test, "Test security event generation"),
690 };
691
692 static int unload_module(void)
693 {
694         return ast_cli_unregister_multiple(cli_sec_evt, ARRAY_LEN(cli_sec_evt));
695 }
696
697 static int load_module(void)
698 {
699         int res;
700
701         res = ast_cli_register_multiple(cli_sec_evt, ARRAY_LEN(cli_sec_evt));
702
703         return res ? AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS;
704 }
705
706 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Test Security Event Generation");