2
0

howto.dox 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. #
  2. # Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.
  3. # Contact: http://philzimmermann.com
  4. # For licensing and other legal details, see the file zrtp_legal.c.
  5. #
  6. # Viktor Krykun <v.krikun at zfoneproject.com>
  7. /**
  8. * \file howto.dox
  9. * \brief How to Get Up and Running Quickly with libZRTP
  10. */
  11. /**
  12. \page howto How to Get Up and Running Quickly with libZRTP
  13. ****************************************************************************************************
  14. \section howto_about 1. About
  15. ****************************************************************************************************
  16. <HR>
  17. The libzrtp library is a cross-platform implementation of ZRTP, a VoIP encryption protocol developed by Phil Zimmermann. libzrtp is suitable for inclusion in software VoIP clients, firmware for hardware VoIP phones, VoIP PBX servers, mobile VoIP clients, and SIP border control servers, enabling a VoIP application to interoperate and make secure calls with the rest of the ZRTP
  18. community.
  19. The libzrtp library consists of three main components: the protocol module responsible for the safe connection of a call, the encryption module, and a set of interfaces. ZRTP works by assuming control of the VoIP traffic and initiating an encrypted connection between two ZRTP endpoints after a safe mode is achieved. To integrate the library, please review our documentation on the
  20. ZRTP interfaces, connections management, and integration plan.
  21. ****************************************************************************************************
  22. \section howto_quick 2. Quick Info
  23. ****************************************************************************************************
  24. <HR>
  25. ***<H3>Building with GNU tools (Linux, *BSD, MacOS X, mingw, etc.)</H3>
  26. Generally these should be all that are needed to build the libraries, applications, and samples:
  27. -# go to ./projects/gnu and run
  28. \code
  29. $ ./configure
  30. $ make clean && make
  31. \endcode
  32. **<H3>Building Win32 Target with Microsoft Visual Studio</H3>
  33. Generally we can just do these steps:
  34. -# Visual Studio 8: open projects/win/libzrtp_vc8.sln solution,
  35. -# build the libzrtp_test application.
  36. **<H3>Building for Windows Mobile</H3>
  37. Generally these are all that are needed:
  38. -# Visual Studio 8: open projects/win/libzrtp_wince_vc8.sln solution,
  39. -# build the libzrtp_test application.
  40. **<H3>Locating Output Binaries/Libraries</H3>
  41. For GNU targets, library files will be placed to <c>./projects/gnu/build</c> and <c>./third_party/bnlib</c>.
  42. **<H3>Running the Applications</H3>
  43. After successful build, you can try running libzrtp_test application on projects/gnu/build/test directory.
  44. ****************************************************************************************************
  45. \section howto_getting_source 3. Getting the Source Distribution
  46. ****************************************************************************************************
  47. <HR>
  48. ***\subsection howto_getting_source_tar 3.1 Getting the Release tarball
  49. Getting the released tarball is the best way to obtain stable version of libzrtp. The tarball may not contain the latest features or bug-fixes, but normally it is considered more stable, tested and well documented.
  50. The latest released tarball can be downloaded from the http://zfoneproject.com/prod_sdk.html
  51. ***\subsection howto_getting_source_svn 3.2 Getting from Subversion trunk
  52. At the moment, SVN repository is available for libzrtp developers only. It will be opened for public soon.
  53. ***\subsection howto_getting_source_layout 3.3 Source Directories Layout
  54. The top-level directories (denoted as $TOP here) in the source distribution contains the following sub-directories:
  55. \c $TOP/doc - documentation folder;
  56. \c $TOP/include - header files:
  57. - \c zrtp_config_user.h - user defined ZRTP configuration options;
  58. - \c zrtp_config_win.h - Windows related configuration options;
  59. - \c zrtp_config.h - libzrtp automatic configuration routine.
  60. - \c zrtp_crypto.h - contains definitions of the data types and functions necessary to
  61. strengthen the crypto-segment of the library. These functions are used only by libzrtp
  62. developers only. Typical projects based on libzrtp do not use these functions;
  63. - \c zrtp_engine.h - contains types and functions needed by the ZRTP state-machine For
  64. internal use only;
  65. - \c zrtp_error.h - contains error codes returned by the libzrtp functions;
  66. - \c zrtp_iface_system.h - contains a set of OS-related interface functions which must be
  67. implemented in order to use the library;
  68. - \c zrtp_iface.h - contains a set of ZRTP utility interface functions which must be
  69. implemented in order to use the library;
  70. - \c zrtp_legal.h - libzrtp license agreement;
  71. - \c zrtp_list.h - contains functions and macros for safe operations with linked lists. All
  72. lists in libzrtp are based on these functions. They can be used to avoid mistakes in list operations;
  73. - \c zrtp_log.h - contains functions to track bugs and store the error log.;
  74. - \c zrtp_pbx.h - conatins declarations of the main PBX related functions. Use this header if you are the implementor of some VoIP-server solutions;
  75. - \c zrtp_srtp.h - SRTP crypto types and interfaces. Used to integrate libzrtp with third
  76. party SRTP implementations;
  77. - \c zrtp_srtp_builtin.h - data structures for built-in realization of SRTP.
  78. - \c zrtp_string.h - contains functions for the use of the special, safe strings,
  79. zrtp_stringn_t, used by libzrtp.
  80. - \c zrtp_types.h - contains the definitions of the internal data types which are used by
  81. libzrtp developers and experienced users.
  82. - \c zrtp.h - conatins declarations of the main dataypes and function
  83. functions necessary to operate libzrtp. This file header is only must to
  84. be included in each module using the libzrt functions;
  85. \c $TOP/projects
  86. - \c gnu - make files for Unix-like systems using autotools;
  87. - \c symbian - configuration and make files for Symbian platform;
  88. - \c win - Set of Microsoft Visual Studio project files for Windows and Windows CE.
  89. - \c win_kernel - makefiles for Windows Kernel mode.
  90. - \c xcode - project files for Apple Xcode.
  91. \c $TOP/src - libzrtp source files;\n
  92. \c $TOP/test - test suite for libZRTP kernel logic. Includes versions for Unix, Windows,
  93. Windows CE and Symbian.
  94. \c $TOP/third_party
  95. - \c bnlib - libbn files which are not intended for external use;
  96. - \c bgaes - AES encryption library and hash functions by Brian Gladman;
  97. ****************************************************************************************************
  98. \section howto_praparations 4. Build Preparation
  99. ****************************************************************************************************
  100. <HR>
  101. ***\subsection howto_praparations_config 4.1 zrtp_cinfig_user.h
  102. Before building libzrtp, some adjustments may be performed according to developers needs. In order to do this, \c include/zrtp_cinfig_user.h should be used. Most of configuration parameters are optional and libzrtp can be build without any modifications.
  103. Check \ref zrtp_config for more information.
  104. ***\subsection howto_praparations_iface 4.2 libzrtp platform-dependent interfaces
  105. The library requires external implementation of some system-dependent functions to enable cross-platform operation. The libzrtp distribution contains almost all interface implementations for the following platforms: Windows, Linux, Mac OSX, Symbian, Windows CE. The Quick Start allows a fast integration of the library. Built-in implementations are used by default and developer don't need to anything more.
  106. In order to start using libzrtp, developer should implement just few feedback interfaces. Libzrtp uses callbacks to notify application about some events in ZRTP protocol, such as:
  107. - zrtp_callback_event_t#on_zrtp_secure - notify user about switching to secure;
  108. - zrtp_callback_event_t#on_zrtp_not_secure - notify about ZRTP security issues.
  109. Another callback which must be implemented - transport routine:
  110. - zrtp_callback_misc_t#on_send_packet - libzrtp uses this function to deliver ZRTP protocol message to the remote party.
  111. These only two callbacks which must be implemented to start using libzrtp. Example can be found at the end of this article.
  112. For more detail information about libzrtp platform-dependent interfaces check \ref XXX.
  113. ****************************************************************************************************
  114. \section howto_unix 5. Building Linux, *nix, *BSD, and MacOS X Targets with GNU Build Systems
  115. ****************************************************************************************************
  116. <HR>
  117. ***\subsection howto_unix_targets Supported Targets
  118. The new, autoconf based GNU build system can be used to build the libraries/applications for the following targets:
  119. - Linux (i386, Opteron, Itanium, MIPS, PowerPC, etc.),
  120. - MacOS X (Intel, PowerPC),
  121. - mingw (i386),
  122. - FreeBSD (i386, Opteron, etc.),
  123. - etc.
  124. ***\subsection howto_unix_requir 5.1 Requirements
  125. In order to use libzrtp's GNU build system, these typical GNU tools are needed:
  126. - GNU make,
  127. - GNU binutils for the target, and
  128. - GNU gcc for the target.
  129. In addition, the appropriate libraries must be installed for platform-dependent interfaces implementation. This could just be a libc and the appropriate system abstraction library such as Posix.
  130. The build system is known to work on the following hosts:
  131. - Linux, many types of distributions.
  132. - MacOS X 10.4 and higher
  133. ***\subsection howto_unix_build 5.2 Running configure and make
  134. Run "./configure" without any options to let the script detect the appropriate settings for the host:
  135. \code
  136. $ cd libzrtp
  137. $ ./configure
  138. ...
  139. \endcode
  140. Once the configure script completes successfully, libzrtp is ready to be built. Use following commands:
  141. \code
  142. $ cd libzrtp
  143. $ make clean
  144. $ make
  145. \endcode
  146. Description of all make targets supported by the Makefile's:
  147. - \c all. The default (or first) target to build the library binary;
  148. - \c clean. Clean the object files and libzrtp binary;
  149. - \c check. Build test cases and start libzrtp_test application;
  150. - \c distclean. Remove all generated files (object, libraries, binaries, and
  151. dependency files).
  152. - \c install. Make install of libzrtp headers and binaries;
  153. - \c uninstall. Remove installed headers and binaries.
  154. ****************************************************************************************************
  155. \section howto_osx 6. Building MacOS X Targets with Xcode
  156. ****************************************************************************************************
  157. <HR>
  158. ***\subsection howto_osx_requir 6.1 Requirements
  159. To build libzrtp on OS X using Xcode you need following:
  160. - Mac OSX 10.4 or later.
  161. - Apple developers Tools installed.
  162. - Xcode 3.1 or higher.
  163. ***\subsection howto_osx_build 6.2 Building the Projects
  164. Follow the steps below to build libzrtp using Apple Xcode:
  165. -# For Apple Xcode: open \c projects/xcode/libzrtp.xcodeproj project file.
  166. -# Set "libzrtp" or "libzrtp_ec" as Active Target.
  167. -# Select Debug or Release build as appropriate.
  168. -# Build "configure" target.
  169. -# Build the project. This will build libzrtp with all dependencies.
  170. -# After successful build, libzrtp will be placed in \c projects/xcode/build/Debug or Release.
  171. Use \c projects/xcode/libzrtp_test.xcodeproj by analogy to build the test application.
  172. ****************************************************************************************************
  173. \section howto_win 7. Building for Windows Targets with Microsoft Visual Studio
  174. ****************************************************************************************************
  175. <HR>
  176. ***\subsection howto_win_requir 7.1 Requirements
  177. The Microsoft Visual Studio based project files can be used with one of the following:
  178. - Microsoft Visual C++ 2005 (including Express edition),
  179. For the host platform, the following are required:
  180. - Windows NT, 2000, XP, 2003, or later ,
  181. - Sufficient amount of RAM for the build process (at least 256MB).
  182. ***\subsection howto_win_build 7.2 Building the Projects
  183. Follow the steps below to build libzrtp using Visual Studio:
  184. -# For Visual Studio 8 (VS 2005): open libzrtp_vs8.sln solution file.
  185. -# Set "libzrtp" or "libzrtp_ec" as StartUp Project.
  186. -# Select Debug or Release build as appropriate.
  187. -# Build the project. This will build libzrtp and all dependencies.
  188. -# After successful build, libzrtp will be placed in \c projects/win/Debug or Release.
  189. To build libzrtp test-cases use "libzrtp_test" as StartUp Project and perform steps listed above.
  190. ****************************************************************************************************
  191. \section howto_wince 8. Building for Windows Mobile Targets (Windows CE/WinCE/PDA/SmartPhone)
  192. ****************************************************************************************************
  193. <HR>
  194. ***\subsection howto_wince_requir 8.1 Requirements
  195. The Microsoft Visual Studio based project files can be used with one of the following:
  196. - Microsoft Visual C++ 2005
  197. For the host platform, the following are required:
  198. - Windows NT, 2000, XP, 2003, or later ,
  199. - Sufficient amount of RAM for the build process (at least 256MB).
  200. ***\subsection howto_wince_build 8.2 Building the Projects
  201. Follow the steps below to build libzrtp using Visual Studio:
  202. -# For Visual Studio 8 (VS 2005): open libzrtp_wince_vs8.sln solution file.
  203. -# Set "libzrtp" or "libzrtp_ec" as StartUp Project.
  204. -# Select Debug or Release build as appropriate.
  205. -# Build the project. This will build libzrtp and all dependencies.
  206. -# After successful build, libzrtp will be placed in \c projects/win/Debug or Release.
  207. \note
  208. The Test Application is not available for Windows Mobile platform at the moment. We will fix this in next version of libzrtp.
  209. ****************************************************************************************************
  210. \section howto_symbian 9. Building for Symbian
  211. ****************************************************************************************************
  212. <HR>
  213. ****************************************************************************************************
  214. \section howto_using 10. Using libzrtp with Applications
  215. ****************************************************************************************************
  216. <HR>
  217. Regardless of the build system being used, the following tasks are normally needed to be done in order to build application to use libzrtp:
  218. -# Add following include directories in the include search path:
  219. - \c libzrtp/include
  220. - \c libzrtp/include/enterprise (if you are using Enterprise version of libzrtp)
  221. - \c libzrtp/third_party/bgaes
  222. - \c libzrtp/third_party/bnlib
  223. - \c libzrtp/projects/gnu/config (for GNU Autoconf targets)
  224. -# Put these library directories in the library search path:
  225. - \c libzrtp/third_party/bnlib
  226. - \c libzrtp/projects/gnu/build (for GNU Autoconf targets)
  227. - \c libzrtp/projects/xcode/build/Release (when building with Xcode)
  228. - \c libzrtp/projects/win/Release (when building with Visual Studio)
  229. -# Include \c libzrtp.h header file to the application.
  230. -# Link with \c libzrtp and \c bnlib.
  231. -# Link with system spesific libraries:
  232. - Windows: Add (among other things): ws2_32.lib.
  233. - Linux, *nix, *BSD: Add (among other things): '-lpthread'.
  234. - MacOS X: Add (among other things): '-lpthread'.
  235. ****************************************************************************************************
  236. \section howto_example 11. Quick Start Example
  237. ****************************************************************************************************
  238. <HR>
  239. An overview for creating an encrypted channel using libzrtp:
  240. *** \subsection howto_example_init 11.1 Initialization
  241. The library supports profiling and dictating different channel parameters, though the initialization can be performed by one function call with default parameters.
  242. \code
  243. typedef struct testcon_t
  244. {
  245. zrtp_session_t *zrtp_session; // ZRTP Session structure
  246. zrtp_stream_t *zrtp_audio; // ZRTP stream for voice encryption
  247. zrtp_stream__t *zrtp_video; // ZRTP stream for video encryption
  248. } testcon_t;
  249. testcon_t safe_connection; // Secure channel instance
  250. zrtp_global_t zrtp_global; // Persistent storage for libzrtp data
  251. \endcode
  252. \code
  253. zrtp_status_t s = zrtp_status_ok;
  254. zrtp_config_t zrtp_config;
  255. // Initialize zrtp config with default values
  256. zrtp_config_defaults(&zrtp_config);
  257. // Make some adjustments:
  258. // - Set Client ID to identify ourself
  259. // - Set appropriate license mode
  260. // - We going to use default zrtp cache implementation, so let's specify cache file path
  261. strcpy(zrtp_config.client_id, TEST_CLIENT_ID);
  262. zrtp_config.lic_mode = ZRTP_LICENSE_MODE_ACTIVE;
  263. zrtp_zstrcpyc( ZSTR_GV(zrtp_config.def_cache_path), TEST_CACHE_PATH);
  264. // Define interface callback functions
  265. zrtp_config.cb.misc_cb.on_send_packet = on_send_packet;
  266. zrtp_config.cb.event_cb.on_zrtp_secure = on_zrtp_secure;
  267. zrtp_config.cb.event_cb.on_zrtp_security_event = on_zrtp_event;
  268. // Everything is ready - initialize libzrtp.
  269. s = zrtp_init(&zrtp_config, &zrtp_global);
  270. if (zrtp_status_ok != s) {
  271. // Check error code and debug logs
  272. }
  273. // The library has been initialized and is ready to use
  274. . . .
  275. \endcode
  276. *** \subsection howto_example_sessions 11.2 Sessions/Streams
  277. The library operates with the ZRTP streams concept, where each packet is encrypted within this stream. The streams are created before the start of the encryption process.
  278. \code
  279. //
  280. // Allocate zrtp session with default parameters
  281. //
  282. z = zrtp_session_init( zrtp_global,
  283. NULL,
  284. zid,
  285. is_initator,
  286. &safe_connection->zrtp_session);
  287. if (zrtp_status_ok != s) {
  288. // Check error code and debug logs
  289. }
  290. // Set call-back pointer to our parent structure
  291. zrtp_session_set_userdata(safe_connection->zrtp_session, &safe_connection);
  292. //
  293. // Attach Audio and Video Streams
  294. //
  295. s = zrtp_stream_attach(safe_connection->zrtp_session, &safe_connection->zrtp_audio);
  296. if (zrtp_status_ok != s) {
  297. // Check error code and debug logs
  298. }
  299. zrtp_stream_set_userdata(safe_connection->zrtp_audio, &safe_connection);
  300. s = zrtp_stream_attach(safe_connection->zrtp_session, &safe_connection->zrtp_video);
  301. if (zrtp_status_ok != s) {
  302. // Check error code and debug logs
  303. }
  304. zrtp_stream_set_userdata(safe_connection->zrtp_video, &safe_connection);
  305. \endcode
  306. *** \subsection howto_example_protocol 11.3 Protocol Handling
  307. To create an encrypted channel, run the ZRTP engine for each stream added to the session. In our case we have two streams. The library will notify when achieving safe mode through the feedback path interface.
  308. \code
  309. //
  310. // Streams are ready - initiate ZRTP protocol
  311. //
  312. zrtp_stream_start(safe_connection->zrtp_audio, assrc);
  313. zrtp_stream_start(safe_connection->zrtp_video, vssrc);
  314. \endcode
  315. The three steps above create the encrypted channel. After entering the "Secure" state, you provide a plain packet to the library and receive an encrypted packet ready to be sent. Decryption works in the analogous way.
  316. \code
  317. zrtp_status_t s = zrtp_status_fail;
  318. char packet[MAX_RTP_SIZE];
  319. int size = 0;
  320. // Some abstract function for packets receiving
  321. size = get_packet(packet);
  322. //
  323. // Processing incoming packets.
  324. // You must determine media type and choose corresponding ZRTP stream
  325. //
  326. s = zrtp_process_srtp(safe_connection->zrtp_audio, packet, &size);
  327. switch (s) {
  328. case zrtp_status_ok:
  329. //
  330. // Packet was successfully decrypted. Dont forget that packet
  331. // size was changed during decryption. New size now in size
  332. //
  333. case zrtp_status_drop:
  334. //
  335. // This is a protocol ZRTP packet or masked RTP media.
  336. // In either case the packet must be dropped to protect your
  337. // private data and media codec
  338. case zrtp_status_fail:
  339. //
  340. // This is some kind of error - see logs for more information.
  341. // Don't put such packet to the network. It is not secure.
  342. //
  343. }
  344. \endcode
  345. *** \subsection howto_example_callbacks 11.4 Callbacks
  346. libzrtp informs the user application about all changes in protocol state through a system of callback functions. The developer's guide considers this question in detail in \ref XXX. In most cases we need to display the SAS string and some other stream options after switching to the Secure state. An example of doing this is follow:
  347. \code
  348. static void on_zrtp_secure(zrtp_stream_t *stream, unsigned event)
  349. {
  350. test_options_t* info; // some user-defined stream options
  351. switch (event) {
  352. case ZRTP_EVENT_IS_SECURE:
  353. {
  354. safe_connection_t* safe_connection = zrtp_stream_get_userdata(stream);
  355. zrtp_session_info_t zrtp_session_info;
  356. zrtp_session_get(safe_connection->zrtp_session, &zrtp_session_info);
  357. //
  358. // Print out SAS there.
  359. //
  360. } break;
  361. // ...
  362. // handle other events there
  363. default:
  364. break;
  365. }
  366. }
  367. \endcode
  368. An overview for closing an secure channel using libzrtp:
  369. *** \subsection howto_example_utilization 11.5 Utilization
  370. The uninstall session permits libzrtp to dispose of all engaged resources and release memory for session context storage. ZRTP streams will be also released, so you don't need to call separate functions.
  371. \code
  372. zrtp_session_down(safe_connection->zrtp_session);
  373. \endcode
  374. When you no longer need the library, dispose of all resources allocated before the beginning of the operation.
  375. \code
  376. zrtp_down(&zrtp_global);
  377. \endcode
  378. ****************************************************************************************************
  379. \section howto_summary 12. Summary
  380. ****************************************************************************************************
  381. <HR>
  382. Integration of libzrtp requires familiarity with the protocol and the library operation features. While the encryption of VoIP is not a trivial task, we have attempted to simplify as much as possible the work required to integrate libzrtp.
  383. */