security_events_defs.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  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 Security Event Reporting Data Structures
  22. *
  23. * \author Russell Bryant <russell@digium.com>
  24. */
  25. #ifndef __AST_SECURITY_EVENTS_DEFS_H__
  26. #define __AST_SECURITY_EVENTS_DEFS_H__
  27. #include "asterisk/network.h"
  28. #include "asterisk/netsock2.h"
  29. #if defined(__cplusplus) || defined(c_plusplus)
  30. extern "C" {
  31. #endif
  32. /*!
  33. * \brief Security event types
  34. */
  35. enum ast_security_event_type {
  36. /*!
  37. * \brief Failed ACL
  38. *
  39. * This security event should be generated when an incoming request
  40. * was made, but was denied due to configured IP address access control
  41. * lists.
  42. */
  43. AST_SECURITY_EVENT_FAILED_ACL,
  44. /*!
  45. * \brief Invalid Account ID
  46. *
  47. * This event is used when an invalid account identifier is supplied
  48. * during authentication. For example, if an invalid username is given,
  49. * this event should be used.
  50. */
  51. AST_SECURITY_EVENT_INVAL_ACCT_ID,
  52. /*!
  53. * \brief Session limit reached
  54. *
  55. * A request has been denied because a configured session limit has been
  56. * reached, such as a call limit.
  57. */
  58. AST_SECURITY_EVENT_SESSION_LIMIT,
  59. /*!
  60. * \brief Memory limit reached
  61. *
  62. * A request has been denied because a configured memory limit has been
  63. * reached.
  64. */
  65. AST_SECURITY_EVENT_MEM_LIMIT,
  66. /*!
  67. * \brief Load Average limit reached
  68. *
  69. * A request has been denied because a configured load average limit has been
  70. * reached.
  71. */
  72. AST_SECURITY_EVENT_LOAD_AVG,
  73. /*!
  74. * \brief A request was made that we understand, but do not support
  75. */
  76. AST_SECURITY_EVENT_REQ_NO_SUPPORT,
  77. /*!
  78. * \brief A request was made that is not allowed
  79. */
  80. AST_SECURITY_EVENT_REQ_NOT_ALLOWED,
  81. /*!
  82. * \brief The attempted authentication method is not allowed
  83. */
  84. AST_SECURITY_EVENT_AUTH_METHOD_NOT_ALLOWED,
  85. /*!
  86. * \brief Request received with bad formatting
  87. */
  88. AST_SECURITY_EVENT_REQ_BAD_FORMAT,
  89. /*!
  90. * \brief FYI FWIW, Successful authentication has occurred
  91. */
  92. AST_SECURITY_EVENT_SUCCESSFUL_AUTH,
  93. /*!
  94. * \brief An unexpected source address was seen for a session in progress
  95. */
  96. AST_SECURITY_EVENT_UNEXPECTED_ADDR,
  97. /*!
  98. * \brief An attempt at challenge/response authentication failed
  99. */
  100. AST_SECURITY_EVENT_CHAL_RESP_FAILED,
  101. /*!
  102. * \brief An attempt at basic password authentication failed
  103. */
  104. AST_SECURITY_EVENT_INVAL_PASSWORD,
  105. /*!
  106. * \brief Challenge was sent out, informational
  107. */
  108. AST_SECURITY_EVENT_CHAL_SENT,
  109. /*!
  110. * \brief An attempt to contact a peer on an invalid transport.
  111. */
  112. AST_SECURITY_EVENT_INVAL_TRANSPORT,
  113. /*!
  114. * \brief This _must_ stay at the end.
  115. */
  116. AST_SECURITY_EVENT_NUM_TYPES
  117. };
  118. /*!
  119. * \brief the severity of a security event
  120. *
  121. * This is defined as a bit field to make it easy for consumers of the API to
  122. * subscribe to any combination of the defined severity levels.
  123. *
  124. * XXX \todo Do we need any more levels here?
  125. */
  126. enum ast_security_event_severity {
  127. /*! \brief Informational event, not something that has gone wrong */
  128. AST_SECURITY_EVENT_SEVERITY_INFO = (1 << 0),
  129. /*! \brief Something has gone wrong */
  130. AST_SECURITY_EVENT_SEVERITY_ERROR = (1 << 1),
  131. };
  132. #define AST_SEC_EVT(e) ((struct ast_security_event_common *) e)
  133. struct ast_security_event_ip_addr {
  134. const struct ast_sockaddr *addr;
  135. enum ast_transport transport;
  136. };
  137. /*!
  138. * \brief Common structure elements
  139. *
  140. * This is the structure header for all event descriptor structures defined
  141. * below. The contents of this structure are very important and must not
  142. * change. Even though these structures are exposed via a public API, we have
  143. * a version field that can be used to ensure ABI safety. If the event
  144. * descriptors need to be changed or updated in the future, we can safely do
  145. * so and can detect ABI changes at runtime.
  146. */
  147. struct ast_security_event_common {
  148. /*! \brief The security event sub-type */
  149. enum ast_security_event_type event_type;
  150. /*! \brief security event version */
  151. uint32_t version;
  152. /*!
  153. * \brief Service that generated the event
  154. * \note Always required
  155. *
  156. * Examples: "SIP", "AMI"
  157. */
  158. const char *service;
  159. /*!
  160. * \brief Module, Normally the AST_MODULE define
  161. * \note Always optional
  162. */
  163. const char *module;
  164. /*!
  165. * \brief Account ID, specific to the service type
  166. * \note optional/required, depending on event type
  167. */
  168. const char *account_id;
  169. /*!
  170. * \brief Session ID, specific to the service type
  171. * \note Always required
  172. */
  173. const char *session_id;
  174. /*!
  175. * \brief Session timeval, when the session started
  176. * \note Always optional
  177. */
  178. const struct timeval *session_tv;
  179. /*!
  180. * \brief Local address the request came in on
  181. * \note Always required
  182. */
  183. struct ast_security_event_ip_addr local_addr;
  184. /*!
  185. * \brief Remote address the request came from
  186. * \note Always required
  187. */
  188. struct ast_security_event_ip_addr remote_addr;
  189. };
  190. /*!
  191. * \brief Checking against an IP access control list failed
  192. */
  193. struct ast_security_event_failed_acl {
  194. /*!
  195. * \brief Event descriptor version
  196. * \note This _must_ be changed if this event descriptor is changed.
  197. */
  198. #define AST_SECURITY_EVENT_FAILED_ACL_VERSION 1
  199. /*!
  200. * \brief Common security event descriptor elements
  201. * \note Account ID required
  202. */
  203. struct ast_security_event_common common;
  204. /*!
  205. * \brief ACL name, identifies which ACL was hit
  206. * \note optional
  207. */
  208. const char *acl_name;
  209. };
  210. /*!
  211. * \brief Invalid account ID specified (invalid username, for example)
  212. */
  213. struct ast_security_event_inval_acct_id {
  214. /*!
  215. * \brief Event descriptor version
  216. * \note This _must_ be changed if this event descriptor is changed.
  217. */
  218. #define AST_SECURITY_EVENT_INVAL_ACCT_ID_VERSION 1
  219. /*!
  220. * \brief Common security event descriptor elements
  221. * \note Account ID required
  222. */
  223. struct ast_security_event_common common;
  224. };
  225. /*!
  226. * \brief Request denied because of a session limit
  227. */
  228. struct ast_security_event_session_limit {
  229. /*!
  230. * \brief Event descriptor version
  231. * \note This _must_ be changed if this event descriptor is changed.
  232. */
  233. #define AST_SECURITY_EVENT_SESSION_LIMIT_VERSION 1
  234. /*!
  235. * \brief Common security event descriptor elements
  236. * \note Account ID required
  237. */
  238. struct ast_security_event_common common;
  239. };
  240. /*!
  241. * \brief Request denied because of a memory limit
  242. */
  243. struct ast_security_event_mem_limit {
  244. /*!
  245. * \brief Event descriptor version
  246. * \note This _must_ be changed if this event descriptor is changed.
  247. */
  248. #define AST_SECURITY_EVENT_MEM_LIMIT_VERSION 1
  249. /*!
  250. * \brief Common security event descriptor elements
  251. * \note Account ID required
  252. */
  253. struct ast_security_event_common common;
  254. };
  255. /*!
  256. * \brief Request denied because of a load average limit
  257. */
  258. struct ast_security_event_load_avg {
  259. /*!
  260. * \brief Event descriptor version
  261. * \note This _must_ be changed if this event descriptor is changed.
  262. */
  263. #define AST_SECURITY_EVENT_LOAD_AVG_VERSION 1
  264. /*!
  265. * \brief Common security event descriptor elements
  266. * \note Account ID required
  267. */
  268. struct ast_security_event_common common;
  269. };
  270. /*!
  271. * \brief Request denied because we don't support it
  272. */
  273. struct ast_security_event_req_no_support {
  274. /*!
  275. * \brief Event descriptor version
  276. * \note This _must_ be changed if this event descriptor is changed.
  277. */
  278. #define AST_SECURITY_EVENT_REQ_NO_SUPPORT_VERSION 1
  279. /*!
  280. * \brief Common security event descriptor elements
  281. * \note Account ID required
  282. */
  283. struct ast_security_event_common common;
  284. /*!
  285. * \brief Request type that was made
  286. * \note required
  287. */
  288. const char *request_type;
  289. };
  290. /*!
  291. * \brief Request denied because it's not allowed
  292. */
  293. struct ast_security_event_req_not_allowed {
  294. /*!
  295. * \brief Event descriptor version
  296. * \note This _must_ be changed if this event descriptor is changed.
  297. */
  298. #define AST_SECURITY_EVENT_REQ_NOT_ALLOWED_VERSION 1
  299. /*!
  300. * \brief Common security event descriptor elements
  301. * \note Account ID required
  302. */
  303. struct ast_security_event_common common;
  304. /*!
  305. * \brief Request type that was made
  306. * \note required
  307. */
  308. const char *request_type;
  309. /*!
  310. * \brief Request type that was made
  311. * \note optional
  312. */
  313. const char *request_params;
  314. };
  315. /*!
  316. * \brief Auth method used not allowed
  317. */
  318. struct ast_security_event_auth_method_not_allowed {
  319. /*!
  320. * \brief Event descriptor version
  321. * \note This _must_ be changed if this event descriptor is changed.
  322. */
  323. #define AST_SECURITY_EVENT_AUTH_METHOD_NOT_ALLOWED_VERSION 1
  324. /*!
  325. * \brief Common security event descriptor elements
  326. * \note Account ID required
  327. */
  328. struct ast_security_event_common common;
  329. /*!
  330. * \brief Auth method attempted
  331. * \note required
  332. */
  333. const char *auth_method;
  334. };
  335. /*!
  336. * \brief Invalid formatting of request
  337. */
  338. struct ast_security_event_req_bad_format {
  339. /*!
  340. * \brief Event descriptor version
  341. * \note This _must_ be changed if this event descriptor is changed.
  342. */
  343. #define AST_SECURITY_EVENT_REQ_BAD_FORMAT_VERSION 1
  344. /*!
  345. * \brief Common security event descriptor elements
  346. * \note Account ID optional
  347. */
  348. struct ast_security_event_common common;
  349. /*!
  350. * \brief Request type that was made
  351. * \note required
  352. */
  353. const char *request_type;
  354. /*!
  355. * \brief Request type that was made
  356. * \note optional
  357. */
  358. const char *request_params;
  359. };
  360. /*!
  361. * \brief Successful authentication
  362. */
  363. struct ast_security_event_successful_auth {
  364. /*!
  365. * \brief Event descriptor version
  366. * \note This _must_ be changed if this event descriptor is changed.
  367. */
  368. #define AST_SECURITY_EVENT_SUCCESSFUL_AUTH_VERSION 1
  369. /*!
  370. * \brief Common security event descriptor elements
  371. * \note Account ID required
  372. */
  373. struct ast_security_event_common common;
  374. /*!
  375. * \brief Using password - if a password was used or not
  376. * \note required, 0 = no, 1 = yes
  377. */
  378. uint32_t using_password;
  379. };
  380. /*!
  381. * \brief Unexpected source address for a session in progress
  382. */
  383. struct ast_security_event_unexpected_addr {
  384. /*!
  385. * \brief Event descriptor version
  386. * \note This _must_ be changed if this event descriptor is changed.
  387. */
  388. #define AST_SECURITY_EVENT_UNEXPECTED_ADDR_VERSION 2
  389. /*!
  390. * \brief Common security event descriptor elements
  391. * \note Account ID required
  392. */
  393. struct ast_security_event_common common;
  394. /*!
  395. * \brief Expected remote address
  396. * \note required
  397. */
  398. struct ast_security_event_ip_addr expected_addr;
  399. };
  400. /*!
  401. * \brief An attempt at challenge/response auth failed
  402. */
  403. struct ast_security_event_chal_resp_failed {
  404. /*!
  405. * \brief Event descriptor version
  406. * \note This _must_ be changed if this event descriptor is changed.
  407. */
  408. #define AST_SECURITY_EVENT_CHAL_RESP_FAILED_VERSION 1
  409. /*!
  410. * \brief Common security event descriptor elements
  411. * \note Account ID required
  412. */
  413. struct ast_security_event_common common;
  414. /*!
  415. * \brief Challenge provided
  416. * \note required
  417. */
  418. const char *challenge;
  419. /*!
  420. * \brief Response received
  421. * \note required
  422. */
  423. const char *response;
  424. /*!
  425. * \brief Response expected to be received
  426. * \note required
  427. */
  428. const char *expected_response;
  429. };
  430. /*!
  431. * \brief An attempt at basic password auth failed
  432. */
  433. struct ast_security_event_inval_password {
  434. /*!
  435. * \brief Event descriptor version
  436. * \note This _must_ be changed if this event descriptor is changed.
  437. */
  438. #define AST_SECURITY_EVENT_INVAL_PASSWORD_VERSION 2
  439. /*!
  440. * \brief Common security event descriptor elements
  441. * \note Account ID required
  442. */
  443. struct ast_security_event_common common;
  444. /*!
  445. * \brief Challenge provided
  446. * \note required
  447. */
  448. const char *challenge;
  449. /*!
  450. * \brief Challenge received
  451. * \note required
  452. */
  453. const char *received_challenge;
  454. /*!
  455. * \brief Hash received
  456. * \note required
  457. */
  458. const char *received_hash;
  459. };
  460. /*!
  461. * \brief A challenge was sent out
  462. */
  463. struct ast_security_event_chal_sent {
  464. /*!
  465. * \brief Event descriptor version
  466. * \note This _must_ be changed if this event descriptor is changed.
  467. */
  468. #define AST_SECURITY_EVENT_CHAL_SENT_VERSION 1
  469. /*!
  470. * \brief Common security event descriptor elements
  471. * \note Account ID required
  472. */
  473. struct ast_security_event_common common;
  474. /*!
  475. * \brief Challenge sent
  476. * \note required
  477. */
  478. const char *challenge;
  479. };
  480. /*!
  481. * \brief Attempt to contact peer on invalid transport
  482. */
  483. struct ast_security_event_inval_transport {
  484. /*!
  485. * \brief Event descriptor version
  486. * \note This _must_ be changed if this event descriptor is changed.
  487. */
  488. #define AST_SECURITY_EVENT_INVAL_TRANSPORT_VERSION 1
  489. /*!
  490. * \brief Common security event descriptor elements
  491. * \note Account ID required
  492. */
  493. struct ast_security_event_common common;
  494. /*!
  495. * \brief Attempted transport
  496. * \note required
  497. */
  498. const char *transport;
  499. };
  500. #if defined(__cplusplus) || defined(c_plusplus)
  501. }
  502. #endif
  503. #endif /* __AST_SECURITY_EVENTS_DEFS_H__ */