security_events.c 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198
  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 Helpers
  22. *
  23. * \author Russell Bryant <russell@digium.com>
  24. */
  25. /*** MODULEINFO
  26. <support_level>core</support_level>
  27. ***/
  28. /*** DOCUMENTATION
  29. <managerEvent language="en_US" name="FailedACL">
  30. <managerEventInstance class="EVENT_FLAG_SECURITY">
  31. <synopsis>Raised when a request violates an ACL check.</synopsis>
  32. <syntax>
  33. <parameter name="EventTV">
  34. <para>The time the event was detected.</para>
  35. </parameter>
  36. <parameter name="Severity">
  37. <para>A relative severity of the security event.</para>
  38. <enumlist>
  39. <enum name="Informational"/>
  40. <enum name="Error"/>
  41. </enumlist>
  42. </parameter>
  43. <parameter name="Service">
  44. <para>The Asterisk service that raised the security event.</para>
  45. </parameter>
  46. <parameter name="EventVersion">
  47. <para>The version of this event.</para>
  48. </parameter>
  49. <parameter name="AccountID">
  50. <para>The Service account associated with the security event
  51. notification.</para>
  52. </parameter>
  53. <parameter name="SessionID">
  54. <para>A unique identifier for the session in the service
  55. that raised the event.</para>
  56. </parameter>
  57. <parameter name="LocalAddress">
  58. <para>The address of the Asterisk service that raised the
  59. security event.</para>
  60. </parameter>
  61. <parameter name="RemoteAddress">
  62. <para>The remote address of the entity that caused the
  63. security event to be raised.</para>
  64. </parameter>
  65. <parameter name="Module" required="false">
  66. <para>If available, the name of the module that raised the event.</para>
  67. </parameter>
  68. <parameter name="ACLName" required="false">
  69. <para>If available, the name of the ACL that failed.</para>
  70. </parameter>
  71. <parameter name="SessionTV" required="false">
  72. <para>The timestamp reported by the session.</para>
  73. </parameter>
  74. </syntax>
  75. </managerEventInstance>
  76. </managerEvent>
  77. <managerEvent language="en_US" name="InvalidAccountID">
  78. <managerEventInstance class="EVENT_FLAG_SECURITY">
  79. <synopsis>Raised when a request fails an authentication check due to an invalid account ID.</synopsis>
  80. <syntax>
  81. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='EventTV'])" />
  82. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Severity'])" />
  83. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Service'])" />
  84. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='EventVersion'])" />
  85. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='AccountID'])" />
  86. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='SessionID'])" />
  87. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='LocalAddress'])" />
  88. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='RemoteAddress'])" />
  89. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Module'])" />
  90. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='SessionTV'])" />
  91. </syntax>
  92. </managerEventInstance>
  93. </managerEvent>
  94. <managerEvent language="en_US" name="SessionLimit">
  95. <managerEventInstance class="EVENT_FLAG_SECURITY">
  96. <synopsis>Raised when a request fails due to exceeding the number of allowed concurrent sessions for that service.</synopsis>
  97. <syntax>
  98. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='EventTV'])" />
  99. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Severity'])" />
  100. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Service'])" />
  101. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='EventVersion'])" />
  102. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='AccountID'])" />
  103. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='SessionID'])" />
  104. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='LocalAddress'])" />
  105. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='RemoteAddress'])" />
  106. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Module'])" />
  107. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='SessionTV'])" />
  108. </syntax>
  109. </managerEventInstance>
  110. </managerEvent>
  111. <managerEvent language="en_US" name="MemoryLimit">
  112. <managerEventInstance class="EVENT_FLAG_SECURITY">
  113. <synopsis>Raised when a request fails due to an internal memory allocation failure.</synopsis>
  114. <syntax>
  115. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='EventTV'])" />
  116. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Severity'])" />
  117. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Service'])" />
  118. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='EventVersion'])" />
  119. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='AccountID'])" />
  120. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='SessionID'])" />
  121. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='LocalAddress'])" />
  122. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='RemoteAddress'])" />
  123. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Module'])" />
  124. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='SessionTV'])" />
  125. </syntax>
  126. </managerEventInstance>
  127. </managerEvent>
  128. <managerEvent language="en_US" name="LoadAverageLimit">
  129. <managerEventInstance class="EVENT_FLAG_SECURITY">
  130. <synopsis>Raised when a request fails because a configured load average limit has been reached.</synopsis>
  131. <syntax>
  132. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='EventTV'])" />
  133. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Severity'])" />
  134. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Service'])" />
  135. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='EventVersion'])" />
  136. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='AccountID'])" />
  137. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='SessionID'])" />
  138. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='LocalAddress'])" />
  139. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='RemoteAddress'])" />
  140. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Module'])" />
  141. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='SessionTV'])" />
  142. </syntax>
  143. </managerEventInstance>
  144. </managerEvent>
  145. <managerEvent language="en_US" name="RequestNotSupported">
  146. <managerEventInstance class="EVENT_FLAG_SECURITY">
  147. <synopsis>Raised when a request fails due to some aspect of the requested item not being supported by the service.</synopsis>
  148. <syntax>
  149. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='EventTV'])" />
  150. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Severity'])" />
  151. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Service'])" />
  152. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='EventVersion'])" />
  153. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='AccountID'])" />
  154. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='SessionID'])" />
  155. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='LocalAddress'])" />
  156. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='RemoteAddress'])" />
  157. <parameter name="RequestType">
  158. <para>The type of request attempted.</para>
  159. </parameter>
  160. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Module'])" />
  161. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='SessionTV'])" />
  162. </syntax>
  163. </managerEventInstance>
  164. </managerEvent>
  165. <managerEvent language="en_US" name="RequestNotAllowed">
  166. <managerEventInstance class="EVENT_FLAG_SECURITY">
  167. <synopsis>Raised when a request is not allowed by the service.</synopsis>
  168. <syntax>
  169. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='EventTV'])" />
  170. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Severity'])" />
  171. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Service'])" />
  172. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='EventVersion'])" />
  173. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='AccountID'])" />
  174. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='SessionID'])" />
  175. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='LocalAddress'])" />
  176. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='RemoteAddress'])" />
  177. <xi:include xpointer="xpointer(/docs/managerEvent[@name='RequestNotSupported']/managerEventInstance/syntax/parameter[@name='RequestType'])" />
  178. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Module'])" />
  179. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='SessionTV'])" />
  180. <parameter name="RequestParams" required="false">
  181. <para>Parameters provided to the rejected request.</para>
  182. </parameter>
  183. </syntax>
  184. </managerEventInstance>
  185. </managerEvent>
  186. <managerEvent language="en_US" name="AuthMethodNotAllowed">
  187. <managerEventInstance class="EVENT_FLAG_SECURITY">
  188. <synopsis>Raised when a request used an authentication method not allowed by the service.</synopsis>
  189. <syntax>
  190. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='EventTV'])" />
  191. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Severity'])" />
  192. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Service'])" />
  193. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='EventVersion'])" />
  194. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='AccountID'])" />
  195. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='SessionID'])" />
  196. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='LocalAddress'])" />
  197. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='RemoteAddress'])" />
  198. <parameter name="AuthMethod">
  199. <para>The authentication method attempted.</para>
  200. </parameter>
  201. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Module'])" />
  202. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='SessionTV'])" />
  203. </syntax>
  204. </managerEventInstance>
  205. </managerEvent>
  206. <managerEvent language="en_US" name="RequestBadFormat">
  207. <managerEventInstance class="EVENT_FLAG_SECURITY">
  208. <synopsis>Raised when a request is received with bad formatting.</synopsis>
  209. <syntax>
  210. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='EventTV'])" />
  211. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Severity'])" />
  212. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Service'])" />
  213. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='EventVersion'])" />
  214. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='AccountID'])" />
  215. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='SessionID'])" />
  216. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='LocalAddress'])" />
  217. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='RemoteAddress'])" />
  218. <xi:include xpointer="xpointer(/docs/managerEvent[@name='RequestNotSupported']/managerEventInstance/syntax/parameter[@name='RequestType'])" />
  219. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Module'])" />
  220. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='SessionTV'])" />
  221. <parameter name="AccountID" required="false">
  222. <para>The account ID associated with the rejected request.</para>
  223. </parameter>
  224. <xi:include xpointer="xpointer(/docs/managerEvent[@name='RequestNotAllowed']/managerEventInstance/syntax/parameter[@name='RequestParams'])" />
  225. </syntax>
  226. </managerEventInstance>
  227. </managerEvent>
  228. <managerEvent language="en_US" name="SuccessfulAuth">
  229. <managerEventInstance class="EVENT_FLAG_SECURITY">
  230. <synopsis>Raised when a request successfully authenticates with a service.</synopsis>
  231. <syntax>
  232. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='EventTV'])" />
  233. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Severity'])" />
  234. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Service'])" />
  235. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='EventVersion'])" />
  236. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='AccountID'])" />
  237. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='SessionID'])" />
  238. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='LocalAddress'])" />
  239. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='RemoteAddress'])" />
  240. <parameter name="UsingPassword">
  241. <para>Whether or not the authentication attempt included a password.</para>
  242. </parameter>
  243. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Module'])" />
  244. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='SessionTV'])" />
  245. </syntax>
  246. </managerEventInstance>
  247. </managerEvent>
  248. <managerEvent language="en_US" name="UnexpectedAddress">
  249. <managerEventInstance class="EVENT_FLAG_SECURITY">
  250. <synopsis>Raised when a request has a different source address then what is expected for a session already in progress with a service.</synopsis>
  251. <syntax>
  252. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='EventTV'])" />
  253. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Severity'])" />
  254. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Service'])" />
  255. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='EventVersion'])" />
  256. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='AccountID'])" />
  257. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='SessionID'])" />
  258. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='LocalAddress'])" />
  259. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='RemoteAddress'])" />
  260. <parameter name="ExpectedAddress">
  261. <para>The address that the request was expected to use.</para>
  262. </parameter>
  263. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Module'])" />
  264. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='SessionTV'])" />
  265. </syntax>
  266. </managerEventInstance>
  267. </managerEvent>
  268. <managerEvent language="en_US" name="ChallengeResponseFailed">
  269. <managerEventInstance class="EVENT_FLAG_SECURITY">
  270. <synopsis>Raised when a request's attempt to authenticate has been challenged, and the request failed the authentication challenge.</synopsis>
  271. <syntax>
  272. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='EventTV'])" />
  273. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Severity'])" />
  274. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Service'])" />
  275. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='EventVersion'])" />
  276. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='AccountID'])" />
  277. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='SessionID'])" />
  278. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='LocalAddress'])" />
  279. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='RemoteAddress'])" />
  280. <parameter name="Challenge">
  281. <para>The challenge that was sent.</para>
  282. </parameter>
  283. <parameter name="Response">
  284. <para>The response that was received.</para>
  285. </parameter>
  286. <parameter name="ExpectedResponse">
  287. <para>The expected response to the challenge.</para>
  288. </parameter>
  289. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Module'])" />
  290. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='SessionTV'])" />
  291. </syntax>
  292. </managerEventInstance>
  293. </managerEvent>
  294. <managerEvent language="en_US" name="InvalidPassword">
  295. <managerEventInstance class="EVENT_FLAG_SECURITY">
  296. <synopsis>Raised when a request provides an invalid password during an authentication attempt.</synopsis>
  297. <syntax>
  298. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='EventTV'])" />
  299. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Severity'])" />
  300. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Service'])" />
  301. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='EventVersion'])" />
  302. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='AccountID'])" />
  303. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='SessionID'])" />
  304. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='LocalAddress'])" />
  305. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='RemoteAddress'])" />
  306. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Module'])" />
  307. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='SessionTV'])" />
  308. <parameter name="Challenge" required="false">
  309. <para>The challenge that was sent.</para>
  310. </parameter>
  311. <parameter name="ReceivedChallenge" required="false">
  312. <para>The challenge that was received.</para>
  313. </parameter>
  314. <parameter name="ReceivedHash" required="false">
  315. <para>The hash that was received.</para>
  316. </parameter>
  317. </syntax>
  318. </managerEventInstance>
  319. </managerEvent>
  320. <managerEvent language="en_US" name="ChallengeSent">
  321. <managerEventInstance class="EVENT_FLAG_SECURITY">
  322. <synopsis>Raised when an Asterisk service sends an authentication challenge to a request.</synopsis>
  323. <syntax>
  324. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='EventTV'])" />
  325. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Severity'])" />
  326. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Service'])" />
  327. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='EventVersion'])" />
  328. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='AccountID'])" />
  329. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='SessionID'])" />
  330. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='LocalAddress'])" />
  331. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='RemoteAddress'])" />
  332. <xi:include xpointer="xpointer(/docs/managerEvent[@name='ChallengeResponseFailed']/managerEventInstance/syntax/parameter[@name='Challenge'])" />
  333. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Module'])" />
  334. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='SessionTV'])" />
  335. </syntax>
  336. </managerEventInstance>
  337. </managerEvent>
  338. <managerEvent language="en_US" name="InvalidTransport">
  339. <managerEventInstance class="EVENT_FLAG_SECURITY">
  340. <synopsis>Raised when a request attempts to use a transport not allowed by the Asterisk service.</synopsis>
  341. <syntax>
  342. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='EventTV'])" />
  343. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Severity'])" />
  344. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Service'])" />
  345. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='EventVersion'])" />
  346. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='AccountID'])" />
  347. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='SessionID'])" />
  348. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='LocalAddress'])" />
  349. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='RemoteAddress'])" />
  350. <parameter name="AttemptedTransport">
  351. <para>The transport type that the request attempted to use.</para>
  352. </parameter>
  353. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='Module'])" />
  354. <xi:include xpointer="xpointer(/docs/managerEvent[@name='FailedACL']/managerEventInstance/syntax/parameter[@name='SessionTV'])" />
  355. </syntax>
  356. </managerEventInstance>
  357. </managerEvent>
  358. ***/
  359. #include "asterisk.h"
  360. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  361. #include "asterisk/utils.h"
  362. #include "asterisk/strings.h"
  363. #include "asterisk/network.h"
  364. #include "asterisk/event.h"
  365. #include "asterisk/security_events.h"
  366. #include "asterisk/netsock2.h"
  367. #include "asterisk/stasis.h"
  368. #include "asterisk/json.h"
  369. #include "asterisk/astobj2.h"
  370. static const size_t SECURITY_EVENT_BUF_INIT_LEN = 256;
  371. /*! \brief Security Topic */
  372. static struct stasis_topic *security_topic;
  373. struct stasis_topic *ast_security_topic(void)
  374. {
  375. return security_topic;
  376. }
  377. static int append_event_str_single(struct ast_str **str, struct ast_json *json,
  378. const enum ast_event_ie_type ie_type)
  379. {
  380. const char *ie_type_key = ast_event_get_ie_type_name(ie_type);
  381. struct ast_json *json_string = ast_json_object_get(json, ie_type_key);
  382. if (!json_string) {
  383. return 0;
  384. }
  385. if (ast_str_append(str, 0, "%s: %s\r\n", ie_type_key, S_OR(ast_json_string_get(json_string), "")) == -1) {
  386. return -1;
  387. }
  388. return 0;
  389. }
  390. static int append_event_str_from_json(struct ast_str **str, struct ast_json *json,
  391. const struct ast_security_event_ie_type *ies)
  392. {
  393. unsigned int i;
  394. if (!ies) {
  395. return 0;
  396. }
  397. for (i = 0; ies[i].ie_type != AST_EVENT_IE_END; i++) {
  398. if (append_event_str_single(str, json, ies[i].ie_type)) {
  399. return -1;
  400. }
  401. }
  402. return 0;
  403. }
  404. static struct ast_manager_event_blob *security_event_to_ami_blob(struct ast_json *json)
  405. {
  406. RAII_VAR(struct ast_str *, str, NULL, ast_free);
  407. struct ast_json *event_type_json;
  408. enum ast_security_event_type event_type;
  409. event_type_json = ast_json_object_get(json, "SecurityEvent");
  410. event_type = ast_json_integer_get(event_type_json);
  411. ast_assert((unsigned int)event_type < AST_SECURITY_EVENT_NUM_TYPES);
  412. if (!(str = ast_str_create(SECURITY_EVENT_BUF_INIT_LEN))) {
  413. return NULL;
  414. }
  415. if (append_event_str_from_json(&str, json,
  416. ast_security_event_get_required_ies(event_type))) {
  417. ast_log(AST_LOG_ERROR, "Failed to issue a security event to AMI: "
  418. "error occurred when adding required event fields.\n");
  419. return NULL;
  420. }
  421. if (append_event_str_from_json(&str, json,
  422. ast_security_event_get_optional_ies(event_type))) {
  423. ast_log(AST_LOG_ERROR, "Failed to issue a security event to AMI: "
  424. "error occurred when adding optional event fields.\n");
  425. return NULL;
  426. }
  427. return ast_manager_event_blob_create(EVENT_FLAG_SECURITY,
  428. ast_security_event_get_name(event_type),
  429. "%s",
  430. ast_str_buffer(str));
  431. }
  432. static struct ast_manager_event_blob *security_event_to_ami(struct stasis_message *message)
  433. {
  434. struct ast_json_payload *payload = stasis_message_data(message);
  435. if (stasis_message_type(message) != ast_security_event_type()) {
  436. return NULL;
  437. }
  438. if (!payload) {
  439. return NULL;
  440. }
  441. return security_event_to_ami_blob(payload->json);
  442. }
  443. /*! \brief Message type for security events */
  444. STASIS_MESSAGE_TYPE_DEFN(ast_security_event_type,
  445. .to_ami = security_event_to_ami,
  446. );
  447. static void security_stasis_cleanup(void)
  448. {
  449. ao2_cleanup(security_topic);
  450. security_topic = NULL;
  451. STASIS_MESSAGE_TYPE_CLEANUP(ast_security_event_type);
  452. }
  453. int ast_security_stasis_init(void)
  454. {
  455. ast_register_cleanup(security_stasis_cleanup);
  456. security_topic = stasis_topic_create("ast_security");
  457. if (!security_topic) {
  458. return -1;
  459. }
  460. if (STASIS_MESSAGE_TYPE_INIT(ast_security_event_type)) {
  461. return -1;
  462. }
  463. return 0;
  464. }
  465. static const struct {
  466. const char *name;
  467. uint32_t version;
  468. enum ast_security_event_severity severity;
  469. #define MAX_SECURITY_IES 12
  470. struct ast_security_event_ie_type required_ies[MAX_SECURITY_IES];
  471. struct ast_security_event_ie_type optional_ies[MAX_SECURITY_IES];
  472. #undef MAX_SECURITY_IES
  473. } sec_events[AST_SECURITY_EVENT_NUM_TYPES] = {
  474. #define SEC_EVT_FIELD(e, field) (offsetof(struct ast_security_event_##e, field))
  475. [AST_SECURITY_EVENT_FAILED_ACL] = {
  476. .name = "FailedACL",
  477. .version = AST_SECURITY_EVENT_FAILED_ACL_VERSION,
  478. .severity = AST_SECURITY_EVENT_SEVERITY_ERROR,
  479. .required_ies = {
  480. { AST_EVENT_IE_EVENT_TV, 0 },
  481. { AST_EVENT_IE_SEVERITY, 0 },
  482. { AST_EVENT_IE_SERVICE, SEC_EVT_FIELD(common, service) },
  483. { AST_EVENT_IE_EVENT_VERSION, SEC_EVT_FIELD(common, version) },
  484. { AST_EVENT_IE_ACCOUNT_ID, SEC_EVT_FIELD(common, account_id) },
  485. { AST_EVENT_IE_SESSION_ID, SEC_EVT_FIELD(common, session_id) },
  486. { AST_EVENT_IE_LOCAL_ADDR, SEC_EVT_FIELD(common, local_addr) },
  487. { AST_EVENT_IE_REMOTE_ADDR, SEC_EVT_FIELD(common, remote_addr) },
  488. { AST_EVENT_IE_END, 0 }
  489. },
  490. .optional_ies = {
  491. { AST_EVENT_IE_MODULE, SEC_EVT_FIELD(common, module) },
  492. { AST_EVENT_IE_ACL_NAME, SEC_EVT_FIELD(failed_acl, acl_name) },
  493. { AST_EVENT_IE_SESSION_TV, SEC_EVT_FIELD(common, session_tv) },
  494. { AST_EVENT_IE_END, 0 }
  495. },
  496. },
  497. [AST_SECURITY_EVENT_INVAL_ACCT_ID] = {
  498. .name = "InvalidAccountID",
  499. .version = AST_SECURITY_EVENT_INVAL_ACCT_ID_VERSION,
  500. .severity = AST_SECURITY_EVENT_SEVERITY_ERROR,
  501. .required_ies = {
  502. { AST_EVENT_IE_EVENT_TV, 0 },
  503. { AST_EVENT_IE_SEVERITY, 0 },
  504. { AST_EVENT_IE_SERVICE, SEC_EVT_FIELD(common, service) },
  505. { AST_EVENT_IE_EVENT_VERSION, SEC_EVT_FIELD(common, version) },
  506. { AST_EVENT_IE_ACCOUNT_ID, SEC_EVT_FIELD(common, account_id) },
  507. { AST_EVENT_IE_SESSION_ID, SEC_EVT_FIELD(common, session_id) },
  508. { AST_EVENT_IE_LOCAL_ADDR, SEC_EVT_FIELD(common, local_addr) },
  509. { AST_EVENT_IE_REMOTE_ADDR, SEC_EVT_FIELD(common, remote_addr) },
  510. { AST_EVENT_IE_END, 0 }
  511. },
  512. .optional_ies = {
  513. { AST_EVENT_IE_MODULE, SEC_EVT_FIELD(common, module) },
  514. { AST_EVENT_IE_SESSION_TV, SEC_EVT_FIELD(common, session_tv) },
  515. { AST_EVENT_IE_END, 0 }
  516. },
  517. },
  518. [AST_SECURITY_EVENT_SESSION_LIMIT] = {
  519. .name = "SessionLimit",
  520. .version = AST_SECURITY_EVENT_SESSION_LIMIT_VERSION,
  521. .severity = AST_SECURITY_EVENT_SEVERITY_ERROR,
  522. .required_ies = {
  523. { AST_EVENT_IE_EVENT_TV, 0 },
  524. { AST_EVENT_IE_SEVERITY, 0 },
  525. { AST_EVENT_IE_SERVICE, SEC_EVT_FIELD(common, service) },
  526. { AST_EVENT_IE_EVENT_VERSION, SEC_EVT_FIELD(common, version) },
  527. { AST_EVENT_IE_ACCOUNT_ID, SEC_EVT_FIELD(common, account_id) },
  528. { AST_EVENT_IE_SESSION_ID, SEC_EVT_FIELD(common, session_id) },
  529. { AST_EVENT_IE_LOCAL_ADDR, SEC_EVT_FIELD(common, local_addr) },
  530. { AST_EVENT_IE_REMOTE_ADDR, SEC_EVT_FIELD(common, remote_addr) },
  531. { AST_EVENT_IE_END, 0 }
  532. },
  533. .optional_ies = {
  534. { AST_EVENT_IE_MODULE, SEC_EVT_FIELD(common, module) },
  535. { AST_EVENT_IE_SESSION_TV, SEC_EVT_FIELD(common, session_tv) },
  536. { AST_EVENT_IE_END, 0 }
  537. },
  538. },
  539. [AST_SECURITY_EVENT_MEM_LIMIT] = {
  540. .name = "MemoryLimit",
  541. .version = AST_SECURITY_EVENT_MEM_LIMIT_VERSION,
  542. .severity = AST_SECURITY_EVENT_SEVERITY_ERROR,
  543. .required_ies = {
  544. { AST_EVENT_IE_EVENT_TV, 0 },
  545. { AST_EVENT_IE_SEVERITY, 0 },
  546. { AST_EVENT_IE_SERVICE, SEC_EVT_FIELD(common, service) },
  547. { AST_EVENT_IE_EVENT_VERSION, SEC_EVT_FIELD(common, version) },
  548. { AST_EVENT_IE_ACCOUNT_ID, SEC_EVT_FIELD(common, account_id) },
  549. { AST_EVENT_IE_SESSION_ID, SEC_EVT_FIELD(common, session_id) },
  550. { AST_EVENT_IE_LOCAL_ADDR, SEC_EVT_FIELD(common, local_addr) },
  551. { AST_EVENT_IE_REMOTE_ADDR, SEC_EVT_FIELD(common, remote_addr) },
  552. { AST_EVENT_IE_END, 0 }
  553. },
  554. .optional_ies = {
  555. { AST_EVENT_IE_MODULE, SEC_EVT_FIELD(common, module) },
  556. { AST_EVENT_IE_SESSION_TV, SEC_EVT_FIELD(common, session_tv) },
  557. { AST_EVENT_IE_END, 0 }
  558. },
  559. },
  560. [AST_SECURITY_EVENT_LOAD_AVG] = {
  561. .name = "LoadAverageLimit",
  562. .version = AST_SECURITY_EVENT_LOAD_AVG_VERSION,
  563. .severity = AST_SECURITY_EVENT_SEVERITY_ERROR,
  564. .required_ies = {
  565. { AST_EVENT_IE_EVENT_TV, 0 },
  566. { AST_EVENT_IE_SEVERITY, 0 },
  567. { AST_EVENT_IE_SERVICE, SEC_EVT_FIELD(common, service) },
  568. { AST_EVENT_IE_EVENT_VERSION, SEC_EVT_FIELD(common, version) },
  569. { AST_EVENT_IE_ACCOUNT_ID, SEC_EVT_FIELD(common, account_id) },
  570. { AST_EVENT_IE_SESSION_ID, SEC_EVT_FIELD(common, session_id) },
  571. { AST_EVENT_IE_LOCAL_ADDR, SEC_EVT_FIELD(common, local_addr) },
  572. { AST_EVENT_IE_REMOTE_ADDR, SEC_EVT_FIELD(common, remote_addr) },
  573. { AST_EVENT_IE_END, 0 }
  574. },
  575. .optional_ies = {
  576. { AST_EVENT_IE_MODULE, SEC_EVT_FIELD(common, module) },
  577. { AST_EVENT_IE_SESSION_TV, SEC_EVT_FIELD(common, session_tv) },
  578. { AST_EVENT_IE_END, 0 }
  579. },
  580. },
  581. [AST_SECURITY_EVENT_REQ_NO_SUPPORT] = {
  582. .name = "RequestNotSupported",
  583. .version = AST_SECURITY_EVENT_REQ_NO_SUPPORT_VERSION,
  584. .severity = AST_SECURITY_EVENT_SEVERITY_ERROR,
  585. .required_ies = {
  586. { AST_EVENT_IE_EVENT_TV, 0 },
  587. { AST_EVENT_IE_SEVERITY, 0 },
  588. { AST_EVENT_IE_SERVICE, SEC_EVT_FIELD(common, service) },
  589. { AST_EVENT_IE_EVENT_VERSION, SEC_EVT_FIELD(common, version) },
  590. { AST_EVENT_IE_ACCOUNT_ID, SEC_EVT_FIELD(common, account_id) },
  591. { AST_EVENT_IE_SESSION_ID, SEC_EVT_FIELD(common, session_id) },
  592. { AST_EVENT_IE_LOCAL_ADDR, SEC_EVT_FIELD(common, local_addr) },
  593. { AST_EVENT_IE_REMOTE_ADDR, SEC_EVT_FIELD(common, remote_addr) },
  594. { AST_EVENT_IE_REQUEST_TYPE, SEC_EVT_FIELD(req_no_support, request_type) },
  595. { AST_EVENT_IE_END, 0 }
  596. },
  597. .optional_ies = {
  598. { AST_EVENT_IE_MODULE, SEC_EVT_FIELD(common, module) },
  599. { AST_EVENT_IE_SESSION_TV, SEC_EVT_FIELD(common, session_tv) },
  600. { AST_EVENT_IE_END, 0 }
  601. },
  602. },
  603. [AST_SECURITY_EVENT_REQ_NOT_ALLOWED] = {
  604. .name = "RequestNotAllowed",
  605. .version = AST_SECURITY_EVENT_REQ_NOT_ALLOWED_VERSION,
  606. .severity = AST_SECURITY_EVENT_SEVERITY_ERROR,
  607. .required_ies = {
  608. { AST_EVENT_IE_EVENT_TV, 0 },
  609. { AST_EVENT_IE_SEVERITY, 0 },
  610. { AST_EVENT_IE_SERVICE, SEC_EVT_FIELD(common, service) },
  611. { AST_EVENT_IE_EVENT_VERSION, SEC_EVT_FIELD(common, version) },
  612. { AST_EVENT_IE_ACCOUNT_ID, SEC_EVT_FIELD(common, account_id) },
  613. { AST_EVENT_IE_SESSION_ID, SEC_EVT_FIELD(common, session_id) },
  614. { AST_EVENT_IE_LOCAL_ADDR, SEC_EVT_FIELD(common, local_addr) },
  615. { AST_EVENT_IE_REMOTE_ADDR, SEC_EVT_FIELD(common, remote_addr) },
  616. { AST_EVENT_IE_REQUEST_TYPE, SEC_EVT_FIELD(req_not_allowed, request_type) },
  617. { AST_EVENT_IE_END, 0 }
  618. },
  619. .optional_ies = {
  620. { AST_EVENT_IE_MODULE, SEC_EVT_FIELD(common, module) },
  621. { AST_EVENT_IE_SESSION_TV, SEC_EVT_FIELD(common, session_tv) },
  622. { AST_EVENT_IE_REQUEST_PARAMS, SEC_EVT_FIELD(req_not_allowed, request_params) },
  623. { AST_EVENT_IE_END, 0 }
  624. },
  625. },
  626. [AST_SECURITY_EVENT_AUTH_METHOD_NOT_ALLOWED] = {
  627. .name = "AuthMethodNotAllowed",
  628. .version = AST_SECURITY_EVENT_AUTH_METHOD_NOT_ALLOWED_VERSION,
  629. .severity = AST_SECURITY_EVENT_SEVERITY_ERROR,
  630. .required_ies = {
  631. { AST_EVENT_IE_EVENT_TV, 0 },
  632. { AST_EVENT_IE_SEVERITY, 0 },
  633. { AST_EVENT_IE_SERVICE, SEC_EVT_FIELD(common, service) },
  634. { AST_EVENT_IE_EVENT_VERSION, SEC_EVT_FIELD(common, version) },
  635. { AST_EVENT_IE_ACCOUNT_ID, SEC_EVT_FIELD(common, account_id) },
  636. { AST_EVENT_IE_SESSION_ID, SEC_EVT_FIELD(common, session_id) },
  637. { AST_EVENT_IE_LOCAL_ADDR, SEC_EVT_FIELD(common, local_addr) },
  638. { AST_EVENT_IE_REMOTE_ADDR, SEC_EVT_FIELD(common, remote_addr) },
  639. { AST_EVENT_IE_AUTH_METHOD, SEC_EVT_FIELD(auth_method_not_allowed, auth_method) },
  640. { AST_EVENT_IE_END, 0 }
  641. },
  642. .optional_ies = {
  643. { AST_EVENT_IE_MODULE, SEC_EVT_FIELD(common, module) },
  644. { AST_EVENT_IE_SESSION_TV, SEC_EVT_FIELD(common, session_tv) },
  645. { AST_EVENT_IE_END, 0 }
  646. },
  647. },
  648. [AST_SECURITY_EVENT_REQ_BAD_FORMAT] = {
  649. .name = "RequestBadFormat",
  650. .version = AST_SECURITY_EVENT_REQ_BAD_FORMAT_VERSION,
  651. .severity = AST_SECURITY_EVENT_SEVERITY_ERROR,
  652. .required_ies = {
  653. { AST_EVENT_IE_EVENT_TV, 0 },
  654. { AST_EVENT_IE_SEVERITY, 0 },
  655. { AST_EVENT_IE_SERVICE, SEC_EVT_FIELD(common, service) },
  656. { AST_EVENT_IE_EVENT_VERSION, SEC_EVT_FIELD(common, version) },
  657. { AST_EVENT_IE_SESSION_ID, SEC_EVT_FIELD(common, session_id) },
  658. { AST_EVENT_IE_LOCAL_ADDR, SEC_EVT_FIELD(common, local_addr) },
  659. { AST_EVENT_IE_REMOTE_ADDR, SEC_EVT_FIELD(common, remote_addr) },
  660. { AST_EVENT_IE_REQUEST_TYPE, SEC_EVT_FIELD(req_bad_format, request_type) },
  661. { AST_EVENT_IE_END, 0 }
  662. },
  663. .optional_ies = {
  664. { AST_EVENT_IE_MODULE, SEC_EVT_FIELD(common, module) },
  665. { AST_EVENT_IE_SESSION_TV, SEC_EVT_FIELD(common, session_tv) },
  666. { AST_EVENT_IE_ACCOUNT_ID, SEC_EVT_FIELD(common, account_id) },
  667. { AST_EVENT_IE_REQUEST_PARAMS, SEC_EVT_FIELD(req_bad_format, request_params) },
  668. { AST_EVENT_IE_END, 0 }
  669. },
  670. },
  671. [AST_SECURITY_EVENT_SUCCESSFUL_AUTH] = {
  672. .name = "SuccessfulAuth",
  673. .version = AST_SECURITY_EVENT_SUCCESSFUL_AUTH_VERSION,
  674. .severity = AST_SECURITY_EVENT_SEVERITY_INFO,
  675. .required_ies = {
  676. { AST_EVENT_IE_EVENT_TV, 0 },
  677. { AST_EVENT_IE_SEVERITY, 0 },
  678. { AST_EVENT_IE_SERVICE, SEC_EVT_FIELD(common, service) },
  679. { AST_EVENT_IE_EVENT_VERSION, SEC_EVT_FIELD(common, version) },
  680. { AST_EVENT_IE_ACCOUNT_ID, SEC_EVT_FIELD(common, account_id) },
  681. { AST_EVENT_IE_SESSION_ID, SEC_EVT_FIELD(common, session_id) },
  682. { AST_EVENT_IE_LOCAL_ADDR, SEC_EVT_FIELD(common, local_addr) },
  683. { AST_EVENT_IE_REMOTE_ADDR, SEC_EVT_FIELD(common, remote_addr) },
  684. { AST_EVENT_IE_USING_PASSWORD, SEC_EVT_FIELD(successful_auth, using_password) },
  685. { AST_EVENT_IE_END, 0 }
  686. },
  687. .optional_ies = {
  688. { AST_EVENT_IE_MODULE, SEC_EVT_FIELD(common, module) },
  689. { AST_EVENT_IE_SESSION_TV, SEC_EVT_FIELD(common, session_tv) },
  690. { AST_EVENT_IE_END, 0 }
  691. },
  692. },
  693. [AST_SECURITY_EVENT_UNEXPECTED_ADDR] = {
  694. .name = "UnexpectedAddress",
  695. .version = AST_SECURITY_EVENT_UNEXPECTED_ADDR_VERSION,
  696. .severity = AST_SECURITY_EVENT_SEVERITY_ERROR,
  697. .required_ies = {
  698. { AST_EVENT_IE_EVENT_TV, 0 },
  699. { AST_EVENT_IE_SEVERITY, 0 },
  700. { AST_EVENT_IE_SERVICE, SEC_EVT_FIELD(common, service) },
  701. { AST_EVENT_IE_EVENT_VERSION, SEC_EVT_FIELD(common, version) },
  702. { AST_EVENT_IE_ACCOUNT_ID, SEC_EVT_FIELD(common, account_id) },
  703. { AST_EVENT_IE_SESSION_ID, SEC_EVT_FIELD(common, session_id) },
  704. { AST_EVENT_IE_LOCAL_ADDR, SEC_EVT_FIELD(common, local_addr) },
  705. { AST_EVENT_IE_REMOTE_ADDR, SEC_EVT_FIELD(common, remote_addr) },
  706. { AST_EVENT_IE_EXPECTED_ADDR, SEC_EVT_FIELD(unexpected_addr, expected_addr) },
  707. { AST_EVENT_IE_END, 0 }
  708. },
  709. .optional_ies = {
  710. { AST_EVENT_IE_MODULE, SEC_EVT_FIELD(common, module) },
  711. { AST_EVENT_IE_SESSION_TV, SEC_EVT_FIELD(common, session_tv) },
  712. { AST_EVENT_IE_END, 0 }
  713. },
  714. },
  715. [AST_SECURITY_EVENT_CHAL_RESP_FAILED] = {
  716. .name = "ChallengeResponseFailed",
  717. .version = AST_SECURITY_EVENT_CHAL_RESP_FAILED_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_CHALLENGE, SEC_EVT_FIELD(chal_resp_failed, challenge) },
  729. { AST_EVENT_IE_RESPONSE, SEC_EVT_FIELD(chal_resp_failed, response) },
  730. { AST_EVENT_IE_EXPECTED_RESPONSE, SEC_EVT_FIELD(chal_resp_failed, expected_response) },
  731. { AST_EVENT_IE_END, 0 }
  732. },
  733. .optional_ies = {
  734. { AST_EVENT_IE_MODULE, SEC_EVT_FIELD(common, module) },
  735. { AST_EVENT_IE_SESSION_TV, SEC_EVT_FIELD(common, session_tv) },
  736. { AST_EVENT_IE_END, 0 }
  737. },
  738. },
  739. [AST_SECURITY_EVENT_INVAL_PASSWORD] = {
  740. .name = "InvalidPassword",
  741. .version = AST_SECURITY_EVENT_INVAL_PASSWORD_VERSION,
  742. .severity = AST_SECURITY_EVENT_SEVERITY_ERROR,
  743. .required_ies = {
  744. { AST_EVENT_IE_EVENT_TV, 0 },
  745. { AST_EVENT_IE_SEVERITY, 0 },
  746. { AST_EVENT_IE_SERVICE, SEC_EVT_FIELD(common, service) },
  747. { AST_EVENT_IE_EVENT_VERSION, SEC_EVT_FIELD(common, version) },
  748. { AST_EVENT_IE_ACCOUNT_ID, SEC_EVT_FIELD(common, account_id) },
  749. { AST_EVENT_IE_SESSION_ID, SEC_EVT_FIELD(common, session_id) },
  750. { AST_EVENT_IE_LOCAL_ADDR, SEC_EVT_FIELD(common, local_addr) },
  751. { AST_EVENT_IE_REMOTE_ADDR, SEC_EVT_FIELD(common, remote_addr) },
  752. { AST_EVENT_IE_END, 0 }
  753. },
  754. .optional_ies = {
  755. { AST_EVENT_IE_MODULE, SEC_EVT_FIELD(common, module) },
  756. { AST_EVENT_IE_SESSION_TV, SEC_EVT_FIELD(common, session_tv) },
  757. { AST_EVENT_IE_CHALLENGE, SEC_EVT_FIELD(inval_password, challenge) },
  758. { AST_EVENT_IE_RECEIVED_CHALLENGE, SEC_EVT_FIELD(inval_password, received_challenge) },
  759. { AST_EVENT_IE_RECEIVED_HASH, SEC_EVT_FIELD(inval_password, received_hash) },
  760. { AST_EVENT_IE_END, 0 }
  761. },
  762. },
  763. [AST_SECURITY_EVENT_CHAL_SENT] = {
  764. .name = "ChallengeSent",
  765. .version = AST_SECURITY_EVENT_CHAL_SENT_VERSION,
  766. .severity = AST_SECURITY_EVENT_SEVERITY_INFO,
  767. .required_ies = {
  768. { AST_EVENT_IE_EVENT_TV, 0 },
  769. { AST_EVENT_IE_SEVERITY, 0 },
  770. { AST_EVENT_IE_SERVICE, SEC_EVT_FIELD(common, service) },
  771. { AST_EVENT_IE_EVENT_VERSION, SEC_EVT_FIELD(common, version) },
  772. { AST_EVENT_IE_ACCOUNT_ID, SEC_EVT_FIELD(common, account_id) },
  773. { AST_EVENT_IE_SESSION_ID, SEC_EVT_FIELD(common, session_id) },
  774. { AST_EVENT_IE_LOCAL_ADDR, SEC_EVT_FIELD(common, local_addr) },
  775. { AST_EVENT_IE_REMOTE_ADDR, SEC_EVT_FIELD(common, remote_addr) },
  776. { AST_EVENT_IE_CHALLENGE, SEC_EVT_FIELD(chal_sent, challenge) },
  777. { AST_EVENT_IE_END, 0 }
  778. },
  779. .optional_ies = {
  780. { AST_EVENT_IE_MODULE, SEC_EVT_FIELD(common, module) },
  781. { AST_EVENT_IE_SESSION_TV, SEC_EVT_FIELD(common, session_tv) },
  782. { AST_EVENT_IE_END, 0 }
  783. },
  784. },
  785. [AST_SECURITY_EVENT_INVAL_TRANSPORT] = {
  786. .name = "InvalidTransport",
  787. .version = AST_SECURITY_EVENT_INVAL_TRANSPORT_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_ATTEMPTED_TRANSPORT, SEC_EVT_FIELD(inval_transport, transport) },
  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. #undef SEC_EVT_FIELD
  808. };
  809. static const struct {
  810. enum ast_security_event_severity severity;
  811. const char *str;
  812. } severities[] = {
  813. { AST_SECURITY_EVENT_SEVERITY_INFO, "Informational" },
  814. { AST_SECURITY_EVENT_SEVERITY_ERROR, "Error" },
  815. };
  816. const char *ast_security_event_severity_get_name(
  817. const enum ast_security_event_severity severity)
  818. {
  819. unsigned int i;
  820. for (i = 0; i < ARRAY_LEN(severities); i++) {
  821. if (severities[i].severity == severity) {
  822. return severities[i].str;
  823. }
  824. }
  825. return NULL;
  826. }
  827. static int check_event_type(const enum ast_security_event_type event_type)
  828. {
  829. if ((unsigned int)event_type >= AST_SECURITY_EVENT_NUM_TYPES) {
  830. ast_log(LOG_ERROR, "Invalid security event type %u\n", event_type);
  831. return -1;
  832. }
  833. return 0;
  834. }
  835. const char *ast_security_event_get_name(const enum ast_security_event_type event_type)
  836. {
  837. if (check_event_type(event_type)) {
  838. return NULL;
  839. }
  840. return sec_events[event_type].name;
  841. }
  842. const struct ast_security_event_ie_type *ast_security_event_get_required_ies(
  843. const enum ast_security_event_type event_type)
  844. {
  845. if (check_event_type(event_type)) {
  846. return NULL;
  847. }
  848. return sec_events[event_type].required_ies;
  849. }
  850. const struct ast_security_event_ie_type *ast_security_event_get_optional_ies(
  851. const enum ast_security_event_type event_type)
  852. {
  853. if (check_event_type(event_type)) {
  854. return NULL;
  855. }
  856. return sec_events[event_type].optional_ies;
  857. }
  858. static int add_ip_json_object(struct ast_json *json, enum ast_event_ie_type ie_type,
  859. const struct ast_security_event_ip_addr *addr)
  860. {
  861. struct ast_json *json_ip;
  862. json_ip = ast_json_ipaddr(addr->addr, addr->transport);
  863. if (!json_ip) {
  864. return -1;
  865. }
  866. return ast_json_object_set(json, ast_event_get_ie_type_name(ie_type), json_ip);
  867. }
  868. enum ie_required {
  869. NOT_REQUIRED,
  870. REQUIRED
  871. };
  872. static int add_json_object(struct ast_json *json, const struct ast_security_event_common *sec,
  873. const struct ast_security_event_ie_type *ie_type, enum ie_required req)
  874. {
  875. int res = 0;
  876. switch (ie_type->ie_type) {
  877. case AST_EVENT_IE_SERVICE:
  878. case AST_EVENT_IE_ACCOUNT_ID:
  879. case AST_EVENT_IE_SESSION_ID:
  880. case AST_EVENT_IE_MODULE:
  881. case AST_EVENT_IE_ACL_NAME:
  882. case AST_EVENT_IE_REQUEST_TYPE:
  883. case AST_EVENT_IE_REQUEST_PARAMS:
  884. case AST_EVENT_IE_AUTH_METHOD:
  885. case AST_EVENT_IE_CHALLENGE:
  886. case AST_EVENT_IE_RESPONSE:
  887. case AST_EVENT_IE_EXPECTED_RESPONSE:
  888. case AST_EVENT_IE_RECEIVED_CHALLENGE:
  889. case AST_EVENT_IE_RECEIVED_HASH:
  890. case AST_EVENT_IE_ATTEMPTED_TRANSPORT:
  891. {
  892. const char *str;
  893. struct ast_json *json_string;
  894. str = *((const char **)(((const char *) sec) + ie_type->offset));
  895. if (req && !str) {
  896. ast_log(LOG_WARNING, "Required IE '%d' (%s) for security event "
  897. "type '%u' (%s) not present\n", ie_type->ie_type,
  898. ast_event_get_ie_type_name(ie_type->ie_type),
  899. sec->event_type, ast_security_event_get_name(sec->event_type));
  900. res = -1;
  901. break;
  902. }
  903. if (!str) {
  904. break;
  905. }
  906. json_string = ast_json_string_create(str);
  907. if (!json_string) {
  908. res = -1;
  909. break;
  910. }
  911. res = ast_json_object_set(json, ast_event_get_ie_type_name(ie_type->ie_type), json_string);
  912. break;
  913. }
  914. case AST_EVENT_IE_EVENT_VERSION:
  915. case AST_EVENT_IE_USING_PASSWORD:
  916. {
  917. struct ast_json *json_string;
  918. uint32_t val;
  919. val = *((const uint32_t *)(((const char *) sec) + ie_type->offset));
  920. json_string = ast_json_stringf("%u", val);
  921. if (!json_string) {
  922. res = -1;
  923. break;
  924. }
  925. res = ast_json_object_set(json, ast_event_get_ie_type_name(ie_type->ie_type), json_string);
  926. break;
  927. }
  928. case AST_EVENT_IE_LOCAL_ADDR:
  929. case AST_EVENT_IE_REMOTE_ADDR:
  930. case AST_EVENT_IE_EXPECTED_ADDR:
  931. {
  932. const struct ast_security_event_ip_addr *addr;
  933. addr = (const struct ast_security_event_ip_addr *)(((const char *) sec) + ie_type->offset);
  934. if (req && !addr->addr) {
  935. ast_log(LOG_WARNING, "Required IE '%d' (%s) for security event "
  936. "type '%u' (%s) not present\n", ie_type->ie_type,
  937. ast_event_get_ie_type_name(ie_type->ie_type),
  938. sec->event_type, ast_security_event_get_name(sec->event_type));
  939. res = -1;
  940. }
  941. if (addr->addr) {
  942. res = add_ip_json_object(json, ie_type->ie_type, addr);
  943. }
  944. break;
  945. }
  946. case AST_EVENT_IE_SESSION_TV:
  947. {
  948. const struct timeval *tval;
  949. tval = *((const struct timeval **)(((const char *) sec) + ie_type->offset));
  950. if (req && !tval) {
  951. ast_log(LOG_WARNING, "Required IE '%d' (%s) for security event "
  952. "type '%u' (%s) not present\n", ie_type->ie_type,
  953. ast_event_get_ie_type_name(ie_type->ie_type),
  954. sec->event_type, ast_security_event_get_name(sec->event_type));
  955. res = -1;
  956. }
  957. if (tval) {
  958. struct ast_json *json_tval = ast_json_timeval(*tval, NULL);
  959. if (!json_tval) {
  960. res = -1;
  961. break;
  962. }
  963. res = ast_json_object_set(json, ast_event_get_ie_type_name(ie_type->ie_type), json_tval);
  964. }
  965. break;
  966. }
  967. case AST_EVENT_IE_EVENT_TV:
  968. case AST_EVENT_IE_SEVERITY:
  969. /* Added automatically, nothing to do here. */
  970. break;
  971. default:
  972. ast_log(LOG_WARNING, "Unhandled IE type '%d' (%s), this security event "
  973. "will be missing data.\n", ie_type->ie_type,
  974. ast_event_get_ie_type_name(ie_type->ie_type));
  975. break;
  976. }
  977. return res;
  978. }
  979. static struct ast_json *alloc_security_event_json_object(const struct ast_security_event_common *sec)
  980. {
  981. struct timeval tv = ast_tvnow();
  982. const char *severity_str;
  983. struct ast_json *json_temp;
  984. RAII_VAR(struct ast_json *, json_object, ast_json_object_create(), ast_json_unref);
  985. if (!json_object) {
  986. return NULL;
  987. }
  988. /* NOTE: Every time ast_json_object_set is used, json_temp becomes a stale pointer since the reference is taken.
  989. * This is true even if ast_json_object_set fails.
  990. */
  991. json_temp = ast_json_integer_create(sec->event_type);
  992. if (!json_temp || ast_json_object_set(json_object, "SecurityEvent", json_temp)) {
  993. return NULL;
  994. }
  995. json_temp = ast_json_stringf("%u", sec->version);
  996. if (!json_temp || ast_json_object_set(json_object, ast_event_get_ie_type_name(AST_EVENT_IE_EVENT_VERSION), json_temp)) {
  997. return NULL;
  998. }
  999. /* AST_EVENT_IE_EVENT_TV */
  1000. json_temp = ast_json_timeval(tv, NULL);
  1001. if (!json_temp || ast_json_object_set(json_object, ast_event_get_ie_type_name(AST_EVENT_IE_EVENT_TV), json_temp)) {
  1002. return NULL;
  1003. }
  1004. /* AST_EVENT_IE_SERVICE */
  1005. json_temp = ast_json_string_create(sec->service);
  1006. if (!json_temp || ast_json_object_set(json_object, ast_event_get_ie_type_name(AST_EVENT_IE_SERVICE), json_temp)) {
  1007. return NULL;
  1008. }
  1009. /* AST_EVENT_IE_SEVERITY */
  1010. severity_str = S_OR(
  1011. ast_security_event_severity_get_name(sec_events[sec->event_type].severity),
  1012. "Unknown"
  1013. );
  1014. json_temp = ast_json_string_create(severity_str);
  1015. if (!json_temp || ast_json_object_set(json_object, ast_event_get_ie_type_name(AST_EVENT_IE_SEVERITY), json_temp)) {
  1016. return NULL;
  1017. }
  1018. return ast_json_ref(json_object);
  1019. }
  1020. static int handle_security_event(const struct ast_security_event_common *sec)
  1021. {
  1022. RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
  1023. RAII_VAR(struct ast_json_payload *, json_payload, NULL, ao2_cleanup);
  1024. RAII_VAR(struct ast_json *, json_object, NULL, ast_json_unref);
  1025. const struct ast_security_event_ie_type *ies;
  1026. unsigned int i;
  1027. if (!ast_security_event_type()) {
  1028. return -1;
  1029. }
  1030. json_object = alloc_security_event_json_object(sec);
  1031. if (!json_object) {
  1032. return -1;
  1033. }
  1034. for (ies = ast_security_event_get_required_ies(sec->event_type), i = 0;
  1035. ies[i].ie_type != AST_EVENT_IE_END;
  1036. i++) {
  1037. if (add_json_object(json_object, sec, ies + i, REQUIRED)) {
  1038. goto return_error;
  1039. }
  1040. }
  1041. for (ies = ast_security_event_get_optional_ies(sec->event_type), i = 0;
  1042. ies[i].ie_type != AST_EVENT_IE_END;
  1043. i++) {
  1044. if (add_json_object(json_object, sec, ies + i, NOT_REQUIRED)) {
  1045. goto return_error;
  1046. }
  1047. }
  1048. /* The json blob is ready. Throw it in the payload and send it out over stasis. */
  1049. if (!(json_payload = ast_json_payload_create(json_object))) {
  1050. goto return_error;
  1051. }
  1052. msg = stasis_message_create(ast_security_event_type(), json_payload);
  1053. if (!msg) {
  1054. goto return_error;
  1055. }
  1056. stasis_publish(ast_security_topic(), msg);
  1057. return 0;
  1058. return_error:
  1059. return -1;
  1060. }
  1061. int ast_security_event_report(const struct ast_security_event_common *sec)
  1062. {
  1063. if ((unsigned int)sec->event_type >= AST_SECURITY_EVENT_NUM_TYPES) {
  1064. ast_log(LOG_ERROR, "Invalid security event type\n");
  1065. return -1;
  1066. }
  1067. if (!sec_events[sec->event_type].name) {
  1068. ast_log(LOG_WARNING, "Security event type %u not handled\n",
  1069. sec->event_type);
  1070. return -1;
  1071. }
  1072. if (sec->version != sec_events[sec->event_type].version) {
  1073. ast_log(LOG_WARNING, "Security event %u version mismatch\n",
  1074. sec->event_type);
  1075. return -1;
  1076. }
  1077. if (handle_security_event(sec)) {
  1078. ast_log(LOG_ERROR, "Failed to issue security event of type %s.\n",
  1079. ast_security_event_get_name(sec->event_type));
  1080. }
  1081. return 0;
  1082. }