Asterisk - The Open Source Telephony Project GIT-master-7e7a603
Typedefs | Functions | Variables
test_security_events.c File Reference

Test security event generation. More...

#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/cli.h"
#include "asterisk/utils.h"
#include "asterisk/security_events.h"
#include "asterisk/netsock2.h"
Include dependency graph for test_security_events.c:

Go to the source code of this file.

Typedefs

typedef void(* evt_generator) (void)
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static void evt_gen_auth_method_not_allowed (void)
 
static void evt_gen_chal_resp_failed (void)
 
static void evt_gen_chal_sent (void)
 
static void evt_gen_failed_acl (void)
 
static void evt_gen_inval_acct_id (void)
 
static void evt_gen_inval_password (void)
 
static void evt_gen_inval_transport (void)
 
static void evt_gen_load_avg (void)
 
static void evt_gen_mem_limit (void)
 
static void evt_gen_req_bad_format (void)
 
static void evt_gen_req_no_support (void)
 
static void evt_gen_req_not_allowed (void)
 
static void evt_gen_session_limit (void)
 
static void evt_gen_successful_auth (void)
 
static void evt_gen_unexpected_addr (void)
 
static void gen_events (struct ast_cli_args *a)
 
static char * handle_cli_sec_evt_test (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static int load_module (void)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Test Security Event Generation" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_cli_entry cli_sec_evt []
 
static const evt_generator evt_generators [AST_SECURITY_EVENT_NUM_TYPES]
 

Detailed Description

Test security event generation.

Author
Russell Bryant russe.nosp@m.ll@d.nosp@m.igium.nosp@m..com

Definition in file test_security_events.c.

Typedef Documentation

◆ evt_generator

typedef void(* evt_generator) (void)

Definition at line 55 of file test_security_events.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 704 of file test_security_events.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 704 of file test_security_events.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 704 of file test_security_events.c.

◆ evt_gen_auth_method_not_allowed()

static void evt_gen_auth_method_not_allowed ( void  )
static

Definition at line 333 of file test_security_events.c.

334{
335 struct ast_sockaddr addr_local = { {0,} };
336 struct ast_sockaddr addr_remote = { {0,} };
337
338 struct timeval session_tv = ast_tvnow();
339 struct ast_security_event_auth_method_not_allowed auth_method_not_allowed = {
342 .common.service = "TEST",
343 .common.module = AST_MODULE,
344 .common.account_id = "Bob",
345 .common.session_id = "010101010101",
346 .common.session_tv = &session_tv,
347 .common.local_addr = {
348 .addr = &addr_local,
349 .transport = AST_TRANSPORT_TCP,
350 },
351 .common.remote_addr = {
352 .addr = &addr_remote,
353 .transport = AST_TRANSPORT_TCP,
354 },
355
356 .auth_method = "PlainText"
357 };
358
359 char localaddr[53];
360 char remoteaddr[53];
361
362 ast_copy_string(localaddr, "10.110.120.135:8754", sizeof(localaddr));
363 ast_copy_string(remoteaddr, "10.120.110.105:8745", sizeof(remoteaddr));
364
365 ast_sockaddr_parse(&addr_local, localaddr, 0);
366 ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
367
368 ast_security_event_report(AST_SEC_EVT(&auth_method_not_allowed));
369}
#define AST_MODULE
@ AST_TRANSPORT_TCP
Definition: netsock2.h:61
int ast_sockaddr_parse(struct ast_sockaddr *addr, const char *str, int flags)
Parse an IPv4 or IPv6 address string.
Definition: netsock2.c:230
int ast_security_event_report(const struct ast_security_event_common *sec)
Report a security event.
#define AST_SECURITY_EVENT_AUTH_METHOD_NOT_ALLOWED_VERSION
Event descriptor version.
@ AST_SECURITY_EVENT_AUTH_METHOD_NOT_ALLOWED
The attempted authentication method is not allowed.
#define AST_SEC_EVT(e)
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
struct ast_security_event_common common
Common security event descriptor elements.
enum ast_security_event_type event_type
The security event sub-type.
Socket address structure.
Definition: netsock2.h:97
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:159

References ast_copy_string(), AST_MODULE, AST_SEC_EVT, AST_SECURITY_EVENT_AUTH_METHOD_NOT_ALLOWED, AST_SECURITY_EVENT_AUTH_METHOD_NOT_ALLOWED_VERSION, ast_security_event_report(), ast_sockaddr_parse(), AST_TRANSPORT_TCP, ast_tvnow(), ast_security_event_auth_method_not_allowed::common, and ast_security_event_common::event_type.

◆ evt_gen_chal_resp_failed()

static void evt_gen_chal_resp_failed ( void  )
static

Definition at line 491 of file test_security_events.c.

492{
493 struct ast_sockaddr addr_local = { {0,} };
494 struct ast_sockaddr addr_remote = { {0,} };
495
496 struct timeval session_tv = ast_tvnow();
497 struct ast_security_event_chal_resp_failed chal_resp_failed = {
500 .common.service = "TEST",
501 .common.module = AST_MODULE,
502 .common.account_id = "SuperDuperUser",
503 .common.session_id = "Session1231231231",
504 .common.session_tv = &session_tv,
505 .common.local_addr = {
506 .addr = &addr_local,
507 .transport = AST_TRANSPORT_TCP,
508 },
509 .common.remote_addr = {
510 .addr = &addr_remote,
511 .transport = AST_TRANSPORT_TCP,
512 },
513
514 .challenge = "8adf8a9sd8fas9df23ljk4",
515 .response = "9u3jlaksdjflakjsdfoi23",
516 .expected_response = "oiafaljhadf9834luahk3k",
517 };
518
519 char localaddr[53];
520 char remoteaddr[53];
521
522 ast_copy_string(localaddr, "10.1.2.3:4321", sizeof(localaddr));
523 ast_copy_string(remoteaddr, "10.1.2.4:1234", sizeof(remoteaddr));
524
525 ast_sockaddr_parse(&addr_local, localaddr, 0);
526 ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
527
528 ast_security_event_report(AST_SEC_EVT(&chal_resp_failed));
529}
#define AST_SECURITY_EVENT_CHAL_RESP_FAILED_VERSION
Event descriptor version.
@ AST_SECURITY_EVENT_CHAL_RESP_FAILED
An attempt at challenge/response authentication failed.
An attempt at challenge/response auth failed.
struct ast_security_event_common common
Common security event descriptor elements.

References ast_copy_string(), AST_MODULE, AST_SEC_EVT, AST_SECURITY_EVENT_CHAL_RESP_FAILED, AST_SECURITY_EVENT_CHAL_RESP_FAILED_VERSION, ast_security_event_report(), ast_sockaddr_parse(), AST_TRANSPORT_TCP, ast_tvnow(), ast_security_event_chal_resp_failed::common, and ast_security_event_common::event_type.

◆ evt_gen_chal_sent()

static void evt_gen_chal_sent ( void  )
static

Definition at line 570 of file test_security_events.c.

571{
572 struct ast_sockaddr addr_local = { {0,} };
573 struct ast_sockaddr addr_remote = { {0,} };
574
575 struct timeval session_tv = ast_tvnow();
576 struct ast_security_event_chal_sent chal_sent = {
578 .common.version = AST_SECURITY_EVENT_CHAL_SENT_VERSION,
579 .common.service = "TEST",
580 .common.module = AST_MODULE,
581 .common.account_id = "AccountIDGoesHere",
582 .common.session_id = "SessionIDGoesHere",
583 .common.session_tv = &session_tv,
584 .common.local_addr = {
585 .addr = &addr_local,
586 .transport = AST_TRANSPORT_TCP,
587 },
588 .common.remote_addr = {
589 .addr = &addr_remote,
590 .transport = AST_TRANSPORT_TCP,
591 },
592 .challenge = "IcHaLlEnGeYoU",
593 };
594
595 char localaddr[53];
596 char remoteaddr[53];
597
598 ast_copy_string(localaddr, "10.200.10.30:5392", sizeof(localaddr));
599 ast_copy_string(remoteaddr, "10.200.10.31:1443", sizeof(remoteaddr));
600
601 ast_sockaddr_parse(&addr_local, localaddr, 0);
602 ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
603
605}
@ AST_SECURITY_EVENT_CHAL_SENT
Challenge was sent out, informational.
#define AST_SECURITY_EVENT_CHAL_SENT_VERSION
Event descriptor version.
A challenge was sent out.
struct ast_security_event_common common
Common security event descriptor elements.

References ast_copy_string(), AST_MODULE, AST_SEC_EVT, AST_SECURITY_EVENT_CHAL_SENT, AST_SECURITY_EVENT_CHAL_SENT_VERSION, ast_security_event_report(), ast_sockaddr_parse(), AST_TRANSPORT_TCP, ast_tvnow(), ast_security_event_chal_sent::common, and ast_security_event_common::event_type.

◆ evt_gen_failed_acl()

static void evt_gen_failed_acl ( void  )
static

Definition at line 74 of file test_security_events.c.

75{
76 struct ast_sockaddr addr_local = { {0,} };
77 struct ast_sockaddr addr_remote = { {0,} };
78
79 struct timeval session_tv = ast_tvnow();
80 struct ast_security_event_failed_acl failed_acl_event = {
83 .common.service = "TEST",
84 .common.module = AST_MODULE,
85 .common.account_id = "Username",
86 .common.session_id = "Session123",
87 .common.session_tv = &session_tv,
88 .common.local_addr = {
89 .addr = &addr_local,
90 .transport = AST_TRANSPORT_UDP,
91 },
92 .common.remote_addr = {
93 .addr = &addr_remote,
94 .transport = AST_TRANSPORT_UDP,
95 },
96
97 .acl_name = "TEST_ACL",
98 };
99
100 char localaddr[53];
101 char remoteaddr[53];
102
103 ast_copy_string(localaddr, "192.168.1.1:12121", sizeof(localaddr));
104 ast_copy_string(remoteaddr, "192.168.1.2:12345", sizeof(remoteaddr));
105
106 ast_sockaddr_parse(&addr_local, localaddr, 0);
107 ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
108
109 ast_security_event_report(AST_SEC_EVT(&failed_acl_event));
110}
@ AST_TRANSPORT_UDP
Definition: netsock2.h:60
#define AST_SECURITY_EVENT_FAILED_ACL_VERSION
Event descriptor version.
@ AST_SECURITY_EVENT_FAILED_ACL
Failed ACL.
Checking against an IP access control list failed.
struct ast_security_event_common common
Common security event descriptor elements.

References ast_copy_string(), AST_MODULE, AST_SEC_EVT, AST_SECURITY_EVENT_FAILED_ACL, AST_SECURITY_EVENT_FAILED_ACL_VERSION, ast_security_event_report(), ast_sockaddr_parse(), AST_TRANSPORT_UDP, ast_tvnow(), ast_security_event_failed_acl::common, and ast_security_event_common::event_type.

◆ evt_gen_inval_acct_id()

static void evt_gen_inval_acct_id ( void  )
static

Definition at line 112 of file test_security_events.c.

113{
114 struct ast_sockaddr addr_local = { {0,} };
115 struct ast_sockaddr addr_remote = { {0,} };
116
117 struct timeval session_tv = ast_tvnow();
118 struct ast_security_event_inval_acct_id inval_acct_id = {
121 .common.service = "TEST",
122 .common.module = AST_MODULE,
123 .common.account_id = "FakeUser",
124 .common.session_id = "Session456",
125 .common.session_tv = &session_tv,
126 .common.local_addr = {
127 .addr = &addr_local,
128 .transport = AST_TRANSPORT_TCP,
129 },
130 .common.remote_addr = {
131 .addr = &addr_remote,
132 .transport = AST_TRANSPORT_TCP,
133 },
134 };
135
136 char localaddr[53];
137 char remoteaddr[53];
138
139 ast_copy_string(localaddr, "10.1.2.3:4321", sizeof(localaddr));
140 ast_copy_string(remoteaddr, "10.1.2.4:123", sizeof(remoteaddr));
141
142 ast_sockaddr_parse(&addr_local, localaddr, 0);
143 ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
144
145 ast_security_event_report(AST_SEC_EVT(&inval_acct_id));
146}
#define AST_SECURITY_EVENT_INVAL_ACCT_ID_VERSION
Event descriptor version.
@ AST_SECURITY_EVENT_INVAL_ACCT_ID
Invalid Account ID.
Invalid account ID specified (invalid username, for example)
struct ast_security_event_common common
Common security event descriptor elements.

References ast_copy_string(), AST_MODULE, AST_SEC_EVT, AST_SECURITY_EVENT_INVAL_ACCT_ID, AST_SECURITY_EVENT_INVAL_ACCT_ID_VERSION, ast_security_event_report(), ast_sockaddr_parse(), AST_TRANSPORT_TCP, ast_tvnow(), ast_security_event_inval_acct_id::common, and ast_security_event_common::event_type.

◆ evt_gen_inval_password()

static void evt_gen_inval_password ( void  )
static

Definition at line 531 of file test_security_events.c.

532{
533 struct ast_sockaddr addr_local = { {0,} };
534 struct ast_sockaddr addr_remote = { {0,} };
535
536 struct timeval session_tv = ast_tvnow();
537 struct ast_security_event_inval_password inval_password = {
540 .common.service = "TEST",
541 .common.module = AST_MODULE,
542 .common.account_id = "AccountIDGoesHere",
543 .common.session_id = "SessionIDGoesHere",
544 .common.session_tv = &session_tv,
545 .common.local_addr = {
546 .addr = &addr_local,
547 .transport = AST_TRANSPORT_TCP,
548 },
549 .common.remote_addr = {
550 .addr = &addr_remote,
551 .transport = AST_TRANSPORT_TCP,
552 },
553 .challenge = "GoOdChAlLeNgE",
554 .received_challenge = "BaDcHaLlEnGe",
555 .received_hash = "3ad9023adf309",
556 };
557
558 char localaddr[53];
559 char remoteaddr[53];
560
561 ast_copy_string(localaddr, "10.200.100.30:4321", sizeof(localaddr));
562 ast_copy_string(remoteaddr, "10.200.100.40:1234", sizeof(remoteaddr));
563
564 ast_sockaddr_parse(&addr_local, localaddr, 0);
565 ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
566
567 ast_security_event_report(AST_SEC_EVT(&inval_password));
568}
#define AST_SECURITY_EVENT_INVAL_PASSWORD_VERSION
Event descriptor version.
@ AST_SECURITY_EVENT_INVAL_PASSWORD
An attempt at basic password authentication failed.
An attempt at basic password auth failed.
struct ast_security_event_common common
Common security event descriptor elements.

References ast_copy_string(), AST_MODULE, AST_SEC_EVT, AST_SECURITY_EVENT_INVAL_PASSWORD, AST_SECURITY_EVENT_INVAL_PASSWORD_VERSION, ast_security_event_report(), ast_sockaddr_parse(), AST_TRANSPORT_TCP, ast_tvnow(), ast_security_event_inval_password::common, and ast_security_event_common::event_type.

◆ evt_gen_inval_transport()

static void evt_gen_inval_transport ( void  )
static

Definition at line 607 of file test_security_events.c.

608{
609 struct ast_sockaddr addr_local = { {0,} };
610 struct ast_sockaddr addr_remote = { {0,} };
611
612 struct timeval session_tv = ast_tvnow();
613 struct ast_security_event_inval_transport inval_transport = {
616 .common.service = "TEST",
617 .common.module = AST_MODULE,
618 .common.account_id = "AccountIDGoesHere",
619 .common.session_id = "SessionIDGoesHere",
620 .common.session_tv = &session_tv,
621 .common.local_addr = {
622 .addr = &addr_local,
623 .transport = AST_TRANSPORT_TCP,
624 },
625 .common.remote_addr = {
626 .addr = &addr_remote,
627 .transport = AST_TRANSPORT_TCP,
628 },
629 .transport = "UDP",
630 };
631
632 char localaddr[53];
633 char remoteaddr[53];
634
635 ast_copy_string(localaddr, "10.200.103.45:8223", sizeof(localaddr));
636 ast_copy_string(remoteaddr, "10.200.103.44:1039", sizeof(remoteaddr));
637
638 ast_sockaddr_parse(&addr_local, localaddr, 0);
639 ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
640
641 ast_security_event_report(AST_SEC_EVT(&inval_transport));
642}
#define AST_SECURITY_EVENT_INVAL_TRANSPORT_VERSION
Event descriptor version.
@ AST_SECURITY_EVENT_INVAL_TRANSPORT
An attempt to contact a peer on an invalid transport.
Attempt to contact peer on invalid transport.
struct ast_security_event_common common
Common security event descriptor elements.

References ast_copy_string(), AST_MODULE, AST_SEC_EVT, AST_SECURITY_EVENT_INVAL_TRANSPORT, AST_SECURITY_EVENT_INVAL_TRANSPORT_VERSION, ast_security_event_report(), ast_sockaddr_parse(), AST_TRANSPORT_TCP, ast_tvnow(), ast_security_event_inval_transport::common, and ast_security_event_common::event_type.

◆ evt_gen_load_avg()

static void evt_gen_load_avg ( void  )
static

Definition at line 220 of file test_security_events.c.

221{
222 struct ast_sockaddr addr_local = { {0,} };
223 struct ast_sockaddr addr_remote = { {0,} };
224
225 struct timeval session_tv = ast_tvnow();
226 struct ast_security_event_load_avg load_avg = {
228 .common.version = AST_SECURITY_EVENT_LOAD_AVG_VERSION,
229 .common.service = "TEST",
230 .common.module = AST_MODULE,
231 .common.account_id = "GuestAccount",
232 .common.session_id = "XYZ123",
233 .common.session_tv = &session_tv,
234 .common.local_addr = {
235 .addr = &addr_local,
236 .transport = AST_TRANSPORT_UDP,
237 },
238 .common.remote_addr = {
239 .addr = &addr_remote,
240 .transport = AST_TRANSPORT_UDP,
241 },
242 };
243
244 char localaddr[53];
245 char remoteaddr[53];
246
247 ast_copy_string(localaddr, "10.11.12.13:9876", sizeof(localaddr));
248 ast_copy_string(remoteaddr, "10.12.11.10:9825", sizeof(remoteaddr));
249
250 ast_sockaddr_parse(&addr_local, localaddr, 0);
251 ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
252
254}
@ AST_SECURITY_EVENT_LOAD_AVG
Load Average limit reached.
#define AST_SECURITY_EVENT_LOAD_AVG_VERSION
Event descriptor version.
Request denied because of a load average limit.
struct ast_security_event_common common
Common security event descriptor elements.

References ast_copy_string(), AST_MODULE, AST_SEC_EVT, AST_SECURITY_EVENT_LOAD_AVG, AST_SECURITY_EVENT_LOAD_AVG_VERSION, ast_security_event_report(), ast_sockaddr_parse(), AST_TRANSPORT_UDP, ast_tvnow(), ast_security_event_load_avg::common, and ast_security_event_common::event_type.

◆ evt_gen_mem_limit()

static void evt_gen_mem_limit ( void  )
static

Definition at line 184 of file test_security_events.c.

185{
186 struct ast_sockaddr addr_local = { {0,} };
187 struct ast_sockaddr addr_remote = { {0,} };
188
189 struct timeval session_tv = ast_tvnow();
190 struct ast_security_event_mem_limit mem_limit = {
192 .common.version = AST_SECURITY_EVENT_MEM_LIMIT_VERSION,
193 .common.service = "TEST",
194 .common.module = AST_MODULE,
195 .common.account_id = "Felix",
196 .common.session_id = "Session2604",
197 .common.session_tv = &session_tv,
198 .common.local_addr = {
199 .addr = &addr_local,
200 .transport = AST_TRANSPORT_UDP,
201 },
202 .common.remote_addr = {
203 .addr = &addr_remote,
204 .transport = AST_TRANSPORT_UDP,
205 },
206 };
207
208 char localaddr[53];
209 char remoteaddr[53];
210
211 ast_copy_string(localaddr, "10.10.10.10:555", sizeof(localaddr));
212 ast_copy_string(remoteaddr, "10.10.10.12:5656", sizeof(remoteaddr));
213
214 ast_sockaddr_parse(&addr_local, localaddr, 0);
215 ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
216
218}
#define AST_SECURITY_EVENT_MEM_LIMIT_VERSION
Event descriptor version.
@ AST_SECURITY_EVENT_MEM_LIMIT
Memory limit reached.
Request denied because of a memory limit.
struct ast_security_event_common common
Common security event descriptor elements.

References ast_copy_string(), AST_MODULE, AST_SEC_EVT, AST_SECURITY_EVENT_MEM_LIMIT, AST_SECURITY_EVENT_MEM_LIMIT_VERSION, ast_security_event_report(), ast_sockaddr_parse(), AST_TRANSPORT_UDP, ast_tvnow(), ast_security_event_mem_limit::common, and ast_security_event_common::event_type.

◆ evt_gen_req_bad_format()

static void evt_gen_req_bad_format ( void  )
static

Definition at line 371 of file test_security_events.c.

372{
373 struct ast_sockaddr addr_local = { {0,} };
374 struct ast_sockaddr addr_remote = { {0,} };
375
376 struct timeval session_tv = ast_tvnow();
377 struct ast_security_event_req_bad_format req_bad_format = {
380 .common.service = "TEST",
381 .common.module = AST_MODULE,
382 .common.account_id = "Larry",
383 .common.session_id = "838383fhfhf83hf8h3f8h",
384 .common.session_tv = &session_tv,
385 .common.local_addr = {
386 .addr = &addr_local,
387 .transport = AST_TRANSPORT_TCP,
388 },
389 .common.remote_addr = {
390 .addr = &addr_remote,
391 .transport = AST_TRANSPORT_TCP,
392 },
393
394 .request_type = "CheeseBurger",
395 .request_params = "Onions,Swiss,MotorOil",
396 };
397
398 char localaddr[53];
399 char remoteaddr[53];
400
401 ast_copy_string(localaddr, "10.110.220.230:1212", sizeof(localaddr));
402 ast_copy_string(remoteaddr, "10.120.210.200:2121", sizeof(remoteaddr));
403
404 ast_sockaddr_parse(&addr_local, localaddr, 0);
405 ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
406
407 ast_security_event_report(AST_SEC_EVT(&req_bad_format));
408}
#define AST_SECURITY_EVENT_REQ_BAD_FORMAT_VERSION
Event descriptor version.
@ AST_SECURITY_EVENT_REQ_BAD_FORMAT
Request received with bad formatting.
Invalid formatting of request.
struct ast_security_event_common common
Common security event descriptor elements.

References ast_copy_string(), AST_MODULE, AST_SEC_EVT, ast_security_event_report(), AST_SECURITY_EVENT_REQ_BAD_FORMAT, AST_SECURITY_EVENT_REQ_BAD_FORMAT_VERSION, ast_sockaddr_parse(), AST_TRANSPORT_TCP, ast_tvnow(), ast_security_event_req_bad_format::common, and ast_security_event_common::event_type.

◆ evt_gen_req_no_support()

static void evt_gen_req_no_support ( void  )
static

Definition at line 256 of file test_security_events.c.

257{
258 struct ast_sockaddr addr_local = { {0,} };
259 struct ast_sockaddr addr_remote = { {0,} };
260
261 struct timeval session_tv = ast_tvnow();
262 struct ast_security_event_req_no_support req_no_support = {
265 .common.service = "TEST",
266 .common.module = AST_MODULE,
267 .common.account_id = "George",
268 .common.session_id = "asdkl23478289lasdkf",
269 .common.session_tv = &session_tv,
270 .common.local_addr = {
271 .addr = &addr_local,
272 .transport = AST_TRANSPORT_UDP,
273 },
274 .common.remote_addr = {
275 .addr = &addr_remote,
276 .transport = AST_TRANSPORT_UDP,
277 },
278
279 .request_type = "MakeMeDinner",
280 };
281
282 char localaddr[53];
283 char remoteaddr[53];
284
285 ast_copy_string(localaddr, "10.110.120.130:9888", sizeof(localaddr));
286 ast_copy_string(remoteaddr, "10.120.110.100:9777", sizeof(remoteaddr));
287
288 ast_sockaddr_parse(&addr_local, localaddr, 0);
289 ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
290
291 ast_security_event_report(AST_SEC_EVT(&req_no_support));
292}
#define AST_SECURITY_EVENT_REQ_NO_SUPPORT_VERSION
Event descriptor version.
@ AST_SECURITY_EVENT_REQ_NO_SUPPORT
A request was made that we understand, but do not support.
Request denied because we don't support it.
struct ast_security_event_common common
Common security event descriptor elements.

References ast_copy_string(), AST_MODULE, AST_SEC_EVT, ast_security_event_report(), AST_SECURITY_EVENT_REQ_NO_SUPPORT, AST_SECURITY_EVENT_REQ_NO_SUPPORT_VERSION, ast_sockaddr_parse(), AST_TRANSPORT_UDP, ast_tvnow(), ast_security_event_req_no_support::common, and ast_security_event_common::event_type.

◆ evt_gen_req_not_allowed()

static void evt_gen_req_not_allowed ( void  )
static

Definition at line 294 of file test_security_events.c.

295{
296 struct ast_sockaddr addr_local = { {0,} };
297 struct ast_sockaddr addr_remote = { {0,} };
298
299 struct timeval session_tv = ast_tvnow();
300 struct ast_security_event_req_not_allowed req_not_allowed = {
303 .common.service = "TEST",
304 .common.module = AST_MODULE,
305 .common.account_id = "George",
306 .common.session_id = "alksdjf023423h4lka0df",
307 .common.session_tv = &session_tv,
308 .common.local_addr = {
309 .addr = &addr_local,
310 .transport = AST_TRANSPORT_UDP,
311 },
312 .common.remote_addr = {
313 .addr = &addr_remote,
314 .transport = AST_TRANSPORT_UDP,
315 },
316
317 .request_type = "MakeMeBreakfast",
318 .request_params = "BACONNNN!",
319 };
320
321 char localaddr[53];
322 char remoteaddr[53];
323
324 ast_copy_string(localaddr, "10.110.120.130:9888", sizeof(localaddr));
325 ast_copy_string(remoteaddr, "10.120.110.100:9777", sizeof(remoteaddr));
326
327 ast_sockaddr_parse(&addr_local, localaddr, 0);
328 ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
329
330 ast_security_event_report(AST_SEC_EVT(&req_not_allowed));
331}
#define AST_SECURITY_EVENT_REQ_NOT_ALLOWED_VERSION
Event descriptor version.
@ AST_SECURITY_EVENT_REQ_NOT_ALLOWED
A request was made that is not allowed.
Request denied because it's not allowed.
struct ast_security_event_common common
Common security event descriptor elements.

References ast_copy_string(), AST_MODULE, AST_SEC_EVT, ast_security_event_report(), AST_SECURITY_EVENT_REQ_NOT_ALLOWED, AST_SECURITY_EVENT_REQ_NOT_ALLOWED_VERSION, ast_sockaddr_parse(), AST_TRANSPORT_UDP, ast_tvnow(), ast_security_event_req_not_allowed::common, and ast_security_event_common::event_type.

◆ evt_gen_session_limit()

static void evt_gen_session_limit ( void  )
static

Definition at line 148 of file test_security_events.c.

149{
150 struct ast_sockaddr addr_local = { {0,} };
151 struct ast_sockaddr addr_remote = { {0,} };
152
153 struct timeval session_tv = ast_tvnow();
155 .common.event_type = AST_SECURITY_EVENT_SESSION_LIMIT,
157 .common.service = "TEST",
158 .common.module = AST_MODULE,
159 .common.account_id = "Jenny",
160 .common.session_id = "8675309",
161 .common.session_tv = &session_tv,
162 .common.local_addr = {
163 .addr = &addr_local,
164 .transport = AST_TRANSPORT_TLS,
165 },
166 .common.remote_addr = {
167 .addr = &addr_remote,
168 .transport = AST_TRANSPORT_TLS,
169 },
170 };
171
172 char localaddr[53];
173 char remoteaddr[53];
174
175 ast_copy_string(localaddr, "10.5.4.3:4444", sizeof(localaddr));
176 ast_copy_string(remoteaddr, "10.5.4.2:3333", sizeof(remoteaddr));
177
178 ast_sockaddr_parse(&addr_local, localaddr, 0);
179 ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
180
182}
static int session_limit
Definition: http.c:106
@ AST_TRANSPORT_TLS
Definition: netsock2.h:62
#define AST_SECURITY_EVENT_SESSION_LIMIT_VERSION
Event descriptor version.
@ AST_SECURITY_EVENT_SESSION_LIMIT
Session limit reached.
Request denied because of a session limit.

References ast_copy_string(), AST_MODULE, AST_SEC_EVT, ast_security_event_report(), AST_SECURITY_EVENT_SESSION_LIMIT, AST_SECURITY_EVENT_SESSION_LIMIT_VERSION, ast_sockaddr_parse(), AST_TRANSPORT_TLS, ast_tvnow(), and session_limit.

◆ evt_gen_successful_auth()

static void evt_gen_successful_auth ( void  )
static

Definition at line 410 of file test_security_events.c.

411{
412 struct ast_sockaddr addr_local = { {0,} };
413 struct ast_sockaddr addr_remote = { {0,} };
414
415 struct timeval session_tv = ast_tvnow();
416 struct ast_security_event_successful_auth successful_auth = {
419 .common.service = "TEST",
420 .common.module = AST_MODULE,
421 .common.account_id = "ValidUser",
422 .common.session_id = "Session456",
423 .common.session_tv = &session_tv,
424 .common.local_addr = {
425 .addr = &addr_local,
426 .transport = AST_TRANSPORT_TCP,
427 },
428 .common.remote_addr = {
429 .addr = &addr_remote,
430 .transport = AST_TRANSPORT_TCP,
431 },
432 };
433
434 char localaddr[53];
435 char remoteaddr[53];
436
437 ast_copy_string(localaddr, "10.1.2.3:4321", sizeof(localaddr));
438 ast_copy_string(remoteaddr, "10.1.2.4:1234", sizeof(remoteaddr));
439
440 ast_sockaddr_parse(&addr_local, localaddr, 0);
441 ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
442
443 ast_security_event_report(AST_SEC_EVT(&successful_auth));
444}
@ AST_SECURITY_EVENT_SUCCESSFUL_AUTH
FYI FWIW, Successful authentication has occurred.
#define AST_SECURITY_EVENT_SUCCESSFUL_AUTH_VERSION
Event descriptor version.
struct ast_security_event_common common
Common security event descriptor elements.

References ast_copy_string(), AST_MODULE, AST_SEC_EVT, ast_security_event_report(), AST_SECURITY_EVENT_SUCCESSFUL_AUTH, AST_SECURITY_EVENT_SUCCESSFUL_AUTH_VERSION, ast_sockaddr_parse(), AST_TRANSPORT_TCP, ast_tvnow(), ast_security_event_successful_auth::common, and ast_security_event_common::event_type.

◆ evt_gen_unexpected_addr()

static void evt_gen_unexpected_addr ( void  )
static

Definition at line 446 of file test_security_events.c.

447{
448 struct ast_sockaddr addr_local = { {0,} };
449 struct ast_sockaddr addr_remote = { {0,} };
450 struct ast_sockaddr addr_expected = { {0,} };
451
452 struct timeval session_tv = ast_tvnow();
453 struct ast_security_event_unexpected_addr unexpected_addr = {
456 .common.service = "TEST",
457 .common.module = AST_MODULE,
458 .common.account_id = "CoolUser",
459 .common.session_id = "Session789",
460 .common.session_tv = &session_tv,
461 .common.local_addr = {
462 .addr = &addr_local,
463 .transport = AST_TRANSPORT_UDP,
464 },
465 .common.remote_addr = {
466 .addr = &addr_remote,
467 .transport = AST_TRANSPORT_UDP,
468 },
469
470 .expected_addr = {
471 .addr = &addr_expected,
472 .transport = AST_TRANSPORT_UDP,
473 },
474 };
475
476 char localaddr[53];
477 char remoteaddr[53];
478 char expectedaddr[53];
479
480 ast_copy_string(localaddr, "10.1.2.3:4321", sizeof(localaddr));
481 ast_copy_string(remoteaddr, "10.1.2.4:1234", sizeof(remoteaddr));
482 ast_copy_string(expectedaddr, "10.1.2.5:2343", sizeof(expectedaddr));
483
484 ast_sockaddr_parse(&addr_local, localaddr, 0);
485 ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
486 ast_sockaddr_parse(&addr_expected, expectedaddr, 0);
487
488 ast_security_event_report(AST_SEC_EVT(&unexpected_addr));
489}
#define AST_SECURITY_EVENT_UNEXPECTED_ADDR_VERSION
Event descriptor version.
@ AST_SECURITY_EVENT_UNEXPECTED_ADDR
An unexpected source address was seen for a session in progress.
Unexpected source address for a session in progress.
struct ast_security_event_common common
Common security event descriptor elements.

References ast_copy_string(), AST_MODULE, AST_SEC_EVT, ast_security_event_report(), AST_SECURITY_EVENT_UNEXPECTED_ADDR, AST_SECURITY_EVENT_UNEXPECTED_ADDR_VERSION, ast_sockaddr_parse(), AST_TRANSPORT_UDP, ast_tvnow(), ast_security_event_unexpected_addr::common, and ast_security_event_common::event_type.

◆ gen_events()

static void gen_events ( struct ast_cli_args a)
static

Definition at line 644 of file test_security_events.c.

645{
646 unsigned int i;
647
648 ast_cli(a->fd, "Generating some security events ...\n");
649
650 for (i = 0; i < ARRAY_LEN(evt_generators); i++) {
651 const char *event_type = ast_security_event_get_name(i);
652
653 if (!evt_generators[i]) {
654 ast_cli(a->fd, "*** No event generator for event type '%s' ***\n",
655 event_type);
656 continue;
657 }
658
659 ast_cli(a->fd, "Generating a '%s' security event ...\n", event_type);
660
661 evt_generators[i]();
662 }
663
664 ast_cli(a->fd, "Security event generation complete.\n");
665}
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
const char * ast_security_event_get_name(const enum ast_security_event_type event_type)
Get the name of a security event sub-type.
static struct test_val a
static const evt_generator evt_generators[AST_SECURITY_EVENT_NUM_TYPES]
#define ARRAY_LEN(a)
Definition: utils.h:666

References a, ARRAY_LEN, ast_cli(), ast_security_event_get_name(), and evt_generators.

Referenced by handle_cli_sec_evt_test().

◆ handle_cli_sec_evt_test()

static char * handle_cli_sec_evt_test ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 667 of file test_security_events.c.

668{
669 switch (cmd) {
670 case CLI_INIT:
671 e->command = "securityevents test generation";
672 e->usage = ""
673 "Usage: securityevents test generation"
674 "";
675 return NULL;
676 case CLI_GENERATE:
677 return NULL;
678 case CLI_HANDLER:
679 gen_events(a);
680 return CLI_SUCCESS;
681 }
682
683 return CLI_FAILURE;
684}
#define CLI_SUCCESS
Definition: cli.h:44
@ CLI_HANDLER
Definition: cli.h:154
@ CLI_INIT
Definition: cli.h:152
@ CLI_GENERATE
Definition: cli.h:153
#define CLI_FAILURE
Definition: cli.h:46
#define NULL
Definition: resample.c:96
char * command
Definition: cli.h:186
const char * usage
Definition: cli.h:177
static void gen_events(struct ast_cli_args *a)

References a, CLI_FAILURE, CLI_GENERATE, CLI_HANDLER, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, gen_events(), NULL, and ast_cli_entry::usage.

◆ load_module()

static int load_module ( void  )
static

Definition at line 695 of file test_security_events.c.

696{
697 int res;
698
700
702}
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
static struct ast_cli_entry cli_sec_evt[]

References ARRAY_LEN, ast_cli_register_multiple, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, and cli_sec_evt.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 690 of file test_security_events.c.

691{
693}
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: clicompat.c:30

References ARRAY_LEN, ast_cli_unregister_multiple(), and cli_sec_evt.

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Test Security Event Generation" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 704 of file test_security_events.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 704 of file test_security_events.c.

◆ cli_sec_evt

struct ast_cli_entry cli_sec_evt[]
static
Initial value:
= {
{ .handler = handle_cli_sec_evt_test , .summary = "Test security event generation" ,},
}
static char * handle_cli_sec_evt_test(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)

Definition at line 686 of file test_security_events.c.

Referenced by load_module(), and unload_module().

◆ evt_generators

const evt_generator evt_generators[AST_SECURITY_EVENT_NUM_TYPES]
static

Definition at line 56 of file test_security_events.c.

Referenced by gen_events().