blob: 04547718e2f0c969a545d440c87c9ba5a0200ecd [file] [log] [blame]
Alexandre Lision51140e12013-12-02 10:54:09 -05001/*
2 Copyright (C) 2006-2009 Werner Dittmann
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#ifndef _ZRTPQUEUE_H_
19#define _ZRTPQUEUE_H_
20
21#include <ccrtp/cqueue.h>
22#include <ccrtp/rtppkt.h>
23#include <libzrtpcpp/ZrtpCallback.h>
24#include <libzrtpcpp/TimeoutProvider.h>
25#include <libzrtpcpp/ZrtpConfigure.h>
26
27class __EXPORT ZrtpUserCallback;
28class __EXPORT ZRtp;
29
30NAMESPACE_COMMONCPP
31
32/**
33 * GNU ccRTP extension to support GNU ZRTP.
34 *
35 * ZRTP was developed by Phil Zimmermann and provides functions to
36 * negotiate keys and other necessary data (crypto data) to set-up
37 * the Secure RTP (SRTP) crypto context. Refer to Phil's ZRTP
38 * specification at his <a href="http://zfoneproject.com/">Zfone
39 * project</a> site to get more detailed imformation about the
40 * capabilities of ZRTP.
41 *
42 * <b>Short overview of the ZRTP implementation</b>
43 *
44 * ZRTP is a specific protocol to negotiate encryption algorithms
45 * and the required key material. ZRTP uses a RTP session to
46 * exchange its protocol messages.
47 *
48 * A complete GNU ZRTP implementation consists of two parts, the
49 * GNU ZRTP core and specific code that binds the GNU ZRTP core to
50 * the underlying RTP/SRTP stack and the operating system:
51 * <ul>
52 * <li>
53 * The GNU ZRTP core is independent of a specific RTP/SRTP
54 * stack and the operationg system and consists of the ZRTP
55 * protocol state engine, the ZRTP protocol messages, and the
56 * GNU ZRTP engine. The GNU ZRTP engine provides methods to
57 * setup ZRTP message and to analyze received ZRTP messages,
58 * to compute the crypto data required for SRTP, and to
59 * maintain the required hashes and HMAC.
60 * </li>
61 * <li>
62 * The second part of an implementation is specific
63 * <em>glue</em> code the binds the GNU ZRTP core to the
64 * actual RTP/SRTP implementation and other operating system
65 * specific services such as timers.
66 * </li>
67 * </ul>
68 *
69 * The GNU ZRTP core uses a callback interface class (refer to
70 * ZrtpCallback) to access RTP/SRTP or operating specific methods,
71 * for example to send data via the RTP/SRTP stack, to access
72 * timers, provide mutex handling, and to report events to the
73 * application.
74 *
75 * <b>The ZrtpQueue</b>
76 *
77 * ZrtpQueue implements code that is specific to the GNU ccRTP
78 * implementation. ZrtpQueue also implements the specific code to
79 * provide the mutex and timeout handling to the GNU ZRTP
80 * core. Both, the mutex and the timeout handling, use the GNU
81 * Common C++ library to stay independent of the operating
82 * seystem. For more information refer to the <a
83 * href="http://www.gnutelephony.org/index.php/GNU_Common_C%2B%2B">GNU
84 * Common C++</a> web site.
85 *
86 * To perform its tasks ZrtpQueue
87 * <ul>
88 * <li> extends GNU ccRTP classes to use the underlying
89 * ccRTP methods and the RTP/SRTP send and receive queues
90 * </li>
91 * <li> implements the ZrtpCallback interface to provide ccRTP
92 * access and other specific services (timer, mutex) to GNU
93 * ZRTP
94 * </li>
95 * <li> provides ZRTP specific methods that applications may use
96 * to control and setup GNU ZRTP
97 * </li>
98 * <li> can register and use an application specific callback
99 * class (refer to ZrtpUserCallback)
100 * </li>
101 * </ul>
102 *
103 * After instantiating a GNU ZRTP session (see below for a short
104 * example) applications may use the ZRTP specific methods of
105 * ZrtpQueue to control and setup GNU ZRTP, for example enable or
106 * disable ZRTP processing or getting ZRTP status information.
107 *
108 * GNU ZRTP provides a ZrtpUserCallback class that an application
109 * may extend and register with ZrtpQueue. GNU ZRTP and ZrtpQueue
110 * use the ZrtpUserCallback methods to report ZRTP events to the
111 * application. The application may display this information to
112 * the user or act otherwise.
113 *
114 * The following figure depicts the relationships between
115 * ZrtpQueue, ccRTP RTP/SRTP implementation, the GNU ZRTP core,
116 * and an application that provides an ZrtpUserCallback class.
117 *
118@verbatim
119
120 +----------+
121 | ccRTP |
122 | RTP/SRTP |
123 | |
124 +----------+
125 ^
126 | extends
127 |
128+----------------+ +-----+------+
129| Application | | | +-----------------+
130| instantiates | uses | ZrtpQueue | uses | |
131| a ZRTP Session +------+ implements +------+ GNU ZRTP |
132| and provides | |ZrtpCallback| | core |
133|ZrtpUserCallback| | | | implementation |
134+----------------+ +------------+ | (ZRtp et al) |
135 | |
136 +-----------------+
137@endverbatim
138 *
139 * Because ZrtpQueue extends the ccRTP RTP/SRTP implementation
140 * (AVPQueue) all public methods defined by ccRTP are also
141 * available for a ZRTP session. ZrtpQueue overwrites some of the
142 * public methods of ccRTP (AVPQueue) to implement ZRTP specific
143 * code.
144 *
145 * GNU ZRTP provides a <em>SymmetricZRTPSession</em> type to
146 * simplify its use. An application uses this type in the same way
147 * as it would use the normal ccRTP <em>SymmetricRTPSession</em>
148 * type. The following short code snippets show how an application
149 * could instantiate ccRTP and GNU ZRTP sessions. The first
150 * snippet shows how to instantiate a ccRTP session:
151 *
152 * @code
153 * ...
154 * #include <ccrtp/rtp.h>
155 * ...
156 * SymmetricRTPSession tx(pattern.getSsrc(),
157 * InetHostAddress("localhost"));
158 * ...
159 *
160 * @endcode
161 *
162 * The same code as above but using a GNU ZRTP session this time:
163 * @code
164 * ...
165 * #include <libzrtpcpp/zrtpccrtp.h>
166 * ...
167 * SymmetricZRTPSession tx(pattern.getSsrc(),
168 * InetHostAddress("localhost"));
169 * ...
170 *
171 * @endcode
172 *
173 * The only differences are the different include statements and
174 * the different session types.
175 *
176 * The <em>demo</em> folder contains a small example that shows
177 * how to use GNU ZRTP.
178 *
179 * Please refer to the GNU ccRTP documentation for a description
180 * of ccRTP methods and functions. This ZrtpQueue documentation
181 * shows the ZRTP specific extensions and describes overloaded
182 * methods and a possible different behaviour.
183 *
184 * @author Werner Dittmann <Werner.Dittmann@t-online.de>
185 */
186
187class __EXPORT ZrtpQueue : public AVPQueue, ZrtpCallback {
188
189public:
190
191 /**
192 * Initialize the ZrtpQueue.
193 *
194 * Before an application can use ZRTP it has to initialize the
195 * ZRTP implementation. This method initializes the timeout
196 * thread and opens a file that contains ZRTP specific
197 * information such as the applications ZID (ZRTP id) and its
198 * retained shared secrets.
199 *
200 * If one application requires several ZRTP sessions all
201 * sessions use the same timeout thread and use the same ZID
202 * file. Therefore an application does not need to do any
203 * synchronisation regading ZID files or timeouts. This is
204 * managed by the ZRTP implementation.
205 *
206 * The current implementation of ZrtpQueue does not support
207 * different ZID files for one application instance. This
208 * restriction may be removed in later versions.
209 *
210 * The application may specify its own ZID file name. If no
211 * ZID file name is specified it defaults to
212 * <code>$HOME/.GNUccRTP.zid</code> if the <code>HOME</code>
213 * environment variable is set. If it is not set the current
214 * directory is used.
215 *
216 * If the method could set up the timeout thread and open the ZID
217 * file then it enables ZRTP processing and returns.
218 *
219 * @param zidFilename
220 * The name of the ZID file, can be a relative or absolut
221 * filename.
222 *
223 * @param autoEnable
224 * if set to true the method automatically sets enableZrtp to
225 * true. This enables the ZRTP auto-sense mode. Default is true.
226 *
227 * @param config
228 * this parameter points to ZRTP configuration data. If it is
229 * NULL then ZrtpQueue uses a default setting. Default is NULL.
230 *
231 * @return
232 * 1 on success, ZRTP processing enabled, -1 on failure,
233 * ZRTP processing disabled.
234 *
235 */
236 int32_t initialize(const char *zidFilename, bool autoEnable = true,
237 ZrtpConfigure* config = NULL);
238
239 /*
240 * Applications use the following methods to control ZRTP, for example
241 * to enable ZRTP, set flags etc.
242 */
243
244 /**
245 * Enable or disable ZRTP processing.
246 *
247 * Call this method to enable or disable ZRTP processing after
248 * calling <code>initialize()</code>. This can be done before
249 * using a RTP session or at any time during a RTP session.
250 *
251 * Existing SRTP sessions or currently active ZRTP processing will
252 * not be stopped or disconnected.
253 *
254 * If the application enables ZRTP then:
255 * <ul>
256 * <li>ZrtpQueue starts to send ZRTP Hello packets after at least
257 * one RTP packet was sent and received on the associated RTP
258 * session. Thus if an application enables ZRTP and ZrtpQueue
259 * detects traffic on the RTP session then ZrtpQueue automatically
260 * starts the ZRTP protocol. This automatic start is convenient
261 * for applications that negotiate RTP parameters and set up RTP
262 * sessions but the actual RTP traffic starts some time later.
263 * </li>
264 * <li>ZrtpQueue analyses incoming packets to detect ZRTP
265 * messages. If ZRTP was started, either via automatic start (see
266 * above) or explicitly via startZrtp(), then ZrtpQueue
267 * forwards ZRTP packets to the GNU ZRTP core.
268 * </ul>
269 *
270 * @param onOff
271 * @c true to enable ZRTP, @c false to disable ZRTP
272 */
273 void setEnableZrtp(bool onOff);
274
275 /**
276 * Return the state of ZRTP enable state.
277 *
278 * @return @c true if ZRTP processing is enabled, @c false
279 * otherwise.
280 */
281 bool isEnableZrtp();
282
283 /**
284 * Set SAS as verified.
285 *
286 * The application may call this method if the user confirmed
287 * (verfied) the Short Authentication String (SAS) with the peer.
288 *
289 * ZRTP calls ZrtpUserCallback#showSAS after it computed the SAS
290 * and the application registered a user callback class. The
291 * application should display the SAS and provide a mechanism at
292 * the user interface that enables the user to confirm the SAS.
293 *
294 * ZRTP remembers the SAS confirmation status together with the
295 * retained secrets data. If both parties confirmed the SAS then
296 * ZRTP informs the application about this status on the next ZRTP
297 * session.
298 *
299 * For more detailed information regarding SAS please refer to the
300 * ZRTP specification, chapter 8.
301 */
302 void SASVerified();
303
304 /**
305 * Reset the SAS verfied flag for the current user's retained secrets.
306 *
307 */
308 void resetSASVerified();
309
310 /**
311 * To confirm a go clear request.
312 *
313 * Call this method if the user confirmed a go clear (secure mode off).
314 */
315 void goClearOk();
316
317 /**
318 * Request to switch off secure mode.
319 *
320 * Call this method is the user itself wants to switch off secure
321 * mode (go clear). After sending the "go clear" request to the peer
322 * ZRTP immediatly switch off SRTP processing. Every RTP data is sent
323 * in clear after the go clear request.
324 */
325 void requestGoClear();
326
327 /**
328 * Set the auxilliary secret.
329 *
330 * Use this method to set the srtps secret data. Refer to ZRTP
331 * specification, chapter 5.3 ff
332 *
333 * @param data
334 * Points to the auxilliary secret data.
335 * @param length
336 * Length of the auxilliary secrect in bytes
337 */
338 void setAuxSecret(uint8_t* data, int32_t length);
339
340 /**
341 * Set the application's callback class.
342 *
343 * The destructor of ZrtpQueue also destorys the user callback
344 * class if it was set. The application must not delete the
345 * callback object or use/reference the callback object after
346 * ZrtpQueue was destroyed.
347 *
348 * @param ucb
349 * Implementation of the application's ZrtpUserCallback class
350 */
351 void setUserCallback(ZrtpUserCallback* ucb);
352
353 /**
354 * Set the client ID for ZRTP Hello message.
355 *
356 * The GNU ccRTP client may set its id to identify itself in the
357 * ZRTP Hello message. The maximum length is 16 characters. A
358 * shorter id string is possible, it will be filled with blanks. A
359 * longer id string will be truncated to 16 characters. The
360 * standard client id is <code>'GNU ccRTP ZRTP '</code> (without
361 * the quotes).
362 *
363 * Setting the client's id must be done before calling
364 * ZrtpQueue#initialize() or ZrtpQueue#startZrtp() .
365 *
366 * @param id
367 * The client's id string
368 */
369 void setClientId(std::string id);
370
371 /**
372 * Get the ZRTP Hello Hash data.
373 *
374 * Use this method to get the ZRTP Hello Hash data. The method
375 * returns the data as a string containing hex-digits. Refer
376 * to ZRTP specification, chapter 9.1.
377 *
378 * @return
379 * a std:string containing the Hello hash value as hex-digits. The
380 * hello hash is available immediatly after calling
381 * ZrtpQueue#startZrtp. If ZRTP was not started the method returns
382 * an empty string.
383 */
384 std::string getHelloHash();
385
386 /**
387 * Get the peer's ZRTP Hello Hash data.
388 *
389 * Use this method to get the peer's ZRTP Hello Hash data. The method
390 * returns the data as a string containing the ZRTP protocol version and
391 * hex-digits.
392 *
393 * The peer's hello hash is available only after ZRTP received a hello. If
394 * no data is available the function returns an empty string.
395 *
396 * Refer to ZRTP specification, chapter 8.
397 *
398 * @return
399 * a std:string containing the Hello version and the hello hash as hex digits.
400 */
401 std::string getPeerHelloHash();
402
403 /**
404 * Get Multi-stream parameters.
405 *
406 * Use this method to get the Multi-stream that were computed during
407 * the ZRTP handshake. An application may use these parameters to
408 * enable multi-stream processing for an associated SRTP session.
409 *
410 * Refer to chapter 5.4.2 in the ZRTP specification for further details
411 * and restriction how and when to use multi-stream mode.
412 *
413 * @return
414 * a string that contains the multi-stream parameters. The application
415 * must not modify the contents of this string, it is opaque data. The
416 * application may hand over this string to a new ZrtpQueue instance
417 * to enable multi-stream processing for this ZrtpQueue. If ZRTP was
418 * not started or ZRTP is not yet in secure state the method returns an
419 * empty string.
420 *
421 * @see setMultiStrParams()
422 */
423 std::string getMultiStrParams();
424
425 /**
426 * Set Multi-stream parameters.
427 *
428 * Use this method to set the parameters required to enable Multi-stream
429 * processing of ZRTP. The multi-stream parameters must be set before the
430 * application starts the ZRTP protocol engine.
431 *
432 * Refer to chapter 5.4.2 in the ZRTP specification for further details
433 * of multi-stream mode.
434 *
435 * @param parameters
436 * A string that contains the multi-stream parameters that this
437 * new ZrtpQueue instanace shall use.
438 *
439 * @see getMultiStrParams()
440 */
441 void setMultiStrParams(std::string parameters);
442
443 /**
444 * Check if this ZRTP use Multi-stream.
445 *
446 * Use this method to check if this ZRTP instance uses multi-stream. Even
447 * if the application provided multi-stram parameters it may happen that
448 * full DH mode was used. Refer to chapters 5.2 and 5.4.2 in the ZRTP #
449 * when this may happen.
450 *
451 * @return
452 * True if multi-stream is used, false otherwise.
453 */
454 bool isMultiStream();
455
456 /**
457 * Check if the other ZRTP client supports Multi-stream.
458 *
459 * Use this method to check if the other ZRTP client supports
460 * Multi-stream mode.
461 *
462 * @return
463 * True if multi-stream is available, false otherwise.
464 */
465 bool isMultiStreamAvailable();
466
467 /**
468 * Accept a PBX enrollment request.
469 *
470 * If a PBX service asks to enroll the MiTM key and the user accepts this
471 * requtes, for example by pressing an OK button, the client application
472 * shall call this method and set the parameter <code>accepted</code> to
473 * true. If the user does not accept the request set the parameter to
474 * false.
475 *
476 * @param accepted
477 * True if the enrollment request is accepted, false otherwise.
478 */
479 void acceptEnrollment(bool accepted);
480
481 /**
482 * Get the commited SAS rendering algorithm for this ZRTP session.
483 *
484 * @return the commited SAS rendering algorithm
485 */
486 std::string getSasType();
487
488 /**
489 * Get the computed SAS hash for this ZRTP session.
490 *
491 * A PBX ZRTP back-to-Back function uses this function to get the SAS
492 * hash of an enrolled client to construct the SAS relay packet for
493 * the other client.
494 *
495 * @return a refernce to the byte array that contains the full
496 * SAS hash.
497 */
498 uint8_t* getSasHash();
499
500 /**
501 * Send the SAS relay packet.
502 *
503 * The method creates and sends a SAS relay packet according to the ZRTP
504 * specifications. Usually only a MitM capable user agent (PBX) uses this
505 * function.
506 *
507 * @param sh the full SAS hash value
508 * @param render the SAS rendering algorithm
509 */
510 bool sendSASRelayPacket(uint8_t* sh, std::string render);
511
512 /**
513 * Check the state of the MitM mode flag.
514 *
515 * If true then this ZRTP session acts as MitM, usually enabled by a PBX
516 * client (user agent)
517 *
518 * @return state of mitmMode
519 */
520 bool isMitmMode();
521
522 /**
523 * Set the state of the MitM mode flag.
524 *
525 * If MitM mode is set to true this ZRTP session acts as MitM, usually
526 * enabled by a PBX client (user agent).
527 *
528 * @param mitmMode defines the new state of the mitmMode flag
529 */
530 void setMitmMode(bool mitmMode);
531
532 /**
533 * Enable or disable paranoid mode.
534 *
535 * The Paranoid mode controls the behaviour and handling of the SAS verify flag. If
536 * Panaoid mode is set to flase then ZRtp applies the normal handling. If Paranoid
537 * mode is set to true then the handling is:
538 *
539 * <ul>
540 * <li> always set the SAS verify flag to <code>false</code> at srtpSecretsOn() callback. The
541 * user interface (UI) must show <b>SAS not verified</b>. See implementation note below.</li>
542 * <li> don't set the SAS verify flag in the <code>Confirm</code> packets, thus forcing the other
543 * peer to report <b>SAS not verified</b>.</li>
544 * <li> ignore the <code>SASVerified()</code> function, thus do not set the SAS verified flag
545 * in the ZRTP cache. </li>
546 * <li> Disable the <em>Trusted PBX MitM</em> feature. Just send the <code>SASRelay</code> packet
547 * but do not process the relayed data. This protects the user from a malicious
548 * "trusted PBX".</li>
549 * </ul>
550 * ZRtp performs alls other steps during the ZRTP negotiations as usual, in particular it
551 * computes, compares, uses, and stores the retained secrets. This avoids unnecessary warning
552 * messages. The user may enable or disable the Paranoid mode on a call-by-call basis without
553 * breaking the key continuity data.
554 *
555 * <b>Implementation note:</b><br/>
556 * An application shall <b>always display the SAS if the SAS verify flag is <code>false</code></b>.
557 * The application shall remind the user to compare the SAS code, for example using larger fonts,
558 * different colours and other display features.
559 */
560 void setParanoidMode(bool yesNo);
561
562 /**
563 * Check status of paranoid mode.
564 *
565 * @return
566 * Returns true if paranoid mode is enabled.
567 */
568 bool isParanoidMode();
569
570 /**
571 * Check the state of the enrollment mode.
572 *
573 * If true then we will set the enrollment flag (E) in the confirm
574 * packets and performs the enrollment actions. A MitM (PBX) enrollment service sets this flagstarted this ZRTP
575 * session. Can be set to true only if mitmMode is also true.
576 * @return status of the enrollmentMode flag.
577 */
578 bool isEnrollmentMode();
579
580 /**
581 * Check the state of the enrollment mode.
582 *
583 * If true then we will set the enrollment flag (E) in the confirm
584 * packets and perform the enrollment actions. A MitM (PBX) enrollment
585 * service must sets this mode to true.
586 *
587 * Can be set to true only if mitmMode is also true.
588 *
589 * @param enrollmentMode defines the new state of the enrollmentMode flag
590 */
591 void setEnrollmentMode(bool enrollmentMode);
592
593 /**
594 * Backwards compatible api fix...
595 */
596 inline void setPBXEnrollment(bool enrollmentMode)
597 {setMitmMode(enrollmentMode); setEnrollmentMode(enrollmentMode);}
598
599 /**
600 * Check if a peer's cache entry has a vaild MitM key.
601 *
602 * If true then the other peer ha a valid MtiM key, i.e. the peer has performed
603 * the enrollment procedure. A PBX ZRTP Back-2-Back application can use this function
604 * to check which of the peers is enrolled.
605 *
606 * @return True if the other peer has a valid Mitm key (is enrolled).
607 */
608 bool isPeerEnrolled();
609
610 /**
611 * Set the state of the SAS signature mode flag.
612 *
613 * If SAS signature mode is set to true this ZRTP session support SAS signature
614 * callbacks and signature transfer between clients.
615 *
616 * @param sasSignMode defines the new state of the sasSignMode flag
617 */
618 void setSignSas(bool sasSignMode);
619
620 /**
621 * Set signature data
622 *
623 * This functions stores signature data and transmitts it during ZRTP
624 * processing to the other party as part of the Confirm packets. Refer to
625 * chapters 6.7 and 8.2 in the ZRTP specification.
626 *
627 * @param data
628 * The signature data including the signature type block. The method
629 * copies this data into the Confirm packet at signature type block.
630 * @param length
631 * The length of the signature data in bytes. This length must be
632 * multiple of 4.
633 * @return
634 * True if the method stored the data, false otherwise.
635 */
636 bool setSignatureData(uint8* data, int32 length);
637
638 /**
639 * Get signature data
640 *
641 * This functions returns signature data that was receivied during ZRTP
642 * processing. Refer to chapters 6.7 and 8.2.
643 *
644 * @return
645 * Pointer to signature data. This is a pointer to volatile data that is
646 * only valid during the checkSASSignature() callback. The application
647 * shall copy the data if necessary.
648 */
649 const uint8* getSignatureData();
650
651 /**
652 * Get length of signature data
653 *
654 * This functions returns the length of signature data that was receivied
655 * during ZRTP processing. Refer to chapters 6.7 and 8.2.
656 *
657 * @return
658 * Length in bytes of the received signature data. The method returns
659 * zero if no signature data avilable.
660 */
661 int32 getSignatureLength();
662
663 /**
664 * Put data into the RTP output queue.
665 *
666 * This is used to create a data packet in the send queue.
667 * Sometimes a "NULL" or empty packet will be used instead, and
668 * these are known as "silent" packets. "Silent" packets are
669 * used simply to "push" the scheduler along more accurately
670 * by giving the appearence that a next packet is waiting to
671 * be sent and to provide a valid timestamp for that packet.
672 *
673 * This method overrides the same method in OutgoingDataQueue class.
674 * During ZRTP processing it may be necessary to control the
675 * flow of outgoing RTP payload packets (GoClear processing).
676 *
677 * @param stamp Timestamp for expected send time of packet.
678 * @param data Value or NULL if special "silent" packet.
679 * @param len May be 0 to indicate a default by payload type.
680 **/
681 void
682 putData(uint32 stamp, const unsigned char* data = NULL, size_t len = 0);
683
684 /**
685 * Immediatly send a data packet.
686 *
687 * This is used to create a data packet and send it immediately.
688 * Sometimes a "NULL" or empty packet will be used instead, and
689 * these are known as "silent" packets. "Silent" packets are
690 * used simply to "push" the scheduler along more accurately
691 * by giving the appearence that a next packet is waiting to
692 * be sent and to provide a valid timestamp for that packet.
693 *
694 * This method overrides the same method in OutgoingDataQueue
695 * class. During ZRTP processing it may be necessary to
696 * control the flow of outgoing RTP payload packets (GoClear
697 * processing).
698 *
699 * @param stamp Timestamp immediate send time of packet.
700 * @param data Value or NULL if special "silent" packet.
701 * @param len May be 0 to indicate a default by payload type.
702 **/
703 void
704 sendImmediate(uint32 stamp, const unsigned char* data = NULL, size_t len = 0);
705
706 /**
707 * Starts the ZRTP protocol engine.
708 *
709 * Applications may call this method to immediatly start the ZRTP protocol
710 * engine any time after initializing ZRTP and setting optinal parameters,
711 * for example client id or multi-stream parameters.
712 *
713 * If the application does not call this method but sucessfully initialized
714 * the ZRTP engine using <code>initialize()</code> then ZRTP also starts
715 * after the application sent and received RTP packets. An application can
716 * disable this automatic, delayed start of the ZRTP engine using
717 * <code>setEnableZrtp(false)</code> before sending or receiving RTP
718 * packets.
719 *
720 */
721 void startZrtp();
722
723 /**
724 * Stops the ZRTP protocol engine.
725 *
726 * Applications call this method to stop the ZRTP protocol
727 * engine.
728 *
729 */
730 void stopZrtp();
731
732 /**
733 * Get other party's ZID (ZRTP Identifier) data
734 *
735 * This functions returns the other party's ZID that was receivied
736 * during ZRTP processing.
737 *
738 * The ZID data can be retrieved after ZRTP receive the first Hello
739 * packet from the other party. The application may call this method
740 * for example during SAS processing in showSAS(...) user callback
741 * method.
742 *
743 * @param data
744 * Pointer to a data buffer. This buffer must have a size of
745 * at least 12 bytes (96 bit) (ZRTP Identifier, see chap. 4.9)
746 * @return
747 * Number of bytes copied into the data buffer - must be equivalent
748 * to 96 bit, usually 12 bytes.
749 */
750 int32 getPeerZid(uint8* data);
751
752protected:
753 friend class TimeoutProvider<std::string, ost::ZrtpQueue*>;
754
755 /**
756 * A hook that gets called if the decoding of an incoming SRTP
757 * was erroneous
758 *
759 * @param pkt
760 * The SRTP packet with error.
761 * @param errorCode
762 * The error code: -1 - SRTP authentication failure, -2 - replay
763 * check failed
764 * @return
765 * True: put the packet in incoming queue for further processing
766 * by the applications; false: dismiss packet. The default
767 * implementation returns false.
768 */
769 virtual bool
770 onSRTPPacketError(IncomingRTPPkt& pkt, int32 errorCode);
771
772 /**
773 * Handle timeout event forwarded by the TimeoutProvider.
774 *
775 * Just call the ZRTP engine for further processing.
776 */
777 void handleTimeout(const std::string &c);
778
779 /**
780 * This function is used by the service thread to process
781 * the next incoming packet and place it in the receive list.
782 *
783 * This class overloads the function of IncomingDataQueue
784 * implementation.
785 *
786 * @return number of payload bytes received, <0 if error.
787 */
788 virtual size_t takeInDataPacket();
789
790 /*
791 * The following methods implement the GNU ZRTP callback interface.
792 * For detailed documentation refer to file ZrtpCallback.h
793 */
794 int32_t sendDataZRTP(const unsigned char* data, int32_t length);
795
796 int32_t activateTimer(int32_t time);
797
798 int32_t cancelTimer();
799
800 void sendInfo(GnuZrtpCodes::MessageSeverity severity, int32_t subCode);
801
802 bool srtpSecretsReady(SrtpSecret_t* secrets, EnableSecurity part);
803
804 void srtpSecretsOff(EnableSecurity part);
805
806 void srtpSecretsOn(std::string c, std::string s, bool verified);
807
808 void handleGoClear();
809
810 void zrtpNegotiationFailed(GnuZrtpCodes::MessageSeverity severity, int32_t subCode);
811
812 void zrtpNotSuppOther();
813
814 void synchEnter();
815
816 void synchLeave();
817
818 void zrtpAskEnrollment(GnuZrtpCodes::InfoEnrollment info);
819
820 void zrtpInformEnrollment(GnuZrtpCodes::InfoEnrollment info);
821
822 void signSAS(uint8_t* sasHash);
823
824 bool checkSASSignature(uint8_t* sasHash);
825
826 /*
827 * End of ZrtpCallback functions.
828 */
829
830 ZrtpQueue(uint32 size = RTPDataQueue::defaultMembersHashSize,
831 RTPApplication& app = defaultApplication());
832
833 /**
834 * Local SSRC is given instead of computed by the queue.
835 */
836 ZrtpQueue(uint32 ssrc, uint32 size =
837 RTPDataQueue::defaultMembersHashSize,
838 RTPApplication& app = defaultApplication());
839
840 virtual ~ZrtpQueue();
841
842private:
843 void init();
844 size_t rtpDataPacket(unsigned char* packet, int32 rtn,
845 InetHostAddress network_address,
846 tpport_t transport_port);
847
848 ZRtp *zrtpEngine;
849 ZrtpUserCallback* zrtpUserCallback;
850
851 std::string clientIdString;
852
853 bool enableZrtp;
854
855 int32 secureParts;
856
857 int16 senderZrtpSeqNo;
858 ost::Mutex synchLock; // Mutex for ZRTP (used by ZrtpStateClass)
859 uint32 peerSSRC;
860 bool started;
861 bool mitmMode;
862 bool signSas;
863 bool enableParanoidMode;
864};
865
866class IncomingZRTPPkt : public IncomingRTPPkt {
867
868public:
869 /**
870 * Build a ZRTP packet object from a data buffer.
871 *
872 * @param block pointer to the buffer the whole packet is stored in.
873 * @param len length of the whole packet, expressed in octets.
874 *
875 **/
876
877 IncomingZRTPPkt(const unsigned char* block, size_t len);
878
879 ~IncomingZRTPPkt()
880 { }
881
882 uint32
883 getZrtpMagic() const;
884
885 uint32
886 getSSRC() const;
887};
888
889class OutgoingZRTPPkt : public OutgoingRTPPkt {
890
891public:
892 /**
893 * Construct a new ZRTP packet to be sent.
894 *
895 * A new copy in memory (holding all this components
896 * along with the fixed header) is created.
897 *
898 * @param hdrext whole header extension.
899 * @param hdrextlen size of whole header extension, in octets.
900 **/
901 OutgoingZRTPPkt(const unsigned char* const hdrext, uint32 hdrextlen);
902 ~OutgoingZRTPPkt()
903 { }
904};
905
906END_NAMESPACE
907
908#endif
909
910/** EMACS **
911 * Local variables:
912 * mode: c++
913 * c-default-style: ellemtel
914 * c-basic-offset: 4
915 * End:
916 */
917