2
0

zrtp_iface.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. /*
  2. * libZRTP SDK library, implements the ZRTP secure VoIP protocol.
  3. * Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.
  4. * Contact: http://philzimmermann.com
  5. * For licensing and other legal details, see the file zrtp_legal.c.
  6. *
  7. * Viktor Krykun <v.krikun at zfoneproject.com>
  8. */
  9. /**
  10. * \file zrtp_iface.h
  11. * \brief libzrtp product-dependent functions
  12. */
  13. #ifndef __ZRTP_IFACE_H__
  14. #define __ZRTP_IFACE_H__
  15. #include "zrtp_config.h"
  16. #include "zrtp_base.h"
  17. #include "zrtp_string.h"
  18. #include "zrtp_error.h"
  19. #include "zrtp_iface_system.h"
  20. #if defined(__cplusplus)
  21. extern "C"
  22. {
  23. #endif
  24. /*======================================================================*/
  25. /* libzrtp interface: Cache */
  26. /*======================================================================*/
  27. /*!
  28. * \defgroup zrtp_iface_cache ZRTP Cache
  29. * \ingroup zrtp_iface
  30. *
  31. * The secret cache implementation should have a two-layer structure: each pair of ZIDs should have
  32. * a relevant pair of secrets (current and previous). In addition to the value of the secret, the
  33. * cache should contain: verification flag, last usage time-stamp and cache TTL value.
  34. *
  35. * The simplest secret cache scheme implementation is:
  36. * \code
  37. * [local_ZID][remote_ZID][curr_cache][prev_cache][verified][used at][cache ttl]
  38. * \endcode
  39. * \warning
  40. * Libzrtp doen't provide synchronization for cache read/write operation. Cache is not thread safe
  41. * by default. Implementor must take care of synchronization inside his implementation.
  42. *
  43. * For more information see corresponding section \ref XXX. Samples can be found at \ref XXX
  44. * (\c zrtp_iface_builtin.h, \c zrtp_iface_cache.c)
  45. * \{
  46. */
  47. /**
  48. * @brief Data types and functions related to shared secrets.
  49. */
  50. typedef struct zrtp_callback_cache_t
  51. {
  52. /**
  53. * \brief Cache initialization.
  54. *
  55. * libzrtp calls this function before start using cache routine at zrtp_init().
  56. *
  57. * \param zrtp - libzrtp global context;
  58. * \sa zrtp_callback_cache_t#on_down()
  59. */
  60. zrtp_status_t (*on_init)(zrtp_global_t* zrtp);
  61. /**
  62. * \brief Cache deinitialization.
  63. *
  64. * libzrtp calls this function when zrtp cache is no longer needed at zrtp_down().
  65. * \sa zrtp_callback_cache_t#on_init()
  66. */
  67. void (*on_down)();
  68. /**
  69. * \brief Add/Update cache value
  70. *
  71. * Interface function for entering the retained secret to the cache. This function should
  72. * guarantee permanent storage in the cache. The implementation algorithm is the following:
  73. * - if the entry associated with a given pair of ZIDs does not exist, the value should be
  74. * stored in cache.
  75. * - if the entry already exists, the current secret value becomes stored as the previous one.
  76. * The new value becomes stored as the current one. Besides rss->value a timestamp
  77. * (rss->lastused_at) and cache TTL(rss->ttl) should be updated.
  78. *
  79. * \param one_zid - ZID of one side;
  80. * \param another_zid - ZID of the other side;
  81. * \param rss - a structure storing the value of the secret that needs to be saved.
  82. * \return
  83. * - zrtp_status_ok if operation is successful;
  84. * - some error code from \ref zrtp_status_t in case of error.
  85. * \sa zrtp_callback_cache_t#on_get
  86. */
  87. zrtp_status_t (*on_put)( const zrtp_stringn_t* one_zid,
  88. const zrtp_stringn_t* another_zid,
  89. zrtp_shared_secret_t *rss);
  90. /**
  91. * \brief Return secret cache associated with specified pair of ZIDs.
  92. *
  93. * This function should return the secret associated with the specified pair of ZIDs. In
  94. * addition to the secret value, TTL (rss->ttl) and cache timestamp (rss->lastused_at) value
  95. * should be also returned.
  96. *
  97. * \param one_zid - one side's ZID;
  98. * \param another_zid - the other side's ZID;
  99. * \param prev_requested - if this parameter value is 1, the function should return the previous
  100. * secret's value. If this parameter value is 0, the function should return the current
  101. * secret's value;
  102. * \param rss - structure that needs to be filled in.
  103. * \return
  104. * - zrtp_status_ok - if operation is successful;
  105. * - zrtp_status_fail - if the secret cannot be found;
  106. * - some error code from zrtp_status_t if an error occurred.
  107. * \sa zrtp_callback_cache_t#on_put
  108. */
  109. zrtp_status_t (*on_get)( const zrtp_stringn_t* one_zid,
  110. const zrtp_stringn_t* another_zid,
  111. zrtp_shared_secret_t *rss,
  112. int prev_requested);
  113. /**
  114. * \brief Set/clear cache verification flag
  115. *
  116. * This function should set the secret verification flag associated with a pair of ZIDs.
  117. * \warning
  118. * For internal use only. To change the verification flag from the user space use the
  119. * zrtp_verified_set() function.
  120. *
  121. * \param one_zid - first ZID for cache identification;
  122. * \param another_zid - second ZID for cache identification;
  123. * \param verified - verification flag (value can be 0 or 1).
  124. * \return
  125. * - zrtp_status_ok if flag is successfully modified;
  126. * - zrtp_status_fail if the secret cannot be found;
  127. * - some other error code from \ref zrtp_status_t if another error occurred.
  128. */
  129. zrtp_status_t (*on_set_verified)( const zrtp_stringn_t* one_zid,
  130. const zrtp_stringn_t* another_zid,
  131. uint32_t verified);
  132. /**
  133. * \brief Return cache verification flag
  134. *
  135. * This function return the secret verification flag associated with a pair of ZIDs.
  136. *
  137. * \param one_zid - first ZID for cache identification;
  138. * \param another_zid - second ZID for cache identification;
  139. * \param verified - verification flag to be filled in
  140. * \return
  141. * - zrtp_status_ok if flag is successfully returned;
  142. * - zrtp_status_fail if the secret cannot be found;
  143. * - some other error code from \ref zrtp_status_t if another error occurred.
  144. */
  145. zrtp_status_t (*on_get_verified)( const zrtp_stringn_t* one_zid,
  146. const zrtp_stringn_t* another_zid,
  147. uint32_t* verified);
  148. /**
  149. * \brief Should set Secure Since cache aparemeter to current date and time
  150. *
  151. * This function is optional and may be ommited.
  152. *
  153. * \param one_zid - first ZID for cache identification;
  154. * \param another_zid - second ZID for cache identification;
  155. * \return
  156. * - zrtp_status_ok if the oprtation finished sucessfully.
  157. * - some other error code from \ref zrtp_status_t if another error occurred.
  158. */
  159. zrtp_status_t (*on_reset_since)( const zrtp_stringn_t* one_zid,
  160. const zrtp_stringn_t* another_zid);
  161. /**
  162. * \brief Add/Update cache value for MiTM endpoint
  163. *
  164. * This function is analogy to zrtp_callback_cache_t#on_put but for MiTM endpoint.
  165. * \todo Add more detail description
  166. * \sa zrtp_callback_cache_t#on_put zrtp_callback_cache_t#on_get_mitm
  167. */
  168. zrtp_status_t (*on_put_mitm)( const zrtp_stringn_t* one_zid,
  169. const zrtp_stringn_t* another_zid,
  170. zrtp_shared_secret_t *rss);
  171. /**
  172. * \brief Return secret cache for MiTM endpoint
  173. *
  174. * This function is analogy to zrtp_callback_cache_t#on_get but for MiTM endpoint.
  175. * \todo Add more detail description
  176. * \sa zrtp_callback_cache_t#on_get zrtp_callback_cache_t#on_put_mitm
  177. */
  178. zrtp_status_t (*on_get_mitm)( const zrtp_stringn_t* one_zid,
  179. const zrtp_stringn_t* another_zid,
  180. zrtp_shared_secret_t *rss);
  181. /**
  182. * \brief Return Preshared calls counter
  183. *
  184. * This function should return the preshared calls counter associated with a pair of ZIDs.
  185. *
  186. * \param one_zid - first ZID for cache identification;
  187. * \param another_zid - second ZID for cache identification;
  188. * \param counter - preshared calls counter to be filled in
  189. * \return
  190. * - zrtp_status_ok if counter is successfully returned;
  191. * - zrtp_status_fail if the secret cannot be found;
  192. * - some other error code from \ref zrtp_status_t if another error occurred.
  193. */
  194. zrtp_status_t (*on_presh_counter_get)( const zrtp_stringn_t* one_zid,
  195. const zrtp_stringn_t* another_zid,
  196. uint32_t* counter);
  197. /**
  198. * \brief Increase/reset Preshared streams counter made between two endpoints (ZIDs)
  199. *
  200. * This function should set the preshared calls counter associated with a pair of ZIDs.
  201. * Function is optional and should be implemented if your prodict uses Preshared keys exchange.
  202. *
  203. * \param one_zid - first ZID for;
  204. * \param another_zid - second ZID;
  205. * \param counter - Preshared calls counter.
  206. * \return
  207. * - zrtp_status_ok if the counter is successfully modified;
  208. * - zrtp_status_fail if the secret cannot be found;
  209. * - some other error code from \ref zrtp_status_t if another error occurred.
  210. */
  211. zrtp_status_t (*on_presh_counter_set)( const zrtp_stringn_t* one_zid,
  212. const zrtp_stringn_t* another_zid,
  213. uint32_t counter);
  214. } zrtp_callback_cache_t;
  215. /** \} */
  216. /*======================================================================*/
  217. /* libzrtp interface: Scheduler */
  218. /*======================================================================*/
  219. /**
  220. * \defgroup zrtp_iface_scheduler ZRTP Delay Calls
  221. * \ingroup zrtp_iface
  222. *
  223. * Algorithm used in the scheduled call module is described in detail in section \ref XXX of the
  224. * developer's guide documentation. Technical details of this function's implementation follows.
  225. *
  226. * For more information see corresponding section \ref XXX. Samples can be found at \ref XXX
  227. * (\c zrtp_iface_builtin.h, \c zrtp_iface_scheduler.c)
  228. * \{
  229. */
  230. /** \brief ZRTP Delays Calls signature. */
  231. typedef void (*zrtp_call_callback_t)(zrtp_stream_t*, zrtp_retry_task_t*);
  232. /**
  233. * @brief Delay Call wrapper
  234. */
  235. struct zrtp_retry_task_t
  236. {
  237. /** \brief Task action callback */
  238. zrtp_call_callback_t callback;
  239. /** \brief Timeout before call in milliseconds */
  240. zrtp_time_t timeout;
  241. /**
  242. * \brief User data pointer.
  243. *
  244. * Pointer to the user data. This pointer can be used for fast access to some additional data
  245. * attached to this task by the user application.
  246. */
  247. void* usr_data;
  248. // TODO: hide these elements
  249. /**
  250. * \brief Task activity flag.
  251. *
  252. * Libzrtp unsets this flag on task canceling. It prevents the scheduler engine from re-adding
  253. * an already canceled task. Callback handlers skip passive tasks.
  254. * \note
  255. * For internal use only. Don't' modify this field in implementation.
  256. */
  257. uint8_t _is_enabled;
  258. /**
  259. * \brief Number of task retries.
  260. *
  261. * Every handler that attempts the task increases it by one. When the limit is reached the
  262. * scheduler should stop retries and performs a specified action - generally raises an error.
  263. * \note
  264. * For internal use only. Don't' modify this field in implementation.
  265. */
  266. uint32_t _retrys;
  267. /**
  268. * \brief Task Busy flag.
  269. *
  270. * Built-in cache implementation uses this flag to protect task from being removed during the
  271. * callback.
  272. *
  273. * Default cache implementation "locks" this flag before call zrtp_retry_task#callback
  274. * and "unlocks" when the call is performed. zrtp_callback_scheduler_t#on_wait_call_later exits
  275. * when there are no callbacks in progress - no tasks with \c _is_busy enabled.
  276. */
  277. uint8_t _is_busy;
  278. };
  279. /**
  280. * @brief Delay Calls callbacks
  281. */
  282. typedef struct zrtp_callback_scheduler_t
  283. {
  284. /**
  285. * \brief Delay Calls initialization.
  286. *
  287. * libzrtp calls this function before start using scheduler routine at zrtp_init().
  288. *
  289. * \param zrtp - libzrtp global context;
  290. * \sa zrtp_callback_scheduler_t#on_down()
  291. */
  292. zrtp_status_t (*on_init)(zrtp_global_t* zrtp);
  293. /**
  294. * \brief Delay Calls deinitialization.
  295. *
  296. * libzrtp calls this function when zrtp scheduler is no longer needed at zrtp_down().
  297. * \sa zrtp_callback_scheduler_t#on_init()
  298. */
  299. void (*on_down)();
  300. /**
  301. * \brief Interface for performing delay call
  302. *
  303. * This function should add delay call request (\c task) to the processing queue. When the
  304. * zrtp_retry_task_t#timeout is expired, scheduler should call zrtp_retry_task_t#callback and
  305. * remove tasks from the processing queue.
  306. *
  307. * \param stream - stream context for processing the callback function;
  308. * \param task - task structure that should be processed.
  309. * \sa zrtp_callback_scheduler_t#on_cancel_call_later
  310. */
  311. void (*on_call_later)(zrtp_stream_t *stream, zrtp_retry_task_t* task);
  312. /**
  313. * \brief Interface for canceling a delay calls
  314. *
  315. * This function cancels delay call if it still in the processing queue. The algorithm is the
  316. * following:
  317. * - If there is a specified task for a specified stream, this task should be deleted.
  318. * - If the \c task parameter is equal to NULL - ALL tasks for the specified stream must be
  319. * terminated and removed from the queue.
  320. *
  321. * \param ctx - stream context for the operation;
  322. * \param task - delayed call wrapper structure.
  323. * \sa zrtp_callback_scheduler_t#on_call_later
  324. */
  325. void (*on_cancel_call_later)(zrtp_stream_t* ctx, zrtp_retry_task_t* task);
  326. /**
  327. * \brief Interface for waiting for scheduling tasks is finished
  328. *
  329. * This function is called by libzrtp when the state-mamchine is in a position to destroy ZRTP
  330. * session and all incapsulated streams. Allocated for the stream memory may be cleared and
  331. * released. If after this operation, scheduler perform time-out call it will bring system to
  332. * crash.
  333. *
  334. * The scheduler implementation must guarantee that any delay call for the \c stream will not be
  335. * performed after on_wait_call_later().
  336. *
  337. * \param stream - stream context for the operation;
  338. * \sa zrtp_callback_scheduler_t#on_call_later.
  339. */
  340. void (*on_wait_call_later)(zrtp_stream_t* stream);
  341. } zrtp_callback_scheduler_t;
  342. /** \} */
  343. /*======================================================================*/
  344. /* libzrtp interface: Protocol */
  345. /*======================================================================*/
  346. /**
  347. * \defgroup zrtp_iface_proto ZRTP Protocol Feedback
  348. * \ingroup zrtp_iface
  349. *
  350. * This section defines ZRTP protcol events. Detail description of ZRTP state-machine is defined in
  351. * \ref XXX.
  352. * \{
  353. */
  354. /**
  355. * \brief ZRTP Protocol events
  356. *
  357. * For additional information see \ref XXX
  358. */
  359. typedef enum zrtp_protocol_event_t
  360. {
  361. /** \brief Just a stub for error detection. */
  362. ZRTP_EVENT_UNSUPPORTED = 0,
  363. /** \brief Switching to CLEAR state */
  364. ZRTP_EVENT_IS_CLEAR,
  365. /** \brief Switching to INITIATING_SECURE state */
  366. ZRTP_EVENT_IS_INITIATINGSECURE,
  367. /** \brief Switching to PENDING_SECURE state */
  368. ZRTP_EVENT_IS_PENDINGSECURE,
  369. /** \brief Switching to PENDING_CLEAR state */
  370. ZRTP_EVENT_IS_PENDINGCLEAR,
  371. /**
  372. * \brief Switching to NO_ZRTP state.
  373. *
  374. * Hello packet undelivered - no ZRTP endpoint and other end
  375. */
  376. ZRTP_EVENT_NO_ZRTP,
  377. /**
  378. * \brief First N Hello packet undelivered - probably, no ZRTP endpoint and other end
  379. *
  380. * Libzrtp raises this event after few Hello have been send without receiving response from the
  381. * remote endpoint. User application may use this event to stop Securing ritual if connection
  382. * lag is important.
  383. *
  384. * Developer should take into account that delays in Hello receiving may be conditioned by
  385. * interruptions in media channel
  386. *
  387. * \warning Don't handle this event unless necessary
  388. */
  389. ZRTP_EVENT_NO_ZRTP_QUICK,
  390. /**
  391. * \brief MiTM Enrollment with MiTM endpoint
  392. *
  393. * Informs the Client-side endpoint of receiving a registration invitation from the MiTM.
  394. * Libzrtp raises this event after switching to the Secure state (ZRTP_EVENT_IS_SECURE). The
  395. * user may accept the invitation using a zrtp_register_with_trusted_mitm() call.
  396. */
  397. ZRTP_EVENT_IS_CLIENT_ENROLLMENT,
  398. /**
  399. * \brief New user has registered to the MitM
  400. *
  401. * Informs MitM of the registration of a new user. Libzrtp raises this event when a user calls
  402. * the special registration number and has switched to the secure state.
  403. */
  404. ZRTP_EVENT_NEW_USER_ENROLLED,
  405. /**
  406. * \brief New user has already registered with the MiTM
  407. *
  408. * Notifies the MiTM of an attempt to register from a user that is already registered. In this
  409. * case a new MiTM secret will not be generated and the user may be informed by voice prompt.
  410. * Libzrtp raises this event from the SECURE state.
  411. */
  412. ZRTP_EVENT_USER_ALREADY_ENROLLED,
  413. /**
  414. * \brief User has cancelled registration
  415. *
  416. * Libzrtp may raise this event during regular calls when it discovers that the user has removed
  417. * its MiTM secret. This event informs the MiTM that the SAS can no longer be transferred to
  418. * this user.
  419. */
  420. ZRTP_EVENT_USER_UNENROLLED,
  421. /**
  422. * \brief SAS value and/or rendering scheme was updated
  423. *
  424. * LibZRTP raises this event when the SAS value is transferred from the trusted MiTM. The value
  425. * is rendered automatically according to the rendering scheme specified by the trusted MiTM.
  426. * (it may be different than that of the previous one).
  427. *
  428. * On receiving this event, the Client application should replace the old SAS with the new one
  429. * and ask the user to verify it. This event is called from the Secure state only.
  430. */
  431. ZRTP_EVENT_LOCAL_SAS_UPDATED,
  432. /**
  433. * \brief SAS transfer was accepted by the remote side
  434. *
  435. * Libzrtp raises this event to inform the Server-side about accepting the change of SAS value
  436. * and/or rendering scheme by the remote client. This event is called from the Secure state
  437. * only.
  438. */
  439. ZRTP_EVENT_REMOTE_SAS_UPDATED,
  440. /**
  441. * \brief Swishing to SECURE state
  442. *
  443. * Duplicates zrtp_callback_event_t#on_zrtp_secure for more thin adjustments.
  444. */
  445. ZRTP_EVENT_IS_SECURE,
  446. /**
  447. * \brief Swishing to SECURE state is finished.
  448. *
  449. * Equal to ZRTP_EVENT_IS_SECURE but called when the Securing process is completely finished:
  450. * new RS secret is generate, cache flags updated and etc. Can be used in extended application
  451. * for more thin adjustments.
  452. */
  453. ZRTP_EVENT_IS_SECURE_DONE,
  454. /**
  455. * \brief Indicates DRM restriction. Stream can't go Secure.
  456. *
  457. * Libzrtp generate this event if DRM rules don't allow to switch to Secure mode:
  458. * - A passive endpoint never sends a Commit message. Semi-active endpoint does not send a
  459. * Commit to a passive endpoint
  460. * - A passive phone, if acting as a SIP initiator r ejects all commit packets from everyone.
  461. * - A passive phone rejects all commit messages from a PBX.
  462. */
  463. ZRTP_EVENT_IS_PASSIVE_RESTRICTION,
  464. ZRTP_EVENT_COUNT
  465. } zrtp_protocol_event_t;
  466. /**
  467. * \brief ZRTP Protocol Errors and Warnings
  468. *
  469. * For additional information see \ref XXX
  470. */
  471. typedef enum zrtp_security_event_t
  472. {
  473. /**
  474. * \brief Switching to ERROR state
  475. *
  476. * The exact error code can be found at zrtp_stream_info_t#last_error. Use zrtp_log_error2str()
  477. * to get error description in text mode.
  478. */
  479. ZRTP_EVENT_PROTOCOL_ERROR = ZRTP_EVENT_COUNT,
  480. /**
  481. * \brief Hello Hash is different from that received in signaling.
  482. *
  483. * In accordance with sec. 8.1 of the ZRTP RFC, libzrtp provides the ability to prevent DOS
  484. * attacks. libzrtp can detect an attack in which the hash of the remote Hello was received
  485. * through signaling and added to the ZRTP context (zrtp_signaling_hash_set()).
  486. *
  487. * When the hash of the incoming Hello doesn't match the hash from signaling, the
  488. * ZRTP_EVENT_WRONG_SIGNALING_HASH event is raised and the connection MAY be terminated
  489. * manually.
  490. */
  491. ZRTP_EVENT_WRONG_SIGNALING_HASH,
  492. /**
  493. * \brief Hmac of the received packet is different from the hmac value earlier received.
  494. *
  495. * If the Hello hash is sent through protected signaling, libzrtp provides the ability to
  496. * prevent protocol packets from modification and even eliminates comparing the SAS. To do this,
  497. * libzrtp compares the message Hmac with the Hmac received in the previous message.
  498. *
  499. * If the Hmacs don't match, the ZRTP_EVENT_WRONG_MESSAGE_HMAC event is raised and the
  500. * connection MAY be terminated manually.
  501. */
  502. ZRTP_EVENT_WRONG_MESSAGE_HMAC,
  503. /**
  504. * \brief Retain secret was found in the cache but it doesn't match with the remote one
  505. *
  506. * The library rises this event when non-expired secret have been found in the cache but
  507. * value of the secret doesn't match with the remote side secret. Such situation may happen
  508. * in case of MiTM attack or when remote side lost it's cache.
  509. *
  510. * Recommended behavior: the application should notify user about the situation and ask him to
  511. * verify the SAS. If SAS is different - it indicates the attack.
  512. */
  513. ZRTP_EVENT_MITM_WARNING
  514. } zrtp_security_event_t;
  515. /**
  516. * \brief Callbacks definitions
  517. *
  518. * This section lists callback functions informing the user about the protocol status. These
  519. * callbacks must be defined in the user application.
  520. */
  521. typedef struct zrtp_callback_event_t
  522. {
  523. /**
  524. * \brief ZRTP Protocol events notification.
  525. *
  526. * Informs about switching between the protocol states and other events. Provides more flexible
  527. * control over the protocol then on_zrtp_secure and on_zrtp_not_secure.
  528. *
  529. * \param event - type of event;
  530. * \param stream - ZRTP stream context.
  531. */
  532. void (*on_zrtp_protocol_event)(zrtp_stream_t *stream, zrtp_protocol_event_t event);
  533. /**
  534. * \brief ZRTP Security events notification
  535. *
  536. * Informs about ZRTP security events: MiTM attacks, cache desynchronization and
  537. * others.
  538. * \warning MUST be handled in the target application to provide high security level.
  539. *
  540. * \param event - type of event;
  541. * \param stream - ZRTP stream context.
  542. */
  543. void (*on_zrtp_security_event)(zrtp_stream_t *stream, zrtp_security_event_t event);
  544. /**
  545. * \brief Indicates switching to SECURE state.
  546. *
  547. * Pair of events: \c on_zrtp_secure and \c on_zrtp_not_secure represent simplified event
  548. * handling mechanism comparing to \c on_zrtp_protocol_event. libzrtp calls this event when the
  549. * call is SECURE and media is encrypted.
  550. *
  551. * SAS Verification is required on this event.
  552. *
  553. * \param stream - ZRTP stream context.
  554. */
  555. void (*on_zrtp_secure)(zrtp_stream_t *stream);
  556. /**
  557. * \brief Indicates switching to NOT SECURE state.
  558. *
  559. * This event duplicates some protocol and security events to simplify libzrtp usage. It may be
  560. * used in applications which don't require detail information about ZRTP protocol.
  561. *
  562. * If Error appeared - the exact error code can be found at zrtp_stream_info_t#last_error. Use
  563. * zrtp_log_error2str() to get error description in text mode.
  564. *
  565. * \param stream - ZRTP stream context.
  566. */
  567. void (*on_zrtp_not_secure)(zrtp_stream_t *stream);
  568. } zrtp_callback_event_t;
  569. /** \} */
  570. /*======================================================================*/
  571. /* libzrtp interface: Misc */
  572. /*======================================================================*/
  573. /**
  574. * \defgroup zrtp_iface_misc Miscellaneous functions
  575. * \ingroup zrtp_iface
  576. * \{
  577. */
  578. /**
  579. * \brief Miscellaneous Functions
  580. */
  581. typedef struct zrtp_callback_misc_t
  582. {
  583. /**
  584. * \brief RTP packet sending function
  585. *
  586. * This function pushes an outgoing ZRTP packet to the network. Correct building of IP and UPD
  587. * headers is the developer's responsibility.
  588. *
  589. * \param stream - ZRTP stream context;
  590. * \param packet - buffer storing the ZRTP packet to send;
  591. * \param length - size of the ZRTP packet.
  592. * \return
  593. * - number of bytes sent if successful;
  594. * - -1 if error occurred.
  595. */
  596. int (*on_send_packet)(const zrtp_stream_t* stream, char* packet, unsigned int length);
  597. } zrtp_callback_misc_t;
  598. /** \} */
  599. /**
  600. * \brief ZRTP feedback interface and application dependent routine
  601. * \ingroup zrtp_iface
  602. */
  603. typedef struct zrtp_callback_t
  604. {
  605. /** \brief ZRTP Protocol Feedback */
  606. zrtp_callback_event_t event_cb;
  607. /** \brief ZRTP Delay Calls routine */
  608. zrtp_callback_scheduler_t sched_cb;
  609. /** \brief ZRTP Cache */
  610. zrtp_callback_cache_t cache_cb;
  611. /** \brief Miscellaneous functions */
  612. zrtp_callback_misc_t misc_cb;
  613. } zrtp_callback_t;
  614. #if defined(__cplusplus)
  615. }
  616. #endif
  617. #endif /*__ZRTP_IFACE_H__*/