| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
#include "asterisk.h" |
| 409 |
|
| 410 |
#include "asterisk/utils.h" |
| 411 |
#include "asterisk/strings.h" |
| 412 |
#include "asterisk/network.h" |
| 413 |
#include "asterisk/event.h" |
| 414 |
#include "asterisk/security_events.h" |
| 415 |
#include "asterisk/netsock2.h" |
| 416 |
#include "asterisk/stasis.h" |
| 417 |
#include "asterisk/json.h" |
| 418 |
#include "asterisk/astobj2.h" |
| 419 |
|
| 420 |
static const size_t SECURITY_EVENT_BUF_INIT_LEN = 256; |
| 421 |
|
| 422 |
|
| 423 |
static struct stasis_topic *security_topic; |
| 424 |
|
| 425 |
struct stasis_topic *ast_security_topic(void) |
| 426 |
{ |
| 427 |
return security_topic; |
| 428 |
} |
| 429 |
|
| 430 |
static int append_event_str_single(struct ast_str **str, struct ast_json *json, |
| 431 |
const enum ast_event_ie_type ie_type) |
| 432 |
{ |
| 433 |
const char *ie_type_key = ast_event_get_ie_type_name(ie_type); |
| 434 |
struct ast_json *json_string = ast_json_object_get(json, ie_type_key); |
| 435 |
|
| 436 |
if (!json_string) { |
| 437 |
return 0; |
| 438 |
} |
| 439 |
|
| 440 |
if (ast_str_append(str, 0, "%s: %s\r\n", ie_type_key, S_OR(ast_json_string_get(json_string), "")) == -1) { |
| 441 |
return -1; |
| 442 |
} |
| 443 |
|
| 444 |
return 0; |
| 445 |
} |
| 446 |
|
| 447 |
static int append_event_str_from_json(struct ast_str **str, struct ast_json *json, |
| 448 |
const struct ast_security_event_ie_type *ies) |
| 449 |
{ |
| 450 |
unsigned int i; |
| 451 |
|
| 452 |
if (!ies) { |
| 453 |
return 0; |
| 454 |
} |
| 455 |
|
| 456 |
for (i = 0; ies[i].ie_type != AST_EVENT_IE_END; i++) { |
| 457 |
if (append_event_str_single(str, json, ies[i].ie_type)) { |
| 458 |
return -1; |
| 459 |
} |
| 460 |
} |
| 461 |
|
| 462 |
return 0; |
| 463 |
} |
| 464 |
|
| 465 |
static struct ast_manager_event_blob *security_event_to_ami_blob(struct ast_json *json) |
| 466 |
{ |
| 467 |
RAII_VAR(struct ast_str *, str, NULL, ast_free); |
| 468 |
struct ast_json *event_type_json; |
| 469 |
enum ast_security_event_type event_type; |
| 470 |
|
| 471 |
event_type_json = ast_json_object_get(json, "SecurityEvent"); |
| 472 |
event_type = ast_json_integer_get(event_type_json); |
| 473 |
|
| 474 |
ast_assert((unsigned int)event_type < AST_SECURITY_EVENT_NUM_TYPES); |
| 475 |
|
| 476 |
if (!(str = ast_str_create(SECURITY_EVENT_BUF_INIT_LEN))) { |
| 477 |
return NULL; |
| 478 |
} |
| 479 |
|
| 480 |
if (append_event_str_from_json(&str, json, |
| 481 |
ast_security_event_get_required_ies(event_type))) { |
| 482 |
ast_log(AST_LOG_ERROR, "Failed to issue a security event to AMI: " |
| 483 |
"error occurred when adding required event fields.\n"); |
| 484 |
return NULL; |
| 485 |
} |
| 486 |
|
| 487 |
if (append_event_str_from_json(&str, json, |
| 488 |
ast_security_event_get_optional_ies(event_type))) { |
| 489 |
ast_log(AST_LOG_ERROR, "Failed to issue a security event to AMI: " |
| 490 |
"error occurred when adding optional event fields.\n"); |
| 491 |
return NULL; |
| 492 |
} |
| 493 |
|
| 494 |
return ast_manager_event_blob_create(EVENT_FLAG_SECURITY, |
| 495 |
ast_security_event_get_name(event_type), |
| 496 |
"%s", |
| 497 |
ast_str_buffer(str)); |
| 498 |
} |
| 499 |
|
| 500 |
static struct ast_manager_event_blob *security_event_to_ami(struct stasis_message *message) |
| 501 |
{ |
| 502 |
struct ast_json_payload *payload = stasis_message_data(message); |
| 503 |
|
| 504 |
if (stasis_message_type(message) != ast_security_event_type()) { |
| 505 |
return NULL; |
| 506 |
} |
| 507 |
|
| 508 |
if (!payload) { |
| 509 |
return NULL; |
| 510 |
} |
| 511 |
|
| 512 |
return security_event_to_ami_blob(payload->json); |
| 513 |
} |
| 514 |
|
| 515 |
|
| 516 |
STASIS_MESSAGE_TYPE_DEFN(ast_security_event_type, |
| 517 |
.to_ami = security_event_to_ami, |
| 518 |
); |
| 519 |
|
| 520 |
static void security_stasis_cleanup(void) |
| 521 |
{ |
| 522 |
ao2_cleanup(security_topic); |
| 523 |
security_topic = NULL; |
| 524 |
|
| 525 |
STASIS_MESSAGE_TYPE_CLEANUP(ast_security_event_type); |
| 526 |
} |
| 527 |
|
| 528 |
int ast_security_stasis_init(void) |
| 529 |
{ |
| 530 |
ast_register_cleanup(security_stasis_cleanup); |
| 531 |
|
| 532 |
security_topic = stasis_topic_create("security:all"); |
| 533 |
if (!security_topic) { |
| 534 |
return -1; |
| 535 |
} |
| 536 |
|
| 537 |
if (STASIS_MESSAGE_TYPE_INIT(ast_security_event_type)) { |
| 538 |
return -1; |
| 539 |
} |
| 540 |
|
| 541 |
|
| 542 |
return 0; |
| 543 |
} |
| 544 |
|
| 545 |
static const struct { |
| 546 |
const char *name; |
| 547 |
uint32_t version; |
| 548 |
enum ast_security_event_severity severity; |
| 549 |
#define MAX_SECURITY_IES 12 |
| 550 |
struct ast_security_event_ie_type required_ies[MAX_SECURITY_IES]; |
| 551 |
struct ast_security_event_ie_type optional_ies[MAX_SECURITY_IES]; |
| 552 |
#undef MAX_SECURITY_IES |
| 553 |
} sec_events[AST_SECURITY_EVENT_NUM_TYPES] = { |
| 554 |
|
| 555 |
#define SEC_EVT_FIELD(e, field) (offsetof(struct ast_security_event_##e, field)) |
| 556 |
|
| 557 |
[AST_SECURITY_EVENT_FAILED_ACL] = { |
| 558 |
.name = "FailedACL", |
| 559 |
.version = AST_SECURITY_EVENT_FAILED_ACL_VERSION, |
| 560 |
.severity = AST_SECURITY_EVENT_SEVERITY_ERROR, |
| 561 |
.required_ies = { |
| 562 |
{ AST_EVENT_IE_EVENT_TV, 0 }, |
| 563 |
{ AST_EVENT_IE_SEVERITY, 0 }, |
| 564 |
{ AST_EVENT_IE_SERVICE, SEC_EVT_FIELD(common, service) }, |
| 565 |
{ AST_EVENT_IE_EVENT_VERSION, SEC_EVT_FIELD(common, version) }, |
| 566 |
{ AST_EVENT_IE_ACCOUNT_ID, SEC_EVT_FIELD(common, account_id) }, |
| 567 |
{ AST_EVENT_IE_SESSION_ID, SEC_EVT_FIELD(common, session_id) }, |
| 568 |
{ AST_EVENT_IE_LOCAL_ADDR, SEC_EVT_FIELD(common, local_addr) }, |
| 569 |
{ AST_EVENT_IE_REMOTE_ADDR, SEC_EVT_FIELD(common, remote_addr) }, |
| 570 |
{ AST_EVENT_IE_END, 0 } |
| 571 |
}, |
| 572 |
.optional_ies = { |
| 573 |
{ AST_EVENT_IE_MODULE, SEC_EVT_FIELD(common, module) }, |
| 574 |
{ AST_EVENT_IE_ACL_NAME, SEC_EVT_FIELD(failed_acl, acl_name) }, |
| 575 |
{ AST_EVENT_IE_SESSION_TV, SEC_EVT_FIELD(common, session_tv) }, |
| 576 |
{ AST_EVENT_IE_END, 0 } |
| 577 |
}, |
| 578 |
}, |
| 579 |
|
| 580 |
[AST_SECURITY_EVENT_INVAL_ACCT_ID] = { |
| 581 |
.name = "InvalidAccountID", |
| 582 |
.version = AST_SECURITY_EVENT_INVAL_ACCT_ID_VERSION, |
| 583 |
.severity = AST_SECURITY_EVENT_SEVERITY_ERROR, |
| 584 |
.required_ies = { |
| 585 |
{ AST_EVENT_IE_EVENT_TV, 0 }, |
| 586 |
{ AST_EVENT_IE_SEVERITY, 0 }, |
| 587 |
{ AST_EVENT_IE_SERVICE, SEC_EVT_FIELD(common, service) }, |
| 588 |
{ AST_EVENT_IE_EVENT_VERSION, SEC_EVT_FIELD(common, version) }, |
| 589 |
{ AST_EVENT_IE_ACCOUNT_ID, SEC_EVT_FIELD(common, account_id) }, |
| 590 |
{ AST_EVENT_IE_SESSION_ID, SEC_EVT_FIELD(common, session_id) }, |
| 591 |
{ AST_EVENT_IE_LOCAL_ADDR, SEC_EVT_FIELD(common, local_addr) }, |
| 592 |
{ AST_EVENT_IE_REMOTE_ADDR, SEC_EVT_FIELD(common, remote_addr) }, |
| 593 |
{ AST_EVENT_IE_END, 0 } |
| 594 |
}, |
| 595 |
.optional_ies = { |
| 596 |
{ AST_EVENT_IE_MODULE, SEC_EVT_FIELD(common, module) }, |
| 597 |
{ AST_EVENT_IE_SESSION_TV, SEC_EVT_FIELD(common, session_tv) }, |
| 598 |
{ AST_EVENT_IE_END, 0 } |
| 599 |
}, |
| 600 |
}, |
| 601 |
|
| 602 |
[AST_SECURITY_EVENT_SESSION_LIMIT] = { |
| 603 |
.name = "SessionLimit", |
| 604 |
.version = AST_SECURITY_EVENT_SESSION_LIMIT_VERSION, |
| 605 |
.severity = AST_SECURITY_EVENT_SEVERITY_ERROR, |
| 606 |
.required_ies = { |
| 607 |
{ AST_EVENT_IE_EVENT_TV, 0 }, |
| 608 |
{ AST_EVENT_IE_SEVERITY, 0 }, |
| 609 |
{ AST_EVENT_IE_SERVICE, SEC_EVT_FIELD(common, service) }, |
| 610 |
{ AST_EVENT_IE_EVENT_VERSION, SEC_EVT_FIELD(common, version) }, |
| 611 |
{ AST_EVENT_IE_ACCOUNT_ID, SEC_EVT_FIELD(common, account_id) }, |
| 612 |
{ AST_EVENT_IE_SESSION_ID, SEC_EVT_FIELD(common, session_id) }, |
| 613 |
{ AST_EVENT_IE_LOCAL_ADDR, SEC_EVT_FIELD(common, local_addr) }, |
| 614 |
{ AST_EVENT_IE_REMOTE_ADDR, SEC_EVT_FIELD(common, remote_addr) }, |
| 615 |
{ AST_EVENT_IE_END, 0 } |
| 616 |
}, |
| 617 |
.optional_ies = { |
| 618 |
{ AST_EVENT_IE_MODULE, SEC_EVT_FIELD(common, module) }, |
| 619 |
{ AST_EVENT_IE_SESSION_TV, SEC_EVT_FIELD(common, session_tv) }, |
| 620 |
{ AST_EVENT_IE_END, 0 } |
| 621 |
}, |
| 622 |
}, |
| 623 |
|
| 624 |
[AST_SECURITY_EVENT_MEM_LIMIT] = { |
| 625 |
.name = "MemoryLimit", |
| 626 |
.version = AST_SECURITY_EVENT_MEM_LIMIT_VERSION, |
| 627 |
.severity = AST_SECURITY_EVENT_SEVERITY_ERROR, |
| 628 |
.required_ies = { |
| 629 |
{ AST_EVENT_IE_EVENT_TV, 0 }, |
| 630 |
{ AST_EVENT_IE_SEVERITY, 0 }, |
| 631 |
{ AST_EVENT_IE_SERVICE, SEC_EVT_FIELD(common, service) }, |
| 632 |
{ AST_EVENT_IE_EVENT_VERSION, SEC_EVT_FIELD(common, version) }, |
| 633 |
{ AST_EVENT_IE_ACCOUNT_ID, SEC_EVT_FIELD(common, account_id) }, |
| 634 |
{ AST_EVENT_IE_SESSION_ID, SEC_EVT_FIELD(common, session_id) }, |
| 635 |
{ AST_EVENT_IE_LOCAL_ADDR, SEC_EVT_FIELD(common, local_addr) }, |
| 636 |
{ AST_EVENT_IE_REMOTE_ADDR, SEC_EVT_FIELD(common, remote_addr) }, |
| 637 |
{ AST_EVENT_IE_END, 0 } |
| 638 |
}, |
| 639 |
.optional_ies = { |
| 640 |
{ AST_EVENT_IE_MODULE, SEC_EVT_FIELD(common, module) }, |
| 641 |
{ AST_EVENT_IE_SESSION_TV, SEC_EVT_FIELD(common, session_tv) }, |
| 642 |
{ AST_EVENT_IE_END, 0 } |
| 643 |
}, |
| 644 |
}, |
| 645 |
|
| 646 |
[AST_SECURITY_EVENT_LOAD_AVG] = { |
| 647 |
.name = "LoadAverageLimit", |
| 648 |
.version = AST_SECURITY_EVENT_LOAD_AVG_VERSION, |
| 649 |
.severity = AST_SECURITY_EVENT_SEVERITY_ERROR, |
| 650 |
.required_ies = { |
| 651 |
{ AST_EVENT_IE_EVENT_TV, 0 }, |
| 652 |
{ AST_EVENT_IE_SEVERITY, 0 }, |
| 653 |
{ AST_EVENT_IE_SERVICE, SEC_EVT_FIELD(common, service) }, |
| 654 |
{ AST_EVENT_IE_EVENT_VERSION, SEC_EVT_FIELD(common, version) }, |
| 655 |
{ AST_EVENT_IE_ACCOUNT_ID, SEC_EVT_FIELD(common, account_id) }, |
| 656 |
{ AST_EVENT_IE_SESSION_ID, SEC_EVT_FIELD(common, session_id) }, |
| 657 |
{ AST_EVENT_IE_LOCAL_ADDR, SEC_EVT_FIELD(common, local_addr) }, |
| 658 |
{ AST_EVENT_IE_REMOTE_ADDR, SEC_EVT_FIELD(common, remote_addr) }, |
| 659 |
{ AST_EVENT_IE_END, 0 } |
| 660 |
}, |
| 661 |
.optional_ies = { |
| 662 |
{ AST_EVENT_IE_MODULE, SEC_EVT_FIELD(common, module) }, |
| 663 |
{ AST_EVENT_IE_SESSION_TV, SEC_EVT_FIELD(common, session_tv) }, |
| 664 |
{ AST_EVENT_IE_END, 0 } |
| 665 |
}, |
| 666 |
}, |
| 667 |
|
| 668 |
[AST_SECURITY_EVENT_REQ_NO_SUPPORT] = { |
| 669 |
.name = "RequestNotSupported", |
| 670 |
.version = AST_SECURITY_EVENT_REQ_NO_SUPPORT_VERSION, |
| 671 |
.severity = AST_SECURITY_EVENT_SEVERITY_ERROR, |
| 672 |
.required_ies = { |
| 673 |
{ AST_EVENT_IE_EVENT_TV, 0 }, |
| 674 |
{ AST_EVENT_IE_SEVERITY, 0 }, |
| 675 |
{ AST_EVENT_IE_SERVICE, SEC_EVT_FIELD(common, service) }, |
| 676 |
{ AST_EVENT_IE_EVENT_VERSION, SEC_EVT_FIELD(common, version) }, |
| 677 |
{ AST_EVENT_IE_ACCOUNT_ID, SEC_EVT_FIELD(common, account_id) }, |
| 678 |
{ AST_EVENT_IE_SESSION_ID, SEC_EVT_FIELD(common, session_id) }, |
| 679 |
{ AST_EVENT_IE_LOCAL_ADDR, SEC_EVT_FIELD(common, local_addr) }, |
| 680 |
{ AST_EVENT_IE_REMOTE_ADDR, SEC_EVT_FIELD(common, remote_addr) }, |
| 681 |
{ AST_EVENT_IE_REQUEST_TYPE, SEC_EVT_FIELD(req_no_support, request_type) }, |
| 682 |
{ AST_EVENT_IE_END, 0 } |
| 683 |
}, |
| 684 |
.optional_ies = { |
| 685 |
{ AST_EVENT_IE_MODULE, SEC_EVT_FIELD(common, module) }, |
| 686 |
{ AST_EVENT_IE_SESSION_TV, SEC_EVT_FIELD(common, session_tv) }, |
| 687 |
{ AST_EVENT_IE_END, 0 } |
| 688 |
}, |
| 689 |
}, |
| 690 |
|
| 691 |
[AST_SECURITY_EVENT_REQ_NOT_ALLOWED] = { |
| 692 |
.name = "RequestNotAllowed", |
| 693 |
.version = AST_SECURITY_EVENT_REQ_NOT_ALLOWED_VERSION, |
| 694 |
.severity = AST_SECURITY_EVENT_SEVERITY_ERROR, |
| 695 |
.required_ies = { |
| 696 |
{ AST_EVENT_IE_EVENT_TV, 0 }, |
| 697 |
{ AST_EVENT_IE_SEVERITY, 0 }, |
| 698 |
{ AST_EVENT_IE_SERVICE, SEC_EVT_FIELD(common, service) }, |
| 699 |
{ AST_EVENT_IE_EVENT_VERSION, SEC_EVT_FIELD(common, version) }, |
| 700 |
{ AST_EVENT_IE_ACCOUNT_ID, SEC_EVT_FIELD(common, account_id) }, |
| 701 |
{ AST_EVENT_IE_SESSION_ID, SEC_EVT_FIELD(common, session_id) }, |
| 702 |
{ AST_EVENT_IE_LOCAL_ADDR, SEC_EVT_FIELD(common, local_addr) }, |
| 703 |
{ AST_EVENT_IE_REMOTE_ADDR, SEC_EVT_FIELD(common, remote_addr) }, |
| 704 |
{ AST_EVENT_IE_REQUEST_TYPE, SEC_EVT_FIELD(req_not_allowed, request_type) }, |
| 705 |
{ AST_EVENT_IE_END, 0 } |
| 706 |
}, |
| 707 |
.optional_ies = { |
| 708 |
{ AST_EVENT_IE_MODULE, SEC_EVT_FIELD(common, module) }, |
| 709 |
{ AST_EVENT_IE_SESSION_TV, SEC_EVT_FIELD(common, session_tv) }, |
| 710 |
{ AST_EVENT_IE_REQUEST_PARAMS, SEC_EVT_FIELD(req_not_allowed, request_params) }, |
| 711 |
{ AST_EVENT_IE_END, 0 } |
| 712 |
}, |
| 713 |
}, |
| 714 |
|
| 715 |
[AST_SECURITY_EVENT_AUTH_METHOD_NOT_ALLOWED] = { |
| 716 |
.name = "AuthMethodNotAllowed", |
| 717 |
.version = AST_SECURITY_EVENT_AUTH_METHOD_NOT_ALLOWED_VERSION, |
| 718 |
.severity = AST_SECURITY_EVENT_SEVERITY_ERROR, |
| 719 |
.required_ies = { |
| 720 |
{ AST_EVENT_IE_EVENT_TV, 0 }, |
| 721 |
{ AST_EVENT_IE_SEVERITY, 0 }, |
| 722 |
{ AST_EVENT_IE_SERVICE, SEC_EVT_FIELD(common, service) }, |
| 723 |
{ AST_EVENT_IE_EVENT_VERSION, SEC_EVT_FIELD(common, version) }, |
| 724 |
{ AST_EVENT_IE_ACCOUNT_ID, SEC_EVT_FIELD(common, account_id) }, |
| 725 |
{ AST_EVENT_IE_SESSION_ID, SEC_EVT_FIELD(common, session_id) }, |
| 726 |
{ AST_EVENT_IE_LOCAL_ADDR, SEC_EVT_FIELD(common, local_addr) }, |
| 727 |
{ AST_EVENT_IE_REMOTE_ADDR, SEC_EVT_FIELD(common, remote_addr) }, |
| 728 |
{ AST_EVENT_IE_AUTH_METHOD, SEC_EVT_FIELD(auth_method_not_allowed, auth_method) }, |
| 729 |
{ AST_EVENT_IE_END, 0 } |
| 730 |
}, |
| 731 |
.optional_ies = { |
| 732 |
{ AST_EVENT_IE_MODULE, SEC_EVT_FIELD(common, module) }, |
| 733 |
{ AST_EVENT_IE_SESSION_TV, SEC_EVT_FIELD(common, session_tv) }, |
| 734 |
{ AST_EVENT_IE_END, 0 } |
| 735 |
}, |
| 736 |
}, |
| 737 |
|
| 738 |
[AST_SECURITY_EVENT_REQ_BAD_FORMAT] = { |
| 739 |
.name = "RequestBadFormat", |
| 740 |
.version = AST_SECURITY_EVENT_REQ_BAD_FORMAT_VERSION, |
| 741 |
.severity = AST_SECURITY_EVENT_SEVERITY_ERROR, |
| 742 |
.required_ies = { |
| 743 |
{ AST_EVENT_IE_EVENT_TV, 0 }, |
| 744 |
{ AST_EVENT_IE_SEVERITY, 0 }, |
| 745 |
{ AST_EVENT_IE_SERVICE, SEC_EVT_FIELD(common, service) }, |
| 746 |
{ AST_EVENT_IE_EVENT_VERSION, SEC_EVT_FIELD(common, version) }, |
| 747 |
{ AST_EVENT_IE_SESSION_ID, SEC_EVT_FIELD(common, session_id) }, |
| 748 |
{ AST_EVENT_IE_LOCAL_ADDR, SEC_EVT_FIELD(common, local_addr) }, |
| 749 |
{ AST_EVENT_IE_REMOTE_ADDR, SEC_EVT_FIELD(common, remote_addr) }, |
| 750 |
{ AST_EVENT_IE_REQUEST_TYPE, SEC_EVT_FIELD(req_bad_format, request_type) }, |
| 751 |
{ AST_EVENT_IE_END, 0 } |
| 752 |
}, |
| 753 |
.optional_ies = { |
| 754 |
{ AST_EVENT_IE_MODULE, SEC_EVT_FIELD(common, module) }, |
| 755 |
{ AST_EVENT_IE_SESSION_TV, SEC_EVT_FIELD(common, session_tv) }, |
| 756 |
{ AST_EVENT_IE_ACCOUNT_ID, SEC_EVT_FIELD(common, account_id) }, |
| 757 |
{ AST_EVENT_IE_REQUEST_PARAMS, SEC_EVT_FIELD(req_bad_format, request_params) }, |
| 758 |
{ AST_EVENT_IE_END, 0 } |
| 759 |
}, |
| 760 |
}, |
| 761 |
|
| 762 |
[AST_SECURITY_EVENT_SUCCESSFUL_AUTH] = { |
| 763 |
.name = "SuccessfulAuth", |
| 764 |
.version = AST_SECURITY_EVENT_SUCCESSFUL_AUTH_VERSION, |
| 765 |
.severity = AST_SECURITY_EVENT_SEVERITY_INFO, |
| 766 |
.required_ies = { |
| 767 |
{ AST_EVENT_IE_EVENT_TV, 0 }, |
| 768 |
{ AST_EVENT_IE_SEVERITY, 0 }, |
| 769 |
{ AST_EVENT_IE_SERVICE, SEC_EVT_FIELD(common, service) }, |
| 770 |
{ AST_EVENT_IE_EVENT_VERSION, SEC_EVT_FIELD(common, version) }, |
| 771 |
{ AST_EVENT_IE_ACCOUNT_ID, SEC_EVT_FIELD(common, account_id) }, |
| 772 |
{ AST_EVENT_IE_SESSION_ID, SEC_EVT_FIELD(common, session_id) }, |
| 773 |
{ AST_EVENT_IE_LOCAL_ADDR, SEC_EVT_FIELD(common, local_addr) }, |
| 774 |
{ AST_EVENT_IE_REMOTE_ADDR, SEC_EVT_FIELD(common, remote_addr) }, |
| 775 |
{ AST_EVENT_IE_USING_PASSWORD, SEC_EVT_FIELD(successful_auth, using_password) }, |
| 776 |
{ AST_EVENT_IE_END, 0 } |
| 777 |
}, |
| 778 |
.optional_ies = { |
| 779 |
{ AST_EVENT_IE_MODULE, SEC_EVT_FIELD(common, module) }, |
| 780 |
{ AST_EVENT_IE_SESSION_TV, SEC_EVT_FIELD(common, session_tv) }, |
| 781 |
{ AST_EVENT_IE_END, 0 } |
| 782 |
}, |
| 783 |
}, |
| 784 |
|
| 785 |
[AST_SECURITY_EVENT_UNEXPECTED_ADDR] = { |
| 786 |
.name = "UnexpectedAddress", |
| 787 |
.version = AST_SECURITY_EVENT_UNEXPECTED_ADDR_VERSION, |
| 788 |
.severity = AST_SECURITY_EVENT_SEVERITY_ERROR, |
| 789 |
.required_ies = { |
| 790 |
{ AST_EVENT_IE_EVENT_TV, 0 }, |
| 791 |
{ AST_EVENT_IE_SEVERITY, 0 }, |
| 792 |
{ AST_EVENT_IE_SERVICE, SEC_EVT_FIELD(common, service) }, |
| 793 |
{ AST_EVENT_IE_EVENT_VERSION, SEC_EVT_FIELD(common, version) }, |
| 794 |
{ AST_EVENT_IE_ACCOUNT_ID, SEC_EVT_FIELD(common, account_id) }, |
| 795 |
{ AST_EVENT_IE_SESSION_ID, SEC_EVT_FIELD(common, session_id) }, |
| 796 |
{ AST_EVENT_IE_LOCAL_ADDR, SEC_EVT_FIELD(common, local_addr) }, |
| 797 |
{ AST_EVENT_IE_REMOTE_ADDR, SEC_EVT_FIELD(common, remote_addr) }, |
| 798 |
{ AST_EVENT_IE_EXPECTED_ADDR, SEC_EVT_FIELD(unexpected_addr, expected_addr) }, |
| 799 |
{ AST_EVENT_IE_END, 0 } |
| 800 |
}, |
| 801 |
.optional_ies = { |
| 802 |
{ AST_EVENT_IE_MODULE, SEC_EVT_FIELD(common, module) }, |
| 803 |
{ AST_EVENT_IE_SESSION_TV, SEC_EVT_FIELD(common, session_tv) }, |
| 804 |
{ AST_EVENT_IE_END, 0 } |
| 805 |
}, |
| 806 |
}, |
| 807 |
|
| 808 |
[AST_SECURITY_EVENT_CHAL_RESP_FAILED] = { |
| 809 |
.name = "ChallengeResponseFailed", |
| 810 |
.version = AST_SECURITY_EVENT_CHAL_RESP_FAILED_VERSION, |
| 811 |
.severity = AST_SECURITY_EVENT_SEVERITY_ERROR, |
| 812 |
.required_ies = { |
| 813 |
{ AST_EVENT_IE_EVENT_TV, 0 }, |
| 814 |
{ AST_EVENT_IE_SEVERITY, 0 }, |
| 815 |
{ AST_EVENT_IE_SERVICE, SEC_EVT_FIELD(common, service) }, |
| 816 |
{ AST_EVENT_IE_EVENT_VERSION, SEC_EVT_FIELD(common, version) }, |
| 817 |
{ AST_EVENT_IE_ACCOUNT_ID, SEC_EVT_FIELD(common, account_id) }, |
| 818 |
{ AST_EVENT_IE_SESSION_ID, SEC_EVT_FIELD(common, session_id) }, |
| 819 |
{ AST_EVENT_IE_LOCAL_ADDR, SEC_EVT_FIELD(common, local_addr) }, |
| 820 |
{ AST_EVENT_IE_REMOTE_ADDR, SEC_EVT_FIELD(common, remote_addr) }, |
| 821 |
{ AST_EVENT_IE_CHALLENGE, SEC_EVT_FIELD(chal_resp_failed, challenge) }, |
| 822 |
{ AST_EVENT_IE_RESPONSE, SEC_EVT_FIELD(chal_resp_failed, response) }, |
| 823 |
{ AST_EVENT_IE_EXPECTED_RESPONSE, SEC_EVT_FIELD(chal_resp_failed, expected_response) }, |
| 824 |
{ AST_EVENT_IE_END, 0 } |
| 825 |
}, |
| 826 |
.optional_ies = { |
| 827 |
{ AST_EVENT_IE_MODULE, SEC_EVT_FIELD(common, module) }, |
| 828 |
{ AST_EVENT_IE_SESSION_TV, SEC_EVT_FIELD(common, session_tv) }, |
| 829 |
{ AST_EVENT_IE_END, 0 } |
| 830 |
}, |
| 831 |
}, |
| 832 |
|
| 833 |
[AST_SECURITY_EVENT_INVAL_PASSWORD] = { |
| 834 |
.name = "InvalidPassword", |
| 835 |
.version = AST_SECURITY_EVENT_INVAL_PASSWORD_VERSION, |
| 836 |
.severity = AST_SECURITY_EVENT_SEVERITY_ERROR, |
| 837 |
.required_ies = { |
| 838 |
{ AST_EVENT_IE_EVENT_TV, 0 }, |
| 839 |
{ AST_EVENT_IE_SEVERITY, 0 }, |
| 840 |
{ AST_EVENT_IE_SERVICE, SEC_EVT_FIELD(common, service) }, |
| 841 |
{ AST_EVENT_IE_EVENT_VERSION, SEC_EVT_FIELD(common, version) }, |
| 842 |
{ AST_EVENT_IE_ACCOUNT_ID, SEC_EVT_FIELD(common, account_id) }, |
| 843 |
{ AST_EVENT_IE_SESSION_ID, SEC_EVT_FIELD(common, session_id) }, |
| 844 |
{ AST_EVENT_IE_LOCAL_ADDR, SEC_EVT_FIELD(common, local_addr) }, |
| 845 |
{ AST_EVENT_IE_REMOTE_ADDR, SEC_EVT_FIELD(common, remote_addr) }, |
| 846 |
{ AST_EVENT_IE_END, 0 } |
| 847 |
}, |
| 848 |
.optional_ies = { |
| 849 |
{ AST_EVENT_IE_MODULE, SEC_EVT_FIELD(common, module) }, |
| 850 |
{ AST_EVENT_IE_SESSION_TV, SEC_EVT_FIELD(common, session_tv) }, |
| 851 |
{ AST_EVENT_IE_CHALLENGE, SEC_EVT_FIELD(inval_password, challenge) }, |
| 852 |
{ AST_EVENT_IE_RECEIVED_CHALLENGE, SEC_EVT_FIELD(inval_password, received_challenge) }, |
| 853 |
{ AST_EVENT_IE_RECEIVED_HASH, SEC_EVT_FIELD(inval_password, received_hash) }, |
| 854 |
{ AST_EVENT_IE_END, 0 } |
| 855 |
}, |
| 856 |
}, |
| 857 |
|
| 858 |
[AST_SECURITY_EVENT_CHAL_SENT] = { |
| 859 |
.name = "ChallengeSent", |
| 860 |
.version = AST_SECURITY_EVENT_CHAL_SENT_VERSION, |
| 861 |
.severity = AST_SECURITY_EVENT_SEVERITY_INFO, |
| 862 |
.required_ies = { |
| 863 |
{ AST_EVENT_IE_EVENT_TV, 0 }, |
| 864 |
{ AST_EVENT_IE_SEVERITY, 0 }, |
| 865 |
{ AST_EVENT_IE_SERVICE, SEC_EVT_FIELD(common, service) }, |
| 866 |
{ AST_EVENT_IE_EVENT_VERSION, SEC_EVT_FIELD(common, version) }, |
| 867 |
{ AST_EVENT_IE_ACCOUNT_ID, SEC_EVT_FIELD(common, account_id) }, |
| 868 |
{ AST_EVENT_IE_SESSION_ID, SEC_EVT_FIELD(common, session_id) }, |
| 869 |
{ AST_EVENT_IE_LOCAL_ADDR, SEC_EVT_FIELD(common, local_addr) }, |
| 870 |
{ AST_EVENT_IE_REMOTE_ADDR, SEC_EVT_FIELD(common, remote_addr) }, |
| 871 |
{ AST_EVENT_IE_CHALLENGE, SEC_EVT_FIELD(chal_sent, challenge) }, |
| 872 |
{ AST_EVENT_IE_END, 0 } |
| 873 |
}, |
| 874 |
.optional_ies = { |
| 875 |
{ AST_EVENT_IE_MODULE, SEC_EVT_FIELD(common, module) }, |
| 876 |
{ AST_EVENT_IE_SESSION_TV, SEC_EVT_FIELD(common, session_tv) }, |
| 877 |
{ AST_EVENT_IE_END, 0 } |
| 878 |
}, |
| 879 |
}, |
| 880 |
|
| 881 |
[AST_SECURITY_EVENT_INVAL_TRANSPORT] = { |
| 882 |
.name = "InvalidTransport", |
| 883 |
.version = AST_SECURITY_EVENT_INVAL_TRANSPORT_VERSION, |
| 884 |
.severity = AST_SECURITY_EVENT_SEVERITY_ERROR, |
| 885 |
.required_ies = { |
| 886 |
{ AST_EVENT_IE_EVENT_TV, 0 }, |
| 887 |
{ AST_EVENT_IE_SEVERITY, 0 }, |
| 888 |
{ AST_EVENT_IE_SERVICE, SEC_EVT_FIELD(common, service) }, |
| 889 |
{ AST_EVENT_IE_EVENT_VERSION, SEC_EVT_FIELD(common, version) }, |
| 890 |
{ AST_EVENT_IE_ACCOUNT_ID, SEC_EVT_FIELD(common, account_id) }, |
| 891 |
{ AST_EVENT_IE_SESSION_ID, SEC_EVT_FIELD(common, session_id) }, |
| 892 |
{ AST_EVENT_IE_LOCAL_ADDR, SEC_EVT_FIELD(common, local_addr) }, |
| 893 |
{ AST_EVENT_IE_REMOTE_ADDR, SEC_EVT_FIELD(common, remote_addr) }, |
| 894 |
{ AST_EVENT_IE_ATTEMPTED_TRANSPORT, SEC_EVT_FIELD(inval_transport, transport) }, |
| 895 |
{ AST_EVENT_IE_END, 0 } |
| 896 |
}, |
| 897 |
.optional_ies = { |
| 898 |
{ AST_EVENT_IE_MODULE, SEC_EVT_FIELD(common, module) }, |
| 899 |
{ AST_EVENT_IE_SESSION_TV, SEC_EVT_FIELD(common, session_tv) }, |
| 900 |
{ AST_EVENT_IE_END, 0 } |
| 901 |
}, |
| 902 |
}, |
| 903 |
|
| 904 |
#undef SEC_EVT_FIELD |
| 905 |
|
| 906 |
}; |
| 907 |
|
| 908 |
static const struct { |
| 909 |
enum ast_security_event_severity severity; |
| 910 |
const char *str; |
| 911 |
} severities[] = { |
| 912 |
{ AST_SECURITY_EVENT_SEVERITY_INFO, "Informational" }, |
| 913 |
{ AST_SECURITY_EVENT_SEVERITY_ERROR, "Error" }, |
| 914 |
}; |
| 915 |
|
| 916 |
const char *ast_security_event_severity_get_name( |
| 917 |
const enum ast_security_event_severity severity) |
| 918 |
{ |
| 919 |
unsigned int i; |
| 920 |
|
| 921 |
for (i = 0; i < ARRAY_LEN(severities); i++) { |
| 922 |
if (severities[i].severity == severity) { |
| 923 |
return severities[i].str; |
| 924 |
} |
| 925 |
} |
| 926 |
|
| 927 |
return NULL; |
| 928 |
} |
| 929 |
|
| 930 |
static int check_event_type(const enum ast_security_event_type event_type) |
| 931 |
{ |
| 932 |
if ((unsigned int)event_type >= AST_SECURITY_EVENT_NUM_TYPES) { |
| 933 |
ast_log(LOG_ERROR, "Invalid security event type %u\n", event_type); |
| 934 |
return -1; |
| 935 |
} |
| 936 |
|
| 937 |
return 0; |
| 938 |
} |
| 939 |
|
| 940 |
const char *ast_security_event_get_name(const enum ast_security_event_type event_type) |
| 941 |
{ |
| 942 |
if (check_event_type(event_type)) { |
| 943 |
return NULL; |
| 944 |
} |
| 945 |
|
| 946 |
return sec_events[event_type].name; |
| 947 |
} |
| 948 |
|
| 949 |
const struct ast_security_event_ie_type *ast_security_event_get_required_ies( |
| 950 |
const enum ast_security_event_type event_type) |
| 951 |
{ |
| 952 |
if (check_event_type(event_type)) { |
| 953 |
return NULL; |
| 954 |
} |
| 955 |
|
| 956 |
return sec_events[event_type].required_ies; |
| 957 |
} |
| 958 |
|
| 959 |
const struct ast_security_event_ie_type *ast_security_event_get_optional_ies( |
| 960 |
const enum ast_security_event_type event_type) |
| 961 |
{ |
| 962 |
if (check_event_type(event_type)) { |
| 963 |
return NULL; |
| 964 |
} |
| 965 |
|
| 966 |
return sec_events[event_type].optional_ies; |
| 967 |
} |
| 968 |
|
| 969 |
static int add_ip_json_object(struct ast_json *json, enum ast_event_ie_type ie_type, |
| 970 |
const struct ast_security_event_ip_addr *addr) |
| 971 |
{ |
| 972 |
struct ast_json *json_ip; |
| 973 |
|
| 974 |
json_ip = ast_json_ipaddr(addr->addr, addr->transport); |
| 975 |
if (!json_ip) { |
| 976 |
return -1; |
| 977 |
} |
| 978 |
|
| 979 |
return ast_json_object_set(json, ast_event_get_ie_type_name(ie_type), json_ip); |
| 980 |
} |
| 981 |
|
| 982 |
enum ie_required { |
| 983 |
NOT_REQUIRED, |
| 984 |
REQUIRED |
| 985 |
}; |
| 986 |
|
| 987 |
static int add_json_object(struct ast_json *json, const struct ast_security_event_common *sec, |
| 988 |
const struct ast_security_event_ie_type *ie_type, enum ie_required req) |
| 989 |
{ |
| 990 |
int res = 0; |
| 991 |
|
| 992 |
switch (ie_type->ie_type) { |
| 993 |
case AST_EVENT_IE_SERVICE: |
| 994 |
case AST_EVENT_IE_ACCOUNT_ID: |
| 995 |
case AST_EVENT_IE_SESSION_ID: |
| 996 |
case AST_EVENT_IE_MODULE: |
| 997 |
case AST_EVENT_IE_ACL_NAME: |
| 998 |
case AST_EVENT_IE_REQUEST_TYPE: |
| 999 |
case AST_EVENT_IE_REQUEST_PARAMS: |
| 1000 |
case AST_EVENT_IE_AUTH_METHOD: |
| 1001 |
case AST_EVENT_IE_CHALLENGE: |
| 1002 |
case AST_EVENT_IE_RESPONSE: |
| 1003 |
case AST_EVENT_IE_EXPECTED_RESPONSE: |
| 1004 |
case AST_EVENT_IE_RECEIVED_CHALLENGE: |
| 1005 |
case AST_EVENT_IE_RECEIVED_HASH: |
| 1006 |
case AST_EVENT_IE_ATTEMPTED_TRANSPORT: |
| 1007 |
{ |
| 1008 |
const char *str; |
| 1009 |
struct ast_json *json_string; |
| 1010 |
|
| 1011 |
str = *((const char **)(((const char *) sec) + ie_type->offset)); |
| 1012 |
|
| 1013 |
if (req && !str) { |
| 1014 |
ast_log(LOG_WARNING, "Required IE '%d' (%s) for security event " |
| 1015 |
"type '%u' (%s) not present\n", ie_type->ie_type, |
| 1016 |
ast_event_get_ie_type_name(ie_type->ie_type), |
| 1017 |
sec->event_type, ast_security_event_get_name(sec->event_type)); |
| 1018 |
res = -1; |
| 1019 |
break; |
| 1020 |
} |
| 1021 |
|
| 1022 |
if (!str) { |
| 1023 |
break; |
| 1024 |
} |
| 1025 |
|
| 1026 |
json_string = ast_json_string_create(str); |
| 1027 |
if (!json_string) { |
| 1028 |
res = -1; |
| 1029 |
break; |
| 1030 |
} |
| 1031 |
|
| 1032 |
res = ast_json_object_set(json, ast_event_get_ie_type_name(ie_type->ie_type), json_string); |
| 1033 |
break; |
| 1034 |
} |
| 1035 |
case AST_EVENT_IE_EVENT_VERSION: |
| 1036 |
case AST_EVENT_IE_USING_PASSWORD: |
| 1037 |
{ |
| 1038 |
struct ast_json *json_string; |
| 1039 |
uint32_t val; |
| 1040 |
val = *((const uint32_t *)(((const char *) sec) + ie_type->offset)); |
| 1041 |
|
| 1042 |
json_string = ast_json_stringf("%u", val); |
| 1043 |
if (!json_string) { |
| 1044 |
res = -1; |
| 1045 |
break; |
| 1046 |
} |
| 1047 |
|
| 1048 |
res = ast_json_object_set(json, ast_event_get_ie_type_name(ie_type->ie_type), json_string); |
| 1049 |
break; |
| 1050 |
} |
| 1051 |
case AST_EVENT_IE_LOCAL_ADDR: |
| 1052 |
case AST_EVENT_IE_REMOTE_ADDR: |
| 1053 |
case AST_EVENT_IE_EXPECTED_ADDR: |
| 1054 |
{ |
| 1055 |
const struct ast_security_event_ip_addr *addr; |
| 1056 |
|
| 1057 |
addr = (const struct ast_security_event_ip_addr *)(((const char *) sec) + ie_type->offset); |
| 1058 |
|
| 1059 |
if (req && !addr->addr) { |
| 1060 |
ast_log(LOG_WARNING, "Required IE '%d' (%s) for security event " |
| 1061 |
"type '%u' (%s) not present\n", ie_type->ie_type, |
| 1062 |
ast_event_get_ie_type_name(ie_type->ie_type), |
| 1063 |
sec->event_type, ast_security_event_get_name(sec->event_type)); |
| 1064 |
res = -1; |
| 1065 |
} |
| 1066 |
|
| 1067 |
if (addr->addr) { |
| 1068 |
res = add_ip_json_object(json, ie_type->ie_type, addr); |
| 1069 |
} |
| 1070 |
|
| 1071 |
break; |
| 1072 |
} |
| 1073 |
case AST_EVENT_IE_SESSION_TV: |
| 1074 |
{ |
| 1075 |
const struct timeval *tval; |
| 1076 |
|
| 1077 |
tval = *((const struct timeval **)(((const char *) sec) + ie_type->offset)); |
| 1078 |
|
| 1079 |
if (req && !tval) { |
| 1080 |
ast_log(LOG_WARNING, "Required IE '%d' (%s) for security event " |
| 1081 |
"type '%u' (%s) not present\n", ie_type->ie_type, |
| 1082 |
ast_event_get_ie_type_name(ie_type->ie_type), |
| 1083 |
sec->event_type, ast_security_event_get_name(sec->event_type)); |
| 1084 |
res = -1; |
| 1085 |
} |
| 1086 |
|
| 1087 |
if (tval) { |
| 1088 |
struct ast_json *json_tval = ast_json_timeval(*tval, NULL); |
| 1089 |
if (!json_tval) { |
| 1090 |
res = -1; |
| 1091 |
break; |
| 1092 |
} |
| 1093 |
res = ast_json_object_set(json, ast_event_get_ie_type_name(ie_type->ie_type), json_tval); |
| 1094 |
} |
| 1095 |
|
| 1096 |
break; |
| 1097 |
} |
| 1098 |
case AST_EVENT_IE_EVENT_TV: |
| 1099 |
case AST_EVENT_IE_SEVERITY: |
| 1100 |
|
| 1101 |
break; |
| 1102 |
default: |
| 1103 |
ast_log(LOG_WARNING, "Unhandled IE type '%d' (%s), this security event " |
| 1104 |
"will be missing data.\n", ie_type->ie_type, |
| 1105 |
ast_event_get_ie_type_name(ie_type->ie_type)); |
| 1106 |
break; |
| 1107 |
} |
| 1108 |
|
| 1109 |
return res; |
| 1110 |
} |
| 1111 |
|
| 1112 |
static struct ast_json *alloc_security_event_json_object(const struct ast_security_event_common *sec) |
| 1113 |
{ |
| 1114 |
struct timeval tv = ast_tvnow(); |
| 1115 |
const char *severity_str; |
| 1116 |
struct ast_json *json_temp; |
| 1117 |
RAII_VAR(struct ast_json *, json_object, ast_json_object_create(), ast_json_unref); |
| 1118 |
|
| 1119 |
if (!json_object) { |
| 1120 |
return NULL; |
| 1121 |
} |
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
json_temp = ast_json_integer_create(sec->event_type); |
| 1128 |
if (!json_temp || ast_json_object_set(json_object, "SecurityEvent", json_temp)) { |
| 1129 |
return NULL; |
| 1130 |
} |
| 1131 |
|
| 1132 |
json_temp = ast_json_stringf("%u", sec->version); |
| 1133 |
if (!json_temp || ast_json_object_set(json_object, ast_event_get_ie_type_name(AST_EVENT_IE_EVENT_VERSION), json_temp)) { |
| 1134 |
return NULL; |
| 1135 |
} |
| 1136 |
|
| 1137 |
|
| 1138 |
json_temp = ast_json_timeval(tv, NULL); |
| 1139 |
if (!json_temp || ast_json_object_set(json_object, ast_event_get_ie_type_name(AST_EVENT_IE_EVENT_TV), json_temp)) { |
| 1140 |
return NULL; |
| 1141 |
} |
| 1142 |
|
| 1143 |
|
| 1144 |
json_temp = ast_json_string_create(sec->service); |
| 1145 |
if (!json_temp || ast_json_object_set(json_object, ast_event_get_ie_type_name(AST_EVENT_IE_SERVICE), json_temp)) { |
| 1146 |
return NULL; |
| 1147 |
} |
| 1148 |
|
| 1149 |
|
| 1150 |
severity_str = S_OR( |
| 1151 |
ast_security_event_severity_get_name(sec_events[sec->event_type].severity), |
| 1152 |
"Unknown" |
| 1153 |
); |
| 1154 |
|
| 1155 |
json_temp = ast_json_string_create(severity_str); |
| 1156 |
if (!json_temp || ast_json_object_set(json_object, ast_event_get_ie_type_name(AST_EVENT_IE_SEVERITY), json_temp)) { |
| 1157 |
return NULL; |
| 1158 |
} |
| 1159 |
|
| 1160 |
return ast_json_ref(json_object); |
| 1161 |
} |
| 1162 |
|
| 1163 |
static int handle_security_event(const struct ast_security_event_common *sec) |
| 1164 |
{ |
| 1165 |
RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup); |
| 1166 |
RAII_VAR(struct ast_json_payload *, json_payload, NULL, ao2_cleanup); |
| 1167 |
RAII_VAR(struct ast_json *, json_object, NULL, ast_json_unref); |
| 1168 |
|
| 1169 |
const struct ast_security_event_ie_type *ies; |
| 1170 |
unsigned int i; |
| 1171 |
|
| 1172 |
if (!ast_security_event_type()) { |
| 1173 |
return -1; |
| 1174 |
} |
| 1175 |
|
| 1176 |
json_object = alloc_security_event_json_object(sec); |
| 1177 |
if (!json_object) { |
| 1178 |
return -1; |
| 1179 |
} |
| 1180 |
|
| 1181 |
for (ies = ast_security_event_get_required_ies(sec->event_type), i = 0; |
| 1182 |
ies[i].ie_type != AST_EVENT_IE_END; |
| 1183 |
i++) { |
| 1184 |
if (add_json_object(json_object, sec, ies + i, REQUIRED)) { |
| 1185 |
goto return_error; |
| 1186 |
} |
| 1187 |
} |
| 1188 |
|
| 1189 |
for (ies = ast_security_event_get_optional_ies(sec->event_type), i = 0; |
| 1190 |
ies[i].ie_type != AST_EVENT_IE_END; |
| 1191 |
i++) { |
| 1192 |
if (add_json_object(json_object, sec, ies + i, NOT_REQUIRED)) { |
| 1193 |
goto return_error; |
| 1194 |
} |
| 1195 |
} |
| 1196 |
|
| 1197 |
|
| 1198 |
if (!(json_payload = ast_json_payload_create(json_object))) { |
| 1199 |
goto return_error; |
| 1200 |
} |
| 1201 |
|
| 1202 |
msg = stasis_message_create(ast_security_event_type(), json_payload); |
| 1203 |
|
| 1204 |
if (!msg) { |
| 1205 |
goto return_error; |
| 1206 |
} |
| 1207 |
|
| 1208 |
stasis_publish(ast_security_topic(), msg); |
| 1209 |
|
| 1210 |
return 0; |
| 1211 |
|
| 1212 |
return_error: |
| 1213 |
return -1; |
| 1214 |
} |
| 1215 |
|
| 1216 |
int ast_security_event_report(const struct ast_security_event_common *sec) |
| 1217 |
{ |
| 1218 |
if ((unsigned int)sec->event_type >= AST_SECURITY_EVENT_NUM_TYPES) { |
| 1219 |
ast_log(LOG_ERROR, "Invalid security event type\n"); |
| 1220 |
return -1; |
| 1221 |
} |
| 1222 |
|
| 1223 |
if (!sec_events[sec->event_type].name) { |
| 1224 |
ast_log(LOG_WARNING, "Security event type %u not handled\n", |
| 1225 |
sec->event_type); |
| 1226 |
return -1; |
| 1227 |
} |
| 1228 |
|
| 1229 |
if (sec->version != sec_events[sec->event_type].version) { |
| 1230 |
ast_log(LOG_WARNING, "Security event %u version mismatch\n", |
| 1231 |
sec->event_type); |
| 1232 |
return -1; |
| 1233 |
} |
| 1234 |
|
| 1235 |
if (handle_security_event(sec)) { |
| 1236 |
ast_log(LOG_ERROR, "Failed to issue security event of type %s.\n", |
| 1237 |
ast_security_event_get_name(sec->event_type)); |
| 1238 |
} |
| 1239 |
|
| 1240 |
return 0; |
| 1241 |
} |