ccRTP 2.1.2
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ZrtpCWrapper.h
Go to the documentation of this file.
1 /*
2  This file defines the GNU ZRTP C-to-C++ wrapper.
3  Copyright (C) 2010 Werner Dittmann
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18 */
19 
20 #ifndef ZRTPCWRAPPER_H
21 #define ZRTPCWRAPPER_H
22 
38 #include <stdint.h>
39 
55 /*
56  * Keep the following defines in sync with Role enumeration in ZrtpCallback.h
57  */
58 #define Responder 1
59 #define Initiator 2
61 #define CRC_SIZE 4
62 #define ZRTP_MAGIC 0x5a525450
63 #define MAX_ZRTP_SIZE 3072
65 /*
66  * IMPORTANT: keep the following enums in synch with ZrtpCodes. We copy them here
67  * to avoid any C++ header includes and defines. The protocol states are located
68  * ZrtpStateClass.h .
69  */
70 
104  zrtp_Info = 1,
108 };
109 
125 };
126 
139 };
140 
153 };
154 
184  zrtp_IgnorePacket = 0x7fffffff
185 };
186 
195 };
196 
197 /* The ZRTP protocol states */
213 };
214 
216 typedef enum {
217  zrtp_Aes = 1,
222 
231 typedef struct c_srtpSecrets
232 {
234  const uint8_t* keyInitiator;
235  int32_t initKeyLen;
236  const uint8_t* saltInitiator;
237  int32_t initSaltLen;
238  const uint8_t* keyResponder;
239  int32_t respKeyLen;
240  const uint8_t* saltResponder;
241  int32_t respSaltLen;
243  int32_t srtpAuthTagLen;
244  char* sas;
245  int32_t role;
247 
248 /*
249  * Keep the following defines in sync with enum EnableSecurity in ZrtpCallback.h
250  */
251 #define ForReceiver 1
252 #define ForSender 2
254 #ifdef __cplusplus
255 #pragma GCC visibility push(default)
256 extern "C"
257 {
258 #endif
259 
260  typedef struct ZRtp ZRtp;
262  typedef struct ZrtpConfigure ZrtpConfigure;
263 
264 
265  typedef struct zrtpContext
266  {
270  void* userData;
271  } ZrtpContext;
272 
294  typedef struct zrtp_Callbacks
295  {
311  int32_t (*zrtp_sendDataZRTP) (ZrtpContext* ctx, const uint8_t* data, int32_t length ) ;
312 
323  int32_t (*zrtp_activateTimer) (ZrtpContext* ctx, int32_t time ) ;
324 
333  int32_t (*zrtp_cancelTimer)(ZrtpContext* ctx) ;
334 
351  void (*zrtp_sendInfo) (ZrtpContext* ctx, int32_t severity, int32_t subCode ) ;
352 
384  int32_t (*zrtp_srtpSecretsReady) (ZrtpContext* ctx, C_SrtpSecret_t* secrets, int32_t part ) ;
385 
394  void (*zrtp_srtpSecretsOff) (ZrtpContext* ctx, int32_t part ) ;
395 
416  void (*zrtp_rtpSecretsOn) (ZrtpContext* ctx, char* c, char* s, int32_t verified ) ;
417 
431 
446  void (*zrtp_zrtpNegotiationFailed) (ZrtpContext* ctx, int32_t severity, int32_t subCode ) ;
447 
458 
471  void (*zrtp_synchEnter)(ZrtpContext* ctx) ;
472 
479  void (*zrtp_synchLeave)(ZrtpContext* ctx) ;
480 
495  void (*zrtp_zrtpAskEnrollment) (ZrtpContext* ctx, int32_t info) ;
496 
511  void (*zrtp_zrtpInformEnrollment) (ZrtpContext* ctx, int32_t info ) ;
512 
532  void (*zrtp_signSAS)(ZrtpContext* ctx, uint8_t* sas) ;
533 
558  int32_t (*zrtp_checkSASSignature) (ZrtpContext* ctx, uint8_t* sas ) ;
559  } zrtp_Callbacks;
560 
569 
605  zrtp_Callbacks *cb,
606  const char* id,
607  const char* zidFilename,
608  void* userData,
609  int32_t mitmMode);
610 
615 
629  int32_t zrtp_CheckCksum(uint8_t* buffer, uint16_t length, uint32_t crc);
630 
641  uint32_t zrtp_GenerateCksum(uint8_t* buffer, uint16_t length);
642 
650  uint32_t zrtp_EndCksum(uint32_t crc);
651 
666 
677 
696  void zrtp_processZrtpMessage(ZrtpContext* zrtpContext, uint8_t *extHeader, uint32_t peerSSRC);
697 
711 
712  /*
713  * Check for and handle GoClear ZRTP packet header.
714  *
715  * This method checks if this is a GoClear packet. If not, just return
716  * false. Otherwise handle it according to the specification.
717  *
718  * @param zrtpContext
719  * Pointer to the opaque ZrtpContext structure.
720  * @param extHeader
721  * A pointer to the first byte of the extension header. Refer to
722  * RFC3550.
723  * @return
724  * False if not a GoClear, true otherwise.
725  *
726  int32_t zrtp_handleGoClear(ZrtpContext* zrtpContext, uint8_t *extHeader);
727  */
728 
742  void zrtp_setAuxSecret(ZrtpContext* zrtpContext, uint8_t* data, int32_t length);
743 
757  int32_t zrtp_inState(ZrtpContext* zrtpContext, int32_t state);
758 
769 
777 
798 
815 
839  char* zrtp_getMultiStrParams(ZrtpContext* zrtpContext, int32_t *length);
840 
860  void zrtp_setMultiStrParams(ZrtpContext* zrtpContext, char* parameters, int32_t length);
861 
874 
887 
902  void zrtp_acceptEnrollment(ZrtpContext* zrtpContext, int32_t accepted);
903 
916 
930  void zrtp_setEnrollmentMode(ZrtpContext* zrtpContext, int32_t enrollmentMode);
931 
942 
955  int32_t zrtp_sendSASRelayPacket(ZrtpContext* zrtpContext, uint8_t* sh, char* render);
956 
965 
979 
1001  int32_t zrtp_setSignatureData(ZrtpContext* zrtpContext, uint8_t* data, int32_t length);
1002 
1018 
1032 
1047 
1068  int32_t zrtp_getPeerZid(ZrtpContext* zrtpContext, uint8_t* data);
1069 
1070 
1075  /* Keep in synch with enumeration in ZrtpConfigure.h */
1076 
1077  typedef enum zrtp_AlgoTypes {
1079  } Zrtp_AlgoTypes;
1080 
1106 
1121 
1131  void zrtp_freeAlgorithmNames(char** names);
1132 
1149 
1166 
1176 
1194  int32_t zrtp_addAlgo(ZrtpContext* zrtpContext, Zrtp_AlgoTypes algoType, const char* algo);
1195 
1214  int32_t zrtp_addAlgoAt(ZrtpContext* zrtpContext, Zrtp_AlgoTypes algoType, const char* algo, int32_t index);
1215 
1237  int32_t zrtp_removeAlgo(ZrtpContext* zrtpContext, Zrtp_AlgoTypes algoType, const char* algo);
1238 
1251 
1267  const char* zrtp_getAlgoAt(ZrtpContext* zrtpContext, Zrtp_AlgoTypes algoType, int32_t index);
1268 
1283  int32_t zrtp_containsAlgo(ZrtpContext* zrtpContext, Zrtp_AlgoTypes algoType, const char* algo);
1284 
1296  void zrtp_setTrustedMitM(ZrtpContext* zrtpContext, int32_t yesNo);
1297 
1307 
1319  void zrtp_setSasSignature(ZrtpContext* zrtpContext, int32_t yesNo);
1320 
1330 
1331 #ifdef __cplusplus
1332 }
1333 #pragma GCC visibility pop
1334 #endif
1335 
1339 #endif
ZRTP configuration data.
void zrtp_conf2AckSecure(ZrtpContext *zrtpContext)
Emulate a Conf2Ack packet.
int32_t zrtp_addAlgo(ZrtpContext *zrtpContext, Zrtp_AlgoTypes algoType, const char *algo)
Add an algorithm to configuration data.
zrtp_SevereCodes
Sub-codes for Severe.
Definition: ZrtpCWrapper.h:144
Enrollment process failed, no PBX secret available.
Definition: ZrtpCWrapper.h:193
void(* zrtp_srtpSecretsOff)(ZrtpContext *ctx, int32_t part)
Switch off the security for the defined part.
Definition: ZrtpCWrapper.h:394
const uint8_t * saltInitiator
Definition: ZrtpCWrapper.h:236
void zrtp_setSasSignature(ZrtpContext *zrtpContext, int32_t yesNo)
Enables or disables SAS signature processing.
int32_t zrtp_inState(ZrtpContext *zrtpContext, int32_t state)
Check current state of the ZRTP state engine.
int32_t initKeyLen
Definition: ZrtpCWrapper.h:235
const char * zrtp_getSasType(ZrtpContext *zrtpContext)
Get the commited SAS rendering algorithm for this ZRTP session.
void(* zrtp_zrtpNotSuppOther)(ZrtpContext *ctx)
ZRTP calls this method if the other side does not support ZRTP.
Definition: ZrtpCWrapper.h:457
char * zrtp_getHelloHash(ZrtpContext *zrtpContext)
Get the ZRTP Hello Hash data.
void zrtp_processTimeout(ZrtpContext *zrtpContext)
Process a timeout event.
int32_t zrtp_CheckCksum(uint8_t *buffer, uint16_t length, uint32_t crc)
Computes the ZRTP checksum over a received ZRTP packet buffer and compares the result with received c...
void zrtp_stopZrtpEngine(ZrtpContext *zrtpContext)
Stop ZRTP security.
void zrtp_setMandatoryOnly(ZrtpContext *zrtpContext)
Convenience function that sets the mandatory algorithms only.
int32_t zrtp_isMultiStream(ZrtpContext *zrtpContext)
Check if this ZRTP session is a Multi-stream session.
int32_t initSaltLen
Definition: ZrtpCWrapper.h:237
const uint8_t * saltResponder
Definition: ZrtpCWrapper.h:240
struct c_srtpSecrets C_SrtpSecret_t
This structure contains pointers to the SRTP secrets and the role info.
Enrollment process for this PBX was ok.
Definition: ZrtpCWrapper.h:194
zrtp_ZrtpErrorCodes
Error codes according to the ZRTP specification chapter 6.9.
Definition: ZrtpCWrapper.h:166
Aks user to confirm or deny an Enrollemnt request.
Definition: ZrtpCWrapper.h:191
void * userData
Definition: ZrtpCWrapper.h:270
int32_t zrtp_getSignatureLength(ZrtpContext *zrtpContext)
Get length of signature data.
int32_t zrtp_getNumConfiguredAlgos(ZrtpContext *zrtpContext, Zrtp_AlgoTypes algoType)
Returns the number of configured algorithms.
void zrtp_initializeZrtpEngine(ZrtpContext *zrtpContext, zrtp_Callbacks *cb, const char *id, const char *zidFilename, void *userData, int32_t mitmMode)
Initialize the ZRTP protocol engine.
void(* zrtp_zrtpInformEnrollment)(ZrtpContext *ctx, int32_t info)
Inform about PBX enrollment result.
Definition: ZrtpCWrapper.h:511
const uint8_t * zrtp_getSignatureData(ZrtpContext *zrtpContext)
Get signature data.
char * zrtp_getPeerHelloHash(ZrtpContext *zrtpContext)
Get the peer's ZRTP Hello Hash data.
int32_t zrtp_removeAlgo(ZrtpContext *zrtpContext, Zrtp_AlgoTypes algoType, const char *algo)
Remove a algorithm from configuration data.
zrtp_AlgoTypes
This enumerations list all configurable algorithm types.
This structure contains pointers to the SRTP secrets and the role info.
Definition: ZrtpCWrapper.h:231
int32_t(* zrtp_cancelTimer)(ZrtpContext *ctx)
Cancel the active timer.
Definition: ZrtpCWrapper.h:333
User did not confirm the PBX enrollement.
Definition: ZrtpCWrapper.h:192
int32_t respKeyLen
Definition: ZrtpCWrapper.h:239
int32_t zrtp_getPeerZid(ZrtpContext *zrtpContext, uint8_t *data)
Get other party's ZID (ZRTP Identifier) data.
ZrtpCallbackWrapper * zrtpCallback
Definition: ZrtpCWrapper.h:268
enum zrtp_AlgoTypes Zrtp_AlgoTypes
This enumerations list all configurable algorithm types.
const uint8_t * keyResponder
Definition: ZrtpCWrapper.h:238
void(* zrtp_signSAS)(ZrtpContext *ctx, uint8_t *sas)
Request a SAS signature.
Definition: ZrtpCWrapper.h:532
uint32_t zrtp_GenerateCksum(uint8_t *buffer, uint16_t length)
Computes the ZRTP checksum over a newly created ZRTP packet buffer.
void(* zrtp_sendInfo)(ZrtpContext *ctx, int32_t severity, int32_t subCode)
Send information messages to the hosting environment.
Definition: ZrtpCWrapper.h:351
int32_t(* zrtp_srtpSecretsReady)(ZrtpContext *ctx, C_SrtpSecret_t *secrets, int32_t part)
SRTP crypto data ready for the sender or receiver.
Definition: ZrtpCWrapper.h:384
zrtp_SrtpAlgorithms symEncAlgorithm
Definition: ZrtpCWrapper.h:233
void zrtp_setMultiStrParams(ZrtpContext *zrtpContext, char *parameters, int32_t length)
Set Multi-stream parameters.
void zrtp_processZrtpMessage(ZrtpContext *zrtpContext, uint8_t *extHeader, uint32_t peerSSRC)
Process RTP extension header.
uint8_t * zrtp_getSasHash(ZrtpContext *zrtpContext)
Get the computed SAS hash for this ZRTP session.
void zrtp_SASVerified(ZrtpContext *zrtpContext)
Set SAS as verified.
ZrtpContext * zrtp_CreateWrapper()
Create the GNU ZRTP C wrapper.
void zrtp_setTrustedMitM(ZrtpContext *zrtpContext, int32_t yesNo)
Enables or disables trusted MitM processing.
int32_t isPeerEnrolled(ZrtpContext *zrtpContext)
Check if a peer's cache entry has a vaild MitM key.
void zrtp_setAuxSecret(ZrtpContext *zrtpContext, uint8_t *data, int32_t length)
Set the auxilliary secret.
void zrtp_startZrtpEngine(ZrtpContext *zrtpContext)
Kick off the ZRTP protocol engine.
void(* zrtp_rtpSecretsOn)(ZrtpContext *ctx, char *c, char *s, int32_t verified)
Switch on the security.
Definition: ZrtpCWrapper.h:416
int32_t zrtp_isMultiStreamAvailable(ZrtpContext *zrtpContext)
Check if the other ZRTP client supports Multi-stream.
void zrtp_freeAlgorithmNames(char **names)
Free storage used to store the algorithm names.
void zrtp_setStandardConfig(ZrtpContext *zrtpContext)
Convenience function that sets a pre-defined standard configuration.
uint32_t zrtp_EndCksum(uint32_t crc)
Prepares the ZRTP checksum for appending to ZRTP packet.
void zrtp_resetSASVerified(ZrtpContext *zrtpContext)
Reset the SAS verfied flag for the current active user's retained secrets.
int32_t zrtp_isEnrollmentMode(ZrtpContext *zrtpContext)
Check the state of the enrollment mode.
zrtp_SrtpAlgorithms
Definition: ZrtpCWrapper.h:216
int32_t srtpAuthTagLen
Definition: ZrtpCWrapper.h:243
void zrtp_DestroyWrapper(ZrtpContext *zrtpContext)
Destroy the ZRTP wrapper and its underlying objects.
struct ZRtp ZRtp
Definition: ZrtpCWrapper.h:260
zrtp_InfoEnrollment
Information codes for the Enrollment user callbacks.
Definition: ZrtpCWrapper.h:190
int32_t zrtp_isTrustedMitM(ZrtpContext *zrtpContext)
Check status of trusted MitM processing.
void(* zrtp_zrtpNegotiationFailed)(ZrtpContext *ctx, int32_t severity, int32_t subCode)
Handle ZRTP negotiation failed.
Definition: ZrtpCWrapper.h:446
void zrtp_confClear(ZrtpContext *zrtpContext)
Clear all configuration data.
struct zrtp_Callbacks zrtp_Callbacks
This structure defines the callback functions required by GNU ZRTP.
void zrtp_setEnrollmentMode(ZrtpContext *zrtpContext, int32_t enrollmentMode)
Check the state of the enrollment mode.
zrtp_SrtpAlgorithms authAlgorithm
Definition: ZrtpCWrapper.h:242
zrtp_WarningCodes
Sub-codes for Warning.
Definition: ZrtpCWrapper.h:130
int32_t respSaltLen
Definition: ZrtpCWrapper.h:241
int32_t(* zrtp_checkSASSignature)(ZrtpContext *ctx, uint8_t *sas)
ZRTPQueue calls this method to request a SAS signature check.
Definition: ZrtpCWrapper.h:558
void(* zrtp_handleGoClear)(ZrtpContext *ctx)
This method handles GoClear requests.
Definition: ZrtpCWrapper.h:430
ZRtp * zrtpEngine
Definition: ZrtpCWrapper.h:267
void zrtp_acceptEnrollment(ZrtpContext *zrtpContext, int32_t accepted)
Accept a PBX enrollment request.
struct zrtpContext ZrtpContext
int32_t zrtp_setSignatureData(ZrtpContext *zrtpContext, uint8_t *data, int32_t length)
Set signature data.
int32_t zrtp_isSasSignature(ZrtpContext *zrtpContext)
Check status of SAS signature processing.
This structure defines the callback functions required by GNU ZRTP.
Definition: ZrtpCWrapper.h:294
int32_t(* zrtp_activateTimer)(ZrtpContext *ctx, int32_t time)
Activate timer.
Definition: ZrtpCWrapper.h:323
void(* zrtp_zrtpAskEnrollment)(ZrtpContext *ctx, int32_t info)
Inform about a PBX enrollment request.
Definition: ZrtpCWrapper.h:495
struct ZrtpCallbackWrapper ZrtpCallbackWrapper
Definition: ZrtpCWrapper.h:261
void(* zrtp_synchLeave)(ZrtpContext *ctx)
Leave synchronization mutex.
Definition: ZrtpCWrapper.h:479
void(* zrtp_synchEnter)(ZrtpContext *ctx)
Enter synchronization mutex.
Definition: ZrtpCWrapper.h:471
int32_t zrtp_InitializeConfig(ZrtpContext *zrtpContext)
Initialize the GNU ZRTP Configure data.
ZrtpConfigure * configure
Definition: ZrtpCWrapper.h:269
zrtpStates
Definition: ZrtpCWrapper.h:198
zrtp_InfoCodes
Sub-codes for Info.
Definition: ZrtpCWrapper.h:113
const uint8_t * keyInitiator
Definition: ZrtpCWrapper.h:234
zrtp_MessageSeverity
This enum defines the information message severity.
Definition: ZrtpCWrapper.h:103
char * zrtp_getMultiStrParams(ZrtpContext *zrtpContext, int32_t *length)
Get Multi-stream parameters.
char ** zrtp_getAlgorithmNames(ZrtpContext *zrtpContext, Zrtp_AlgoTypes type)
Get names of all available algorithmes of a given algorithm type.
const char * zrtp_getAlgoAt(ZrtpContext *zrtpContext, Zrtp_AlgoTypes algoType, int32_t index)
Returns the identifier of the algorithm at index.
int32_t zrtp_sendSASRelayPacket(ZrtpContext *zrtpContext, uint8_t *sh, char *render)
Send the SAS relay packet.
int32_t zrtp_addAlgoAt(ZrtpContext *zrtpContext, Zrtp_AlgoTypes algoType, const char *algo, int32_t index)
Add an algorithm to configuration data at given index.
int32_t(* zrtp_sendDataZRTP)(ZrtpContext *ctx, const uint8_t *data, int32_t length)
Send a ZRTP packet via RTP.
Definition: ZrtpCWrapper.h:311
int32_t zrtp_containsAlgo(ZrtpContext *zrtpContext, Zrtp_AlgoTypes algoType, const char *algo)
Checks if the configuration data of the algorihm type already contains a specific algorithms...