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 ZRTP interfaces, connections management, and integration plan.
Generally these should be all that are needed to build the libraries, applications, and samples:
$ ./configure $ make clean && make
Generally we can just do these steps:
Generally these are all that are needed:
For GNU targets, library files will be placed to ./projects/gnu/build
and ./third_party/bnlib
.
After successful build, you can try running libzrtp_test application on projects/gnu/build/test directory.
The latest released tarball can be downloaded from the http://zfoneproject.com/prod_sdk.html
$TOP/doc
- documentation folder;
$TOP/include
- header files:
zrtp_config_user.h
- user defined ZRTP configuration options;zrtp_config_win.h
- Windows related configuration options;zrtp_config.h
- libzrtp automatic configuration routine.zrtp_crypto.h
- contains definitions of the data types and functions necessary to strengthen the crypto-segment of the library. These functions are used only by libzrtp developers only. Typical projects based on libzrtp do not use these functions;zrtp_engine.h
- contains types and functions needed by the ZRTP state-machine For internal use only;zrtp_error.h
- contains error codes returned by the libzrtp functions;zrtp_iface_system.h
- contains a set of OS-related interface functions which must be implemented in order to use the library;zrtp_iface.h
- contains a set of ZRTP utility interface functions which must be implemented in order to use the library;zrtp_legal.h
- libzrtp license agreement;zrtp_list.h
- contains functions and macros for safe operations with linked lists. All lists in libzrtp are based on these functions. They can be used to avoid mistakes in list operations;zrtp_log.h
- contains functions to track bugs and store the error log.;zrtp_pbx.h
- conatins declarations of the main PBX related functions. Use this header if you are the implementor of some VoIP-server solutions;zrtp_srtp.h
- SRTP crypto types and interfaces. Used to integrate libzrtp with third party SRTP implementations;zrtp_srtp_builtin.h
- data structures for built-in realization of SRTP.zrtp_string.h
- contains functions for the use of the special, safe strings, zrtp_stringn_t, used by libzrtp.zrtp_types.h
- contains the definitions of the internal data types which are used by libzrtp developers and experienced users.zrtp.h
- conatins declarations of the main dataypes and function functions necessary to operate libzrtp. This file header is only must to be included in each module using the libzrt functions;
$TOP/projects
gnu
- make files for Unix-like systems using autotools;symbian
- configuration and make files for Symbian platform;win
- Set of Microsoft Visual Studio project files for Windows and Windows CE.win_kernel
- makefiles for Windows Kernel mode.xcode
- project files for Apple Xcode.
$TOP/src
- libzrtp source files;
$TOP/test
- test suite for libZRTP kernel logic. Includes versions for Unix, Windows, Windows CE and Symbian.
$TOP/third_party
bnlib
- libbn files which are not intended for external use;bgaes
- AES encryption library and hash functions by Brian Gladman;include/zrtp_cinfig_user.h
should be used. Most of configuration parameters are optional and libzrtp can be build without any modifications.Check Build Configuration for more information.
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:
Another callback which must be implemented - transport routine:
These only two callbacks which must be implemented to start using libzrtp. Example can be found at the end of this article.
For more detail information about libzrtp platform-dependent interfaces check XXX.
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.
The build system is known to work on the following hosts:
$ cd libzrtp $ ./configure ...
Once the configure script completes successfully, libzrtp is ready to be built. Use following commands:
$ cd libzrtp $ make clean $ make
Description of all make targets supported by the Makefile's:
all
. The default (or first) target to build the library binary;clean
. Clean the object files and libzrtp binary;check
. Build test cases and start libzrtp_test application;distclean
. Remove all generated files (object, libraries, binaries, and dependency files).install
. Make install of libzrtp headers and binaries;uninstall
. Remove installed headers and binaries.projects/xcode/libzrtp.xcodeproj
project file.projects/xcode/build/Debug
or Release.
Use projects/xcode/libzrtp_test.xcodeproj
by analogy to build the test application.
For the host platform, the following are required:
projects/win/Debug
or Release.To build libzrtp test-cases use "libzrtp_test" as StartUp Project and perform steps listed above.
For the host platform, the following are required:
projects/win/Debug
or Release.
libzrtp/include
libzrtp/include/enterprise
(if you are using Enterprise version of libzrtp)libzrtp/third_party/bgaes
libzrtp/third_party/bnlib
libzrtp/projects/gnu/config
(for GNU Autoconf targets)libzrtp/third_party/bnlib
libzrtp/projects/gnu/build
(for GNU Autoconf targets)libzrtp/projects/xcode/build/Release
(when building with Xcode)libzrtp/projects/win/Release
(when building with Visual Studio)libzrtp.h
header file to the application.libzrtp
and bnlib
.An overview for creating an encrypted channel using libzrtp:
typedef struct testcon_t { zrtp_session_t *zrtp_session; // ZRTP Session structure zrtp_stream_t *zrtp_audio; // ZRTP stream for voice encryption zrtp_stream__t *zrtp_video; // ZRTP stream for video encryption } testcon_t; testcon_t safe_connection; // Secure channel instance zrtp_global_t zrtp_global; // Persistent storage for libzrtp data
zrtp_status_t s = zrtp_status_ok; zrtp_config_t zrtp_config; // Initialize zrtp config with default values zrtp_config_defaults(&zrtp_config); // Make some adjustments: // - Set Client ID to identify ourself // - Set appropriate license mode // - We going to use default zrtp cache implementation, so let's specify cache file path strcpy(zrtp_config.client_id, TEST_CLIENT_ID); zrtp_config.lic_mode = ZRTP_LICENSE_MODE_ACTIVE; zrtp_zstrcpyc( ZSTR_GV(zrtp_config.def_cache_path), TEST_CACHE_PATH); // Define interface callback functions zrtp_config.cb.misc_cb.on_send_packet = on_send_packet; zrtp_config.cb.event_cb.on_zrtp_secure = on_zrtp_secure; zrtp_config.cb.event_cb.on_zrtp_security_event = on_zrtp_event; // Everything is ready - initialize libzrtp. s = zrtp_init(&zrtp_config, &zrtp_global); if (zrtp_status_ok != s) { // Check error code and debug logs } // The library has been initialized and is ready to use . . .
// // Allocate zrtp session with default parameters // z = zrtp_session_init( zrtp_global, NULL, zid, is_initator, &safe_connection->zrtp_session); if (zrtp_status_ok != s) { // Check error code and debug logs } // Set call-back pointer to our parent structure zrtp_session_set_userdata(safe_connection->zrtp_session, &safe_connection); // // Attach Audio and Video Streams // s = zrtp_stream_attach(safe_connection->zrtp_session, &safe_connection->zrtp_audio); if (zrtp_status_ok != s) { // Check error code and debug logs } zrtp_stream_set_userdata(safe_connection->zrtp_audio, &safe_connection); s = zrtp_stream_attach(safe_connection->zrtp_session, &safe_connection->zrtp_video); if (zrtp_status_ok != s) { // Check error code and debug logs } zrtp_stream_set_userdata(safe_connection->zrtp_video, &safe_connection);
// // Streams are ready - initiate ZRTP protocol // zrtp_stream_start(safe_connection->zrtp_audio, assrc); zrtp_stream_start(safe_connection->zrtp_video, vssrc);
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.
zrtp_status_t s = zrtp_status_fail; char packet[MAX_RTP_SIZE]; int size = 0; // Some abstract function for packets receiving size = get_packet(packet); // // Processing incoming packets. // You must determine media type and choose corresponding ZRTP stream // s = zrtp_process_srtp(safe_connection->zrtp_audio, packet, &size); switch (s) { case zrtp_status_ok: // // Packet was successfully decrypted. Dont forget that packet // size was changed during decryption. New size now in size // case zrtp_status_drop: // // This is a protocol ZRTP packet or masked RTP media. // In either case the packet must be dropped to protect your // private data and media codec case zrtp_status_fail: // // This is some kind of error - see logs for more information. // Don't put such packet to the network. It is not secure. // }
static void on_zrtp_secure(zrtp_stream_t *stream, unsigned event) { test_options_t* info; // some user-defined stream options switch (event) { case ZRTP_EVENT_IS_SECURE: { safe_connection_t* safe_connection = zrtp_stream_get_userdata(stream); zrtp_session_info_t zrtp_session_info; zrtp_session_get(safe_connection->zrtp_session, &zrtp_session_info); // // Print out SAS there. // } break; // ... // handle other events there default: break; } }
An overview for closing an secure channel using libzrtp:
zrtp_session_down(safe_connection->zrtp_session);
When you no longer need the library, dispose of all resources allocated before the beginning of the operation.
zrtp_down(&zrtp_global);