| ZrtpCWrapper.h | | ZrtpCWrapper.h | |
| | | | |
| skipping to change at line 23 | | skipping to change at line 23 | |
| GNU General Public License for more details. | | GNU General Public License for more details. | |
| | | | |
| You should have received a copy of the GNU General Public License | | You should have received a copy of the GNU General Public License | |
| along with this program. If not, see <http://www.gnu.org/licenses/>. | | along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| | | | |
| */ | | */ | |
| | | | |
| #ifndef ZRTPCWRAPPER_H | | #ifndef ZRTPCWRAPPER_H | |
| #define ZRTPCWRAPPER_H | | #define ZRTPCWRAPPER_H | |
| | | | |
|
| | | /** | |
| | | * | |
| | | * @file ZrtpCWrapper.h | |
| | | * @brief The GNU ZRTP C-to-C++ wrapper. | |
| | | * | |
| | | * To avoid any include of C++ header files some structure, defines, and | |
| | | * enumerations are repeated in this file. Refer to the inline comments if | |
| | | * you modify the file. | |
| | | * | |
| | | * @ingroup GNU_ZRTP | |
| | | * @{ | |
| | | * | |
| | | * @see ZRtp | |
| | | */ | |
| | | | |
| #include <stdint.h> | | #include <stdint.h> | |
| | | | |
| /** | | /** | |
|
| * This enum defines which role a ZRTP peer has. | | * Defines to specify the role a ZRTP peer has. | |
| * | | * | |
| * According to the ZRTP specification the role determines which keys to | | * According to the ZRTP specification the role determines which keys to | |
| * use to encrypt or decrypt SRTP data. | | * use to encrypt or decrypt SRTP data. | |
| * | | * | |
| * <ul> | | * <ul> | |
| * <li> The Initiator encrypts SRTP data using the <em>keyInitiator</em> an
d the | | * <li> The Initiator encrypts SRTP data using the <em>keyInitiator</em> an
d the | |
| * <em>saltInitiator</em> data, the Responder uses these data to decry
pt. | | * <em>saltInitiator</em> data, the Responder uses these data to decry
pt. | |
| * </li> | | * </li> | |
| * <li> The Responder encrypts SRTP data using the <em>keyResponder</em> an
d the | | * <li> The Responder encrypts SRTP data using the <em>keyResponder</em> an
d the | |
| * <em>saltResponder</em> data, the Initiator uses these data to decry
pt. | | * <em>saltResponder</em> data, the Initiator uses these data to decry
pt. | |
| * </li> | | * </li> | |
| * </ul> | | * </ul> | |
| */ | | */ | |
| /* | | /* | |
| * Keep the following defines in sync with Role enumeration in ZrtpCallback
.h | | * Keep the following defines in sync with Role enumeration in ZrtpCallback
.h | |
| */ | | */ | |
|
| #define Responder 1 | | #define Responder 1 /*!< This client is in ZRTP Responder mode | |
| #define Initiator 2 | | */ | |
| | | #define Initiator 2 /*!< This client is in ZRTP Initiator mode | |
| | | */ | |
| | | | |
| #define CRC_SIZE 4 /*!< Size of CRC code of a ZRTP packet */ | | #define CRC_SIZE 4 /*!< Size of CRC code of a ZRTP packet */ | |
| #define ZRTP_MAGIC 0x5a525450 /*!< The magic code that identifies a ZRTP
packet */ | | #define ZRTP_MAGIC 0x5a525450 /*!< The magic code that identifies a ZRTP
packet */ | |
|
| #define MAX_ZRTP_SIZE 3072 | | #define MAX_ZRTP_SIZE 3072 /*!< The biggest ZRTP packet ever possible
*/ | |
| | | | |
| /* | | /* | |
| * IMPORTANT: keep the following enums in synch with ZrtpCodes. We copy the
m here | | * IMPORTANT: keep the following enums in synch with ZrtpCodes. We copy the
m here | |
| * to avoid any C++ header includes and defines. The protocol states are lo
cated | | * to avoid any C++ header includes and defines. The protocol states are lo
cated | |
| * ZrtpStateClass.h . | | * ZrtpStateClass.h . | |
| */ | | */ | |
| /** | | /** | |
| * This enum defines the information message severity. | | * This enum defines the information message severity. | |
| * | | * | |
| * The ZRTP implementation issues information messages to inform the user | | * The ZRTP implementation issues information messages to inform the user | |
| | | | |
| skipping to change at line 89 | | skipping to change at line 104 | |
| * The enumeration SevereCodes defines the sub-codes. | | * The enumeration SevereCodes defines the sub-codes. | |
| * </dd> | | * </dd> | |
| * <dt>Zrtp</dt> <dd>shows a ZRTP security problem. Refer to the enumeratio
n | | * <dt>Zrtp</dt> <dd>shows a ZRTP security problem. Refer to the enumeratio
n | |
| * ZrtpErrorCodes for sub-codes. GNU ZRTP of course will <b>not</b> | | * ZrtpErrorCodes for sub-codes. GNU ZRTP of course will <b>not</b> | |
| * establish a secure session. | | * establish a secure session. | |
| * </dd> | | * </dd> | |
| * </dl> | | * </dl> | |
| * | | * | |
| */ | | */ | |
| enum zrtp_MessageSeverity { | | enum zrtp_MessageSeverity { | |
|
| zrtp_Info = 1, | | zrtp_Info = 1, /*!< Just an info message */ | |
| zrtp_Warning, | | zrtp_Warning, /*!< A Warning message - security c | |
| zrtp_Severe, | | an be established */ | |
| zrtp_ZrtpError | | zrtp_Severe, /*!< Severe error, security will no | |
| | | t be established */ | |
| | | zrtp_ZrtpError /*!< ZRTP error, security will not | |
| | | be established */ | |
| }; | | }; | |
| | | | |
| /** | | /** | |
| * Sub-codes for Info | | * Sub-codes for Info | |
| */ | | */ | |
| enum zrtp_InfoCodes { | | enum zrtp_InfoCodes { | |
| zrtp_InfoHelloReceived = 1, /*!< Hello received, preparing a C
ommit */ | | zrtp_InfoHelloReceived = 1, /*!< Hello received, preparing a C
ommit */ | |
| zrtp_InfoCommitDHGenerated, /*!< Commit: Generated a public DH
key */ | | zrtp_InfoCommitDHGenerated, /*!< Commit: Generated a public DH
key */ | |
| zrtp_InfoRespCommitReceived, /*!< Responder: Commit received, p
reparing DHPart1 */ | | zrtp_InfoRespCommitReceived, /*!< Responder: Commit received, p
reparing DHPart1 */ | |
| zrtp_InfoDH1DHGenerated, /*!< DH1Part: Generated a public D
H key */ | | zrtp_InfoDH1DHGenerated, /*!< DH1Part: Generated a public D
H key */ | |
| | | | |
| skipping to change at line 174 | | skipping to change at line 189 | |
| zrtp_SASuntrustedMiTM = 0x63, /*!< Received relayed SAS from untrus
ted MiTM */ | | zrtp_SASuntrustedMiTM = 0x63, /*!< Received relayed SAS from untrus
ted MiTM */ | |
| zrtp_ConfirmHMACWrong = 0x70, /*!< Auth. Error: Bad Confirm pkt HMA
C */ | | zrtp_ConfirmHMACWrong = 0x70, /*!< Auth. Error: Bad Confirm pkt HMA
C */ | |
| zrtp_NonceReused = 0x80, /*!< Nonce reuse */ | | zrtp_NonceReused = 0x80, /*!< Nonce reuse */ | |
| zrtp_EqualZIDHello = 0x90, /*!< Equal ZIDs in Hello */ | | zrtp_EqualZIDHello = 0x90, /*!< Equal ZIDs in Hello */ | |
| zrtp_GoCleatNotAllowed = 0x100, /*!< GoClear packet received, but not
allowed */ | | zrtp_GoCleatNotAllowed = 0x100, /*!< GoClear packet received, but not
allowed */ | |
| zrtp_IgnorePacket = 0x7fffffff /*!< Internal state, not reported *
/ | | zrtp_IgnorePacket = 0x7fffffff /*!< Internal state, not reported *
/ | |
| }; | | }; | |
| | | | |
| /* The ZRTP protocol states */ | | /* The ZRTP protocol states */ | |
| enum zrtpStates { | | enum zrtpStates { | |
|
| Initial, | | Initial, /*!< Initial state after starting the state engine | |
| Detect, | | */ | |
| AckDetected, | | Detect, /*!< State sending Hello, try to detect answer mess | |
| AckSent, | | age */ | |
| WaitCommit, | | AckDetected, /*!< HelloAck received */ | |
| CommitSent, | | AckSent, /*!< HelloAck sent after Hello received */ | |
| WaitDHPart2, | | WaitCommit, /*!< Wait for a Commit message */ | |
| WaitConfirm1, | | CommitSent, /*!< Commit message sent */ | |
| WaitConfirm2, | | WaitDHPart2, /*!< Wait for a DHPart2 message */ | |
| WaitConfAck, | | WaitConfirm1, /*!< Wait for a Confirm1 message */ | |
| WaitClearAck, | | WaitConfirm2, /*!< Wait for a confirm2 message */ | |
| SecureState, | | WaitConfAck, /*!< Wait for Conf2Ack */ | |
| WaitErrorAck, | | WaitClearAck, /*!< Wait for clearAck - not used */ | |
| numberOfStates | | SecureState, /*!< This is the secure state - SRTP active */ | |
| | | WaitErrorAck, /*!< Wait for ErrorAck message */ | |
| | | numberOfStates /*!< Gives total number of protocol states */ | |
| }; | | }; | |
| | | | |
|
| | | /*! The algorihms that we support in SRTP and that ZRTP can negotiate. */ | |
| | | typedef enum { | |
| | | zrtp_Aes = 1, /*!< Use AES as symmetrical cipher algorithm */ | |
| | | zrtp_TwoFish, /*!< Use TwoFish as symmetrical cipher algorithm * | |
| | | / | |
| | | zrtp_Sha1, /*!< Use Sha1 as authentication algorithm */ | |
| | | zrtp_Skein /*!< Use Skein as authentication algorithm */ | |
| | | } zrtp_SrtpAlgorithms; | |
| | | | |
| /** | | /** | |
| * This structure contains pointers to the SRTP secrets and the role info. | | * This structure contains pointers to the SRTP secrets and the role info. | |
| * | | * | |
| * About the role and what the meaning of the role is refer to the | | * About the role and what the meaning of the role is refer to the | |
| * of the enum Role. The pointers to the secrets are valid as long as | | * of the enum Role. The pointers to the secrets are valid as long as | |
| * the ZRtp object is active. To use these data after the ZRtp object's | | * the ZRtp object is active. To use these data after the ZRtp object's | |
|
| * lifetime you may copy the data into a save place. The destructor | | * lifetime you may copy the data into a save place. | |
| * of ZRtp clears the data. | | | |
| */ | | */ | |
| typedef struct c_srtpSecrets | | typedef struct c_srtpSecrets | |
| { | | { | |
|
| const uint8_t* keyInitiator; | | zrtp_SrtpAlgorithms symEncAlgorithm;/*!< symmetrical cipher algorithm * | |
| int32_t initKeyLen; | | / | |
| const uint8_t* saltInitiator; | | const uint8_t* keyInitiator; /*!< Initiator's key */ | |
| int32_t initSaltLen; | | int32_t initKeyLen; /*!< Initiator's key length */ | |
| const uint8_t* keyResponder; | | const uint8_t* saltInitiator; /*!< Initiator's salt */ | |
| int32_t respKeyLen; | | int32_t initSaltLen; /*!< Initiator's salt length */ | |
| const uint8_t* saltResponder; | | const uint8_t* keyResponder; /*!< Responder's key */ | |
| int32_t respSaltLen; | | int32_t respKeyLen; /*!< Responder's key length */ | |
| int32_t srtpAuthTagLen; | | const uint8_t* saltResponder; /*!< Responder's salt */ | |
| char* sas; | | int32_t respSaltLen; /*!< Responder's salt length */ | |
| int32_t role; | | zrtp_SrtpAlgorithms authAlgorithm; /*!< SRTP authentication algorithm | |
| | | */ | |
| | | int32_t srtpAuthTagLen; /*!< SRTP authentication length */ | |
| | | char* sas; /*!< The SAS string */ | |
| | | int32_t role; /*!< ZRTP role of this client */ | |
| } C_SrtpSecret_t; | | } C_SrtpSecret_t; | |
| | | | |
| /* | | /* | |
| * Keep the following defines in sync with enum EnableSecurity in ZrtpCallb
ack.h | | * Keep the following defines in sync with enum EnableSecurity in ZrtpCallb
ack.h | |
| */ | | */ | |
|
| #define ForReceiver 1 | | #define ForReceiver 1 /*!< Enable security for SRTP receiver */ | |
| #define ForSender 2 | | #define ForSender 2 /*!< Enable security for SRTP sender */ | |
| | | | |
| #ifdef __cplusplus | | #ifdef __cplusplus | |
| extern "C" | | extern "C" | |
| { | | { | |
| #endif | | #endif | |
| | | | |
| typedef struct ZRtp ZRtp; | | typedef struct ZRtp ZRtp; | |
| typedef struct ZrtpCallbackWrapper ZrtpCallbackWrapper; | | typedef struct ZrtpCallbackWrapper ZrtpCallbackWrapper; | |
|
| | | typedef struct ZrtpConfigure ZrtpConfigure; | |
| | | | |
| typedef struct zrtpContext | | typedef struct zrtpContext | |
| { | | { | |
|
| ZRtp* zrtpEngine; | | ZRtp* zrtpEngine; /*!< Holds the real ZRTP engine | |
| ZrtpCallbackWrapper* zrtpCallback; | | */ | |
| void* userData; | | ZrtpCallbackWrapper* zrtpCallback; /*!< Help class Callback wrappe | |
| | | r */ | |
| | | ZrtpConfigure* configure; /*!< Optional configuration dat | |
| | | a */ | |
| | | void* userData; /*!< User data, set by applicat | |
| | | ion */ | |
| } ZrtpContext; | | } ZrtpContext; | |
| | | | |
| /** | | /** | |
| * This structure defines the callback functions required by GNU ZRTP. | | * This structure defines the callback functions required by GNU ZRTP. | |
| * | | * | |
| * The RTP stack specific part must implement the callback methods. | | * The RTP stack specific part must implement the callback methods. | |
| * The generic part of GNU ZRTP uses these mehtods | | * The generic part of GNU ZRTP uses these mehtods | |
| * to communicate with the specific part, for example to send data | | * to communicate with the specific part, for example to send data | |
| * via the RTP/SRTP stack, to set timers and cancel timer and so on. | | * via the RTP/SRTP stack, to set timers and cancel timer and so on. | |
| * | | * | |
| * The generiy part of GNU ZRTP needs only a few callback methods to | | * The generiy part of GNU ZRTP needs only a few callback methods to | |
| * be implemented by the specific part. | | * be implemented by the specific part. | |
| * | | * | |
| * @author Werner Dittmann <Werner.Dittmann@t-online.de> | | * @author Werner Dittmann <Werner.Dittmann@t-online.de> | |
| */ | | */ | |
| | | | |
|
| | | /** | |
| | | * The following methods define the GNU ZRTP callback interface. | |
| | | * For detailed documentation refer to file ZrtpCallback.h, each C | |
| | | * method has "zrtp_" prepended to the C++ name. | |
| | | * | |
| | | * @see ZrtpCallback | |
| | | */ | |
| typedef struct zrtp_Callbacks | | typedef struct zrtp_Callbacks | |
| { | | { | |
|
| /* | | /** | |
| * The following methods define the GNU ZRTP callback interface. | | * Send a ZRTP packet via RTP. | |
| * For detailed documentation refer to file ZrtpCallback.h, each C | | * | |
| * method has "zrtp_" prepended to the C++ name. | | * ZRTP calls this method to send a ZRTP packet via the RTP session. | |
| | | * | |
| | | * @param ctx | |
| | | * Pointer to the opaque ZrtpContext structure. | |
| | | * @param data | |
| | | * Points to ZRTP packet to send. | |
| | | * @param length | |
| | | * The length in bytes of the data | |
| | | * @return | |
| | | * zero if sending failed, one if packet was send | |
| */ | | */ | |
| int32_t (*zrtp_sendDataZRTP) (ZrtpContext* ctx, const uint8_t* data
, int32_t length ) ; | | int32_t (*zrtp_sendDataZRTP) (ZrtpContext* ctx, const uint8_t* data
, int32_t length ) ; | |
|
| | | | |
| | | /** | |
| | | * Activate timer. | |
| | | * | |
| | | * @param ctx | |
| | | * Pointer to the opaque ZrtpContext structure. | |
| | | * @param time | |
| | | * The time in ms for the timer | |
| | | * @return | |
| | | * zero if activation failed, one if timer was activated | |
| | | */ | |
| int32_t (*zrtp_activateTimer) (ZrtpContext* ctx, int32_t time ) ; | | int32_t (*zrtp_activateTimer) (ZrtpContext* ctx, int32_t time ) ; | |
|
| | | | |
| | | /** | |
| | | * Cancel the active timer. | |
| | | * | |
| | | * @param ctx | |
| | | * Pointer to the opaque ZrtpContext structure. | |
| | | * @return | |
| | | * zero if cancel action failed, one if timer was canceled | |
| | | */ | |
| int32_t (*zrtp_cancelTimer)(ZrtpContext* ctx) ; | | int32_t (*zrtp_cancelTimer)(ZrtpContext* ctx) ; | |
|
| | | | |
| | | /** | |
| | | * Send information messages to the hosting environment. | |
| | | * | |
| | | * The ZRTP implementation uses this method to send information | |
| | | * messages to the host. Along with the message ZRTP provides a | |
| | | * severity indicator that defines: Info, Warning, Error, | |
| | | * Alert. Refer to the <code>MessageSeverity</code> enum above. | |
| | | * | |
| | | * @param ctx | |
| | | * Pointer to the opaque ZrtpContext structure. | |
| | | * @param severity | |
| | | * This defines the message's severity | |
| | | * @param subCode | |
| | | * The subcode identifying the reason. | |
| | | * @see ZrtpCodes#MessageSeverity | |
| | | */ | |
| void (*zrtp_sendInfo) (ZrtpContext* ctx, int32_t severity, int32_t
subCode ) ; | | void (*zrtp_sendInfo) (ZrtpContext* ctx, int32_t severity, int32_t
subCode ) ; | |
|
| | | | |
| | | /** | |
| | | * SRTP crypto data ready for the sender or receiver. | |
| | | * | |
| | | * The ZRTP implementation calls this method right after all SRTP | |
| | | * secrets are computed and ready to be used. The parameter points | |
| | | * to a structure that contains pointers to the SRTP secrets and a | |
| | | * <code>enum Role</code>. The called method (the implementation | |
| | | * of this abstract method) must either copy the pointers to the SR | |
| | | TP | |
| | | * data or the SRTP data itself to a save place. The SrtpSecret_t | |
| | | * structure is destroyed after the callback method returns to the | |
| | | * ZRTP implementation. | |
| | | * | |
| | | * The SRTP data themselfs are ontained in the ZRtp object and are | |
| | | * valid as long as the ZRtp object is active. TheZRtp's | |
| | | * destructor clears the secrets. Thus the called method needs to | |
| | | * save the pointers only, ZRtp takes care of the data. | |
| | | * | |
| | | * The implementing class may enable SRTP processing in this | |
| | | * method or delay it to srtpSecertsOn(). | |
| | | * | |
| | | * @param ctx | |
| | | * Pointer to the opaque ZrtpContext structure. | |
| | | * @param secrets A pointer to a SrtpSecret_t structure that | |
| | | * contains all necessary data. | |
| | | * | |
| | | * @param part for which part (Sender or Receiver) this data is | |
| | | * valid. | |
| | | * | |
| | | * @return Returns false if something went wrong during | |
| | | * initialization of SRTP context, for example memory shortage. | |
| | | */ | |
| int32_t (*zrtp_srtpSecretsReady) (ZrtpContext* ctx, C_SrtpSecret_t*
secrets, int32_t part ) ; | | int32_t (*zrtp_srtpSecretsReady) (ZrtpContext* ctx, C_SrtpSecret_t*
secrets, int32_t part ) ; | |
|
| | | | |
| | | /** | |
| | | * Switch off the security for the defined part. | |
| | | * | |
| | | * @param ctx | |
| | | * Pointer to the opaque ZrtpContext structure. | |
| | | * @param part Defines for which part (sender or receiver) to | |
| | | * switch on security | |
| | | */ | |
| void (*zrtp_srtpSecretsOff) (ZrtpContext* ctx, int32_t part ) ; | | void (*zrtp_srtpSecretsOff) (ZrtpContext* ctx, int32_t part ) ; | |
|
| | | | |
| | | /** | |
| | | * Switch on the security. | |
| | | * | |
| | | * ZRTP calls this method after it has computed the SAS and check | |
| | | * if it is verified or not. In addition ZRTP provides information | |
| | | * about the cipher algorithm and key length for the SRTP session. | |
| | | * | |
| | | * This method must enable SRTP processing if it was not enabled | |
| | | * during sertSecretsReady(). | |
| | | * | |
| | | * @param ctx | |
| | | * Pointer to the opaque ZrtpContext structure. | |
| | | * @param c The name of the used cipher algorithm and mode, or | |
| | | * NULL | |
| | | * | |
| | | * @param s The SAS string | |
| | | * | |
| | | * @param verified if <code>verified</code> is true then SAS was | |
| | | * verified by both parties during a previous call. | |
| | | */ | |
| void (*zrtp_rtpSecretsOn) (ZrtpContext* ctx, char* c, char* s, int3
2_t verified ) ; | | void (*zrtp_rtpSecretsOn) (ZrtpContext* ctx, char* c, char* s, int3
2_t verified ) ; | |
|
| | | | |
| | | /** | |
| | | * This method handles GoClear requests. | |
| | | * | |
| | | * According to the ZRTP specification the user must be informed ab | |
| | | out | |
| | | * a GoClear request because the ZRTP implementation switches off s | |
| | | ecurity | |
| | | * if it could authenticate the GoClear packet. | |
| | | * | |
| | | * <b>Note:</b> GoClear is not yet implemented in GNU ZRTP. | |
| | | * | |
| | | * @param ctx | |
| | | * Pointer to the opaque ZrtpContext structure. | |
| | | */ | |
| void (*zrtp_handleGoClear)(ZrtpContext* ctx) ; | | void (*zrtp_handleGoClear)(ZrtpContext* ctx) ; | |
|
| | | | |
| | | /** | |
| | | * Handle ZRTP negotiation failed. | |
| | | * | |
| | | * ZRTP calls this method in case ZRTP negotiation failed. The | |
| | | * parameters show the severity as well as the reason. | |
| | | * | |
| | | * @param ctx | |
| | | * Pointer to the opaque ZrtpContext structure. | |
| | | * @param severity | |
| | | * This defines the message's severity | |
| | | * @param subCode | |
| | | * The subcode identifying the reason. | |
| | | * @see ZrtpCodes#MessageSeverity | |
| | | */ | |
| void (*zrtp_zrtpNegotiationFailed) (ZrtpContext* ctx, int32_t sever
ity, int32_t subCode ) ; | | void (*zrtp_zrtpNegotiationFailed) (ZrtpContext* ctx, int32_t sever
ity, int32_t subCode ) ; | |
|
| | | | |
| | | /** | |
| | | * ZRTP calls this method if the other side does not support ZRTP. | |
| | | * | |
| | | * @param ctx | |
| | | * Pointer to the opaque ZrtpContext structure. | |
| | | * If the other side does not answer the ZRTP <em>Hello</em> packet | |
| | | s then | |
| | | * ZRTP calls this method, | |
| | | * | |
| | | */ | |
| void (*zrtp_zrtpNotSuppOther)(ZrtpContext* ctx) ; | | void (*zrtp_zrtpNotSuppOther)(ZrtpContext* ctx) ; | |
|
| | | | |
| | | /** | |
| | | * Enter synchronization mutex. | |
| | | * | |
| | | * GNU ZRTP requires one mutes to synchronize its | |
| | | * processing. Because mutex implementations depend on the | |
| | | * underlying infrastructure, for example operating system or | |
| | | * thread implementation, GNU ZRTP delegates mutex handling to the | |
| | | * spcific part of its implementation. | |
| | | * | |
| | | * @param ctx | |
| | | * Pointer to the opaque ZrtpContext structure. | |
| | | */ | |
| void (*zrtp_synchEnter)(ZrtpContext* ctx) ; | | void (*zrtp_synchEnter)(ZrtpContext* ctx) ; | |
|
| | | | |
| | | /** | |
| | | * Leave synchronization mutex. | |
| | | * | |
| | | * @param ctx | |
| | | * Pointer to the opaque ZrtpContext structure. | |
| | | */ | |
| void (*zrtp_synchLeave)(ZrtpContext* ctx) ; | | void (*zrtp_synchLeave)(ZrtpContext* ctx) ; | |
|
| | | | |
| | | /** | |
| | | * Inform about a PBX enrollment request. | |
| | | * | |
| | | * Please refer to chapter 8.3 ff to get more details about PBX | |
| | | * enrollment and SAS relay. | |
| | | * | |
| | | * <b>Note:</b> PBX enrollement is not yet fully supported by GNU | |
| | | * ZRTP. | |
| | | * | |
| | | * @param ctx | |
| | | * Pointer to the opaque ZrtpContext structure. | |
| | | * @param info Give some information to the user about the PBX | |
| | | * requesting an enrollment. | |
| | | */ | |
| void (*zrtp_zrtpAskEnrollment) (ZrtpContext* ctx, char* info ) ; | | void (*zrtp_zrtpAskEnrollment) (ZrtpContext* ctx, char* info ) ; | |
|
| | | | |
| | | /** | |
| | | * Inform about PBX enrollment result. | |
| | | * | |
| | | * Informs the use about the acceptance or denial of an PBX enrollm | |
| | | ent | |
| | | * request | |
| | | * | |
| | | * <b>Note:</b> PBX enrollement is not yet fully supported by GNU | |
| | | * ZRTP. | |
| | | * | |
| | | * @param ctx | |
| | | * Pointer to the opaque ZrtpContext structure. | |
| | | * @param info Give some information to the user about the result | |
| | | * of an enrollment. | |
| | | */ | |
| void (*zrtp_zrtpInformEnrollment) (ZrtpContext* ctx, char* info ) ; | | void (*zrtp_zrtpInformEnrollment) (ZrtpContext* ctx, char* info ) ; | |
|
| | | | |
| | | /** | |
| | | * Request a SAS signature. | |
| | | * | |
| | | * After ZRTP was able to compute the Short Authentication String | |
| | | * (SAS) it calls this method. The client may now use an | |
| | | * approriate method to sign the SAS. The client may use | |
| | | * ZrtpQueue#setSignatureData() to store the signature data an | |
| | | * enable signature transmission to the other peer. Refer to | |
| | | * chapter 8.2 of ZRTP specification. | |
| | | * | |
| | | * <b>Note:</b> SAS signing is not yet fully supported by GNU | |
| | | * ZRTP. | |
| | | * | |
| | | * @param ctx | |
| | | * Pointer to the opaque ZrtpContext structure. | |
| | | * @param sas | |
| | | * The SAS string to sign. | |
| | | * | |
| | | */ | |
| void (*zrtp_signSAS)(ZrtpContext* ctx, char* sas) ; | | void (*zrtp_signSAS)(ZrtpContext* ctx, char* sas) ; | |
|
| | | | |
| | | /** | |
| | | * ZRTPQueue calls this method to request a SAS signature check. | |
| | | * | |
| | | * After ZRTP received a SAS signature in one of the Confirm packet | |
| | | s it | |
| | | * call this method. The client may use <code>getSignatureLength()< | |
| | | /code> | |
| | | * and <code>getSignatureData()</code>of ZrtpQueue to get the signa | |
| | | ture | |
| | | * data and perform the signature check. Refer to chapter 8.2 of ZR | |
| | | TP | |
| | | * specification. | |
| | | * | |
| | | * If the signature check fails the client may return false to ZRTP | |
| | | . In | |
| | | * this case ZRTP signals an error to the other peer and terminates | |
| | | * the ZRTP handshake. | |
| | | * | |
| | | * <b>Note:</b> SAS signing is not yet fully supported by GNU | |
| | | * ZRTP. | |
| | | * | |
| | | * @param ctx | |
| | | * Pointer to the opaque ZrtpContext structure. | |
| | | * @param sas | |
| | | * The SAS string that was signed by the other peer. | |
| | | * @return | |
| | | * true if the signature was ok, false otherwise. | |
| | | * | |
| | | */ | |
| int32_t (*zrtp_checkSASSignature) (ZrtpContext* ctx, char* sas ) ; | | int32_t (*zrtp_checkSASSignature) (ZrtpContext* ctx, char* sas ) ; | |
| } zrtp_Callbacks; | | } zrtp_Callbacks; | |
| | | | |
| /** | | /** | |
|
| * Application callback methods. | | * Create the GNU ZRTP C wrapper. | |
| * | | | |
| * The RTP stack specific part of GNU ZRTP uses these callback methods | | | |
| * to report ZRTP events to the application. Thus the application that | | | |
| * instantiates the RTP stack shall implement these methods and show th | | | |
| ese | | | |
| * inforemation to the user. | | | |
| * | | | |
| * <b>CAVEAT</b><br/> | | | |
| * All user callback methods run in the context of the RTP thread. Thus | | | |
| * it is of paramount importance to keep the execution time of the meth | | | |
| ods | | | |
| * as short as possible. | | | |
| * | | * | |
|
| * @author Werner Dittmann <Werner.Dittmann@t-online.de> | | * This wrapper implements the C interface to the C++ based GNU ZRTP. | |
| | | * @returns | |
| | | * Pointer to the ZrtpContext | |
| */ | | */ | |
|
| | | ZrtpContext* zrtp_CreateWrapper(); | |
| typedef struct zrtp_UserCallbacks | | | |
| { | | | |
| /* | | | |
| * The following methods define the GNU ZRTP user callback interface | | | |
| . | | | |
| * For detailed documentation refer to file ZrtpUserCallback.h, each | | | |
| C | | | |
| * method has "zrtp_" prepended to the C++ name. | | | |
| */ | | | |
| void (*zrtp_secureOn)(void* data, char* cipher); | | | |
| void (*zrtp_secureOff)(void* data); | | | |
| void (*zrtp_showSAS)(void* data, char* sas, int32_t verified); | | | |
| void (*zrtp_confirmGoClear)(void* data); | | | |
| void (*zrtp_showMessage)(void* data, int32_t sev, int32_t subCode); | | | |
| void (*zrtp_zrtpNegotiationFailed)(void* data, int32_t severity, in | | | |
| t32_t subCode); | | | |
| void (*zrtp_zrtpNotSuppOther)(void* data); | | | |
| void (*zrtp_zrtpAskEnrollment)(void* data, char* info); | | | |
| void (*zrtp_zrtpInformEnrollment)(void* data, char* info); | | | |
| void (*zrtp_signSAS)(void* data, char* sas); | | | |
| int32_t (*zrtp_checkSASSignature)(void* data, char* sas); | | | |
| | | | |
| void* userData; | | | |
| } zrtp_UserCallbacks; | | | |
| | | | |
| /** | | /** | |
|
| * Create the GNU ZRTP C wrapper. | | * Initialize the ZRTP protocol engine. | |
| * | | * | |
|
| * This wrapper implements the C interface to the C++ based GNU ZRTP. | | * This method initialized the GNU ZRTP protocol engine. An application | |
| | | * call this method to actually create the ZRTP protocol engine and | |
| | | * initialize its configuration data. This method does not start the | |
| | | * protocol engine. | |
| * | | * | |
|
| | | * If an application requires a specific algorithm configuration then i | |
| | | t | |
| | | * must set the algorithm configuration data before it initializes the | |
| | | * ZRTP protocol engine. | |
| | | * | |
| | | * @param zrtpContext | |
| | | * Pointer to the opaque ZrtpContext structure. | |
| * @param cb | | * @param cb | |
| * The callback structure that holds the addresses of the callback | | * The callback structure that holds the addresses of the callback | |
| * methods. | | * methods. | |
| * @param id | | * @param id | |
| * A C string that holds the ZRTP client id, only the first 16 char
s | | * A C string that holds the ZRTP client id, only the first 16 char
s | |
| * are used. | | * are used. | |
|
| * @param config | | | |
| * Pointer to ZRTP config data - TDB - defines which encryption | | | |
| * algorithms to, which SHA etc. | | | |
| * @param zidFilename | | * @param zidFilename | |
| * The name of the ZID file. This file holds some parameters and | | * The name of the ZID file. This file holds some parameters and | |
| * other data like additional shared secrets. | | * other data like additional shared secrets. | |
| * @param userData | | * @param userData | |
| * A pointer to user data. The wrapper just stores this pointer in | | * A pointer to user data. The wrapper just stores this pointer in | |
| * the ZrtpContext and the application may use it for its purposes. | | * the ZrtpContext and the application may use it for its purposes. | |
| * @returns | | * @returns | |
|
| * Pointer to the ZrtpContext | | * Pointer to the ZrtpContext | |
| | | * | |
| | | * @see zrtp_InitializeConfig | |
| */ | | */ | |
|
| ZrtpContext* zrtp_CreateWrapper (zrtp_Callbacks *cb, char* id, | | void zrtp_initializeZrtpEngine(ZrtpContext* zrtpContext, | |
| void* config, const char* zidFilename, | | zrtp_Callbacks *cb, | |
| void* userData ); | | char* id, | |
| | | const char* zidFilename, | |
| | | void* userData); | |
| | | | |
|
| void zrtp_DestroyWrapper (ZrtpContext* zrtpContext ); | | /** | |
| | | * Destroy the ZRTP wrapper and its underlying objects. | |
| | | */ | |
| | | void zrtp_DestroyWrapper (ZrtpContext* zrtpContext); | |
| | | | |
| /** | | /** | |
| * Computes the ZRTP checksum over a received ZRTP packet buffer and | | * Computes the ZRTP checksum over a received ZRTP packet buffer and | |
| * compares the result with received checksum. | | * compares the result with received checksum. | |
| * | | * | |
| * @param buffer | | * @param buffer | |
| * Pointer to ZRTP packet buffer | | * Pointer to ZRTP packet buffer | |
| * @param length | | * @param length | |
| * Length of the packet buffer excluding received CRC data | | * Length of the packet buffer excluding received CRC data | |
| * @param crc | | * @param crc | |
| | | | |
| skipping to change at line 437 | | skipping to change at line 695 | |
| * protocol state engine. | | * protocol state engine. | |
| * | | * | |
| * <b>NOTE: application shall never call this method directly. Only | | * <b>NOTE: application shall never call this method directly. Only | |
| * the module that implements the RTP binding shall use this method</b> | | * the module that implements the RTP binding shall use this method</b> | |
| * | | * | |
| * @param zrtpContext | | * @param zrtpContext | |
| * Pointer to the opaque ZrtpContext structure. | | * Pointer to the opaque ZrtpContext structure. | |
| */ | | */ | |
| void zrtp_processTimeout(ZrtpContext* zrtpContext); | | void zrtp_processTimeout(ZrtpContext* zrtpContext); | |
| | | | |
|
| /** | | /* | |
| * Check for and handle GoClear ZRTP packet header. | | * Check for and handle GoClear ZRTP packet header. | |
| * | | * | |
| * This method checks if this is a GoClear packet. If not, just return | | * This method checks if this is a GoClear packet. If not, just return | |
| * false. Otherwise handle it according to the specification. | | * false. Otherwise handle it according to the specification. | |
| * | | * | |
| * @param zrtpContext | | * @param zrtpContext | |
| * Pointer to the opaque ZrtpContext structure. | | * Pointer to the opaque ZrtpContext structure. | |
| * @param extHeader | | * @param extHeader | |
| * A pointer to the first byte of the extension header. Refer to | | * A pointer to the first byte of the extension header. Refer to | |
| * RFC3550. | | * RFC3550. | |
| * @return | | * @return | |
| * False if not a GoClear, true otherwise. | | * False if not a GoClear, true otherwise. | |
| * | | * | |
| int32_t zrtp_handleGoClear(ZrtpContext* zrtpContext, uint8_t *extHeader
); | | int32_t zrtp_handleGoClear(ZrtpContext* zrtpContext, uint8_t *extHeader
); | |
| */ | | */ | |
|
| | | | |
| /** | | /** | |
| * Set the auxilliary secret. | | * Set the auxilliary secret. | |
| * | | * | |
| * Use this method to set the auxilliary secret data. Refer to ZRTP | | * Use this method to set the auxilliary secret data. Refer to ZRTP | |
| * specification, chapter 4.3 ff | | * specification, chapter 4.3 ff | |
| * | | * | |
| * @param zrtpContext | | * @param zrtpContext | |
| * Pointer to the opaque ZrtpContext structure. | | * Pointer to the opaque ZrtpContext structure. | |
| * @param data | | * @param data | |
| * Points to the secret data. | | * Points to the secret data. | |
| | | | |
| skipping to change at line 737 | | skipping to change at line 996 | |
| * Pointer to the opaque ZrtpContext structure. | | * Pointer to the opaque ZrtpContext structure. | |
| * @param data | | * @param data | |
| * Pointer to a data buffer. This buffer must have a size of | | * Pointer to a data buffer. This buffer must have a size of | |
| * at least 12 bytes (96 bit) (ZRTP Identifier, see chap. 4.9) | | * at least 12 bytes (96 bit) (ZRTP Identifier, see chap. 4.9) | |
| * @return | | * @return | |
| * Number of bytes copied into the data buffer - must be equivalent | | * Number of bytes copied into the data buffer - must be equivalent | |
| * to 12 bytes. | | * to 12 bytes. | |
| */ | | */ | |
| int32_t zrtp_getZid(ZrtpContext* zrtpContext, uint8_t* data); | | int32_t zrtp_getZid(ZrtpContext* zrtpContext, uint8_t* data); | |
| | | | |
|
| | | /** | |
| | | * This enumerations list all configurable algorithm types. | |
| | | */ | |
| | | | |
| | | /* Keep in synch with enumeration in ZrtpConfigure.h */ | |
| | | | |
| | | typedef enum zrtp_AlgoTypes { | |
| | | zrtp_HashAlgorithm = 1, zrtp_CipherAlgorithm, zrtp_PubKeyAlgorithm, | |
| | | zrtp_SasType, zrtp_AuthLength | |
| | | } Zrtp_AlgoTypes; | |
| | | | |
| | | /** | |
| | | * Initialize the GNU ZRTP Configure data. | |
| | | * | |
| | | * Initializing and setting a ZRTP configuration is optional. GNU ZRTP | |
| | | * uses a sensible default if an application does not define its own | |
| | | * ZRTP configuration. | |
| | | * | |
| | | * If an application initialize th configure data it must set the | |
| | | * configuration data. | |
| | | * | |
| | | * The ZRTP specification, chapters 5.1.2 through 5.1.6 defines the | |
| | | * algorithm names and their meaning. | |
| | | * | |
| | | * The current ZRTP implementation implements all mandatory algorithms | |
| | | * plus a set of the optional algorithms. An application shall use | |
| | | * @c zrtp_getAlgorithmNames to get the names of the available algorith | |
| | | ms. | |
| | | * | |
| | | * @param zrtpContext | |
| | | * Pointer to the opaque ZrtpContext structure. | |
| | | * @returns | |
| | | * Pointer to the ZrtpConfCtx | |
| | | * | |
| | | * @see zrtp_getAlgorithmNames | |
| | | */ | |
| | | int32_t zrtp_InitializeConfig (ZrtpContext* zrtpContext); | |
| | | | |
| | | /** | |
| | | * Get names of all available algorithmes of a given algorithm type. | |
| | | * | |
| | | * The algorithm names are as specified in the ZRTP specification, chap | |
| | | ters | |
| | | * 5.1.2 through 5.1.6 . | |
| | | * | |
| | | * @param zrtpContext | |
| | | * Pointer to the opaque ZrtpContext structure. | |
| | | * @param type | |
| | | * The algorithm type. | |
| | | * @returns | |
| | | * A NULL terminated array of character pointers. | |
| | | */ | |
| | | char** zrtp_getAlgorithmNames(ZrtpContext* zrtpContext, Zrtp_AlgoTypes | |
| | | type); | |
| | | | |
| | | /** | |
| | | * Free storage used to store the algorithm names. | |
| | | * | |
| | | * If an application does not longer require the algoritm names it shou | |
| | | ld | |
| | | * free the space. | |
| | | * | |
| | | * @param names | |
| | | * The NULL terminated array of character pointers. | |
| | | */ | |
| | | void zrtp_freeAlgorithmNames(char** names); | |
| | | | |
| | | /** | |
| | | * Convenience function that sets a pre-defined standard configuration. | |
| | | * | |
| | | * The standard configuration consists of the following algorithms: | |
| | | * <ul> | |
| | | * <li> Hash: SHA256 </li> | |
| | | * <li> Symmetric Cipher: AES 128, AES 256 </li> | |
| | | * <li> Public Key Algorithm: DH2048, DH3027, MultiStream </li> | |
| | | * <li> SAS type: libase 32 </li> | |
| | | * <li> SRTP Authentication lengths: 32, 80 </li> | |
| | | *</ul> | |
| | | * | |
| | | * @param zrtpContext | |
| | | * Pointer to the opaque ZrtpContext structure. | |
| | | */ | |
| | | void zrtp_setStandardConfig(ZrtpContext* zrtpContext); | |
| | | | |
| | | /** | |
| | | * Convenience function that sets the mandatory algorithms only. | |
| | | * | |
| | | * Mandatory algorithms are: | |
| | | * <ul> | |
| | | * <li> Hash: SHA256 </li> | |
| | | * <li> Symmetric Cipher: AES 128 </li> | |
| | | * <li> Public Key Algorithm: DH3027, MultiStream </li> | |
| | | * <li> SAS type: libase 32 </li> | |
| | | * <li> SRTP Authentication lengths: 32, 80 </li> | |
| | | *</ul> | |
| | | * | |
| | | * @param zrtpContext | |
| | | * Pointer to the opaque ZrtpContext structure. | |
| | | */ | |
| | | void zrtp_setMandatoryOnly(ZrtpContext* zrtpContext); | |
| | | | |
| | | /** | |
| | | * Clear all configuration data. | |
| | | * | |
| | | * The functions clears all configuration data. | |
| | | * | |
| | | * @param zrtpContext | |
| | | * Pointer to the opaque ZrtpContext structure. | |
| | | */ | |
| | | void zrtp_confClear(ZrtpContext* zrtpContext); | |
| | | | |
| | | /** | |
| | | * Add an algorithm to configuration data. | |
| | | * | |
| | | * Adds the specified algorithm to the configuration data. | |
| | | * If no free configuration data slot is available the | |
| | | * function does not add the algorithm and returns -1. The | |
| | | * methods appends the algorithm to the existing algorithms. | |
| | | * | |
| | | * @param zrtpContext | |
| | | * Pointer to the opaque ZrtpContext structure. | |
| | | * @param algoType | |
| | | * Specifies which algorithm type to select | |
| | | * @param algo | |
| | | * The name of the algorithm to add. | |
| | | * @return | |
| | | * Number of free configuration data slots or -1 on error | |
| | | */ | |
| | | int32_t zrtp_addAlgo(ZrtpContext* zrtpContext, Zrtp_AlgoTypes algoType, | |
| | | const char* algo); | |
| | | | |
| | | /** | |
| | | * Add an algorithm to configuration data at given index | |
| | | * | |
| | | * Adds the specified algorithm to the configuration data vector | |
| | | * at a given index. If the index is larger than the actual size | |
| | | * of the configuration vector the method just appends the algorithm. | |
| | | * | |
| | | * @param zrtpContext | |
| | | * Pointer to the opaque ZrtpContext structure. | |
| | | * @param algoType | |
| | | * Specifies which algorithm type to select | |
| | | * @param algo | |
| | | * The name of the algorithm to add. | |
| | | * @param index | |
| | | * The index where to add the algorihm | |
| | | * @return | |
| | | * Number of free configuration data slots or -1 on error | |
| | | */ | |
| | | int32_t zrtp_addAlgoAt(ZrtpContext* zrtpContext, Zrtp_AlgoTypes algoTyp | |
| | | e, const char* algo, int32_t index); | |
| | | | |
| | | /** | |
| | | * Remove a algorithm from configuration data. | |
| | | * | |
| | | * Removes the specified algorithm from configuration data. If | |
| | | * the algorithm was not configured previously the function does | |
| | | * not modify the configuration data and returns the number of | |
| | | * free configuration data slots. | |
| | | * | |
| | | * If an application removes all algorithms then ZRTP does not | |
| | | * include any algorithm into the hello message and falls back | |
| | | * to a predefined mandatory algorithm. | |
| | | * | |
| | | * @param zrtpContext | |
| | | * Pointer to the opaque ZrtpContext structure. | |
| | | * @param algoType | |
| | | * Specifies which algorithm type to select | |
| | | * @param algo | |
| | | * The name of the algorithm to remove. | |
| | | * @return | |
| | | * Number of free configuration slots. | |
| | | */ | |
| | | int32_t zrtp_removeAlgo(ZrtpContext* zrtpContext, Zrtp_AlgoTypes algoTy | |
| | | pe, const char* algo); | |
| | | | |
| | | /** | |
| | | * Returns the number of configured algorithms. | |
| | | * | |
| | | * @param zrtpContext | |
| | | * Pointer to the opaque ZrtpContext structure. | |
| | | * @param algoType | |
| | | * Specifies which algorithm type to select | |
| | | * @return | |
| | | * The number of configured algorithms (used configuration | |
| | | * data slots) | |
| | | */ | |
| | | int32_t zrtp_getNumConfiguredAlgos(ZrtpContext* zrtpContext, Zrtp_AlgoT | |
| | | ypes algoType); | |
| | | | |
| | | /** | |
| | | * Returns the identifier of the algorithm at index. | |
| | | * | |
| | | * @param zrtpContext | |
| | | * Pointer to the opaque ZrtpContext structure. | |
| | | * @param algoType | |
| | | * Specifies which algorithm type to select | |
| | | * @param index | |
| | | * The index in the list of the algorihm type | |
| | | * @return | |
| | | * A pointer to the algorithm name. If the index | |
| | | * does not point to a configured slot then the function | |
| | | * returns NULL. | |
| | | * | |
| | | */ | |
| | | const char* zrtp_getAlgoAt(ZrtpContext* zrtpContext, Zrtp_AlgoTypes alg | |
| | | oType, int32_t index); | |
| | | | |
| | | /** | |
| | | * Checks if the configuration data of the algorihm type already contai | |
| | | ns | |
| | | * a specific algorithms. | |
| | | * | |
| | | * @param zrtpContext | |
| | | * Pointer to the opaque ZrtpContext structure. | |
| | | * @param algoType | |
| | | * Specifies which algorithm type to select | |
| | | * @param algo | |
| | | * The name of the algorithm to check | |
| | | * @return | |
| | | * True if the algorithm was found, false otherwise. | |
| | | * | |
| | | */ | |
| | | int32_t zrtp_containsAlgo(ZrtpContext* zrtpContext, Zrtp_AlgoTypes algo | |
| | | Type, const char* algo); | |
| | | | |
| | | /** | |
| | | * Enables or disables trusted MitM processing. | |
| | | * | |
| | | * For further details of trusted MitM processing refer to ZRTP | |
| | | * specification, chapter 7.3 | |
| | | * | |
| | | * @param zrtpContext | |
| | | * Pointer to the opaque ZrtpContext structure. | |
| | | * @param yesNo | |
| | | * If set to true then trusted MitM processing is enabled. | |
| | | */ | |
| | | void zrtp_setTrustedMitM(ZrtpContext* zrtpContext, int32_t yesNo); | |
| | | | |
| | | /** | |
| | | * Check status of trusted MitM processing. | |
| | | * | |
| | | * @param zrtpContext | |
| | | * Pointer to the opaque ZrtpContext structure. | |
| | | * @return | |
| | | * Returns true if trusted MitM processing is enabled. | |
| | | */ | |
| | | int32_t zrtp_isTrustedMitM(ZrtpContext* zrtpContext); | |
| | | | |
| | | /** | |
| | | * Enables or disables SAS signature processing. | |
| | | * | |
| | | * For further details of trusted MitM processing refer to ZRTP | |
| | | * specification, chapter 7.2 | |
| | | * | |
| | | * @param zrtpContext | |
| | | * Pointer to the opaque ZrtpContext structure. | |
| | | * @param yesNo | |
| | | * If true then certificate processing is enabled. | |
| | | */ | |
| | | void zrtp_setSasSignature(ZrtpContext* zrtpContext, int32_t yesNo); | |
| | | | |
| | | /** | |
| | | * Check status of SAS signature processing. | |
| | | * | |
| | | * @param zrtpContext | |
| | | * Pointer to the opaque ZrtpContext structure. | |
| | | * @return | |
| | | * Returns true if certificate processing is enabled. | |
| | | */ | |
| | | int32_t zrtp_isSasSignature(ZrtpContext* zrtpContext); | |
| | | | |
| #ifdef __cplusplus | | #ifdef __cplusplus | |
| } | | } | |
| #endif | | #endif | |
| | | | |
|
| | | /** | |
| | | * @} | |
| | | */ | |
| #endif | | #endif | |
| | | | |
End of changes. 43 change blocks. |
| 94 lines changed or deleted | | 648 lines changed or added | |
|
| ZrtpConfigure.h | | ZrtpConfigure.h | |
| /* | | /* | |
|
| Copyright (C) 2009 Werner Dittmann | | Copyright (C) 2009 - 2010 Werner Dittmann | |
| | | | |
| This program is free software: you can redistribute it and/or modify | | This program is free software: you can redistribute it and/or modify | |
| it under the terms of the GNU General Public License as published by | | it under the terms of the GNU General Public License as published by | |
| the Free Software Foundation, either version 3 of the License, or | | the Free Software Foundation, either version 3 of the License, or | |
| (at your option) any later version. | | (at your option) any later version. | |
| | | | |
| This program is distributed in the hope that it will be useful, | | This program is distributed in the hope that it will be useful, | |
| but WITHOUT ANY WARRANTY; without even the implied warranty of | | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| GNU General Public License for more details. | | GNU General Public License for more details. | |
| | | | |
| skipping to change at line 25 | | skipping to change at line 25 | |
| along with this program. If not, see <http://www.gnu.org/licenses/>. | | along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| */ | | */ | |
| | | | |
| /* | | /* | |
| * Authors: Werner Dittmann <Werner.Dittmann@t-online.de> | | * Authors: Werner Dittmann <Werner.Dittmann@t-online.de> | |
| */ | | */ | |
| | | | |
| #ifndef _ZRTPCONFIGURE_H_ | | #ifndef _ZRTPCONFIGURE_H_ | |
| #define _ZRTPCONFIGURE_H_ | | #define _ZRTPCONFIGURE_H_ | |
| | | | |
|
| | | /** | |
| | | * @file ZrtpConfigure.h | |
| | | * @brief The ZRTP configure functions | |
| | | * @ingroup GNU_ZRTP | |
| | | * @{ | |
| | | */ | |
| | | | |
| #include <stdio.h> | | #include <stdio.h> | |
| #include <stdint.h> | | #include <stdint.h> | |
| #include <list> | | #include <list> | |
| #include <string> | | #include <string> | |
| #include <vector> | | #include <vector> | |
| #include <string.h> | | #include <string.h> | |
| | | | |
| /** | | /** | |
| * This enumerations list all configurable algorithm types. | | * This enumerations list all configurable algorithm types. | |
| */ | | */ | |
| | | | |
| enum AlgoTypes { | | enum AlgoTypes { | |
|
| HashAlgorithm = 1, CipherAlgorithm, PubKeyAlgorithm, SasType, AuthLengt
h | | Invalid = 0, HashAlgorithm = 1, CipherAlgorithm, PubKeyAlgorithm, SasTy
pe, AuthLength | |
| }; | | }; | |
| | | | |
| /** | | /** | |
| * The algorithm enumration class. | | * The algorithm enumration class. | |
| * | | * | |
| * This simple class is just a container of an algorithm's name and | | * This simple class is just a container of an algorithm's name and | |
| * its associated algorithm type. We use this class together with the | | * its associated algorithm type. We use this class together with the | |
| * EnumBase class to implement a Java-like enum class functionality | | * EnumBase class to implement a Java-like enum class functionality | |
|
| * (not fully, but OK for our use case at hand). | | * (not fully, but OK for our use case). | |
| | | * | |
| | | * An application shall use the get / check methods to retrieve information | |
| | | . | |
| */ | | */ | |
| class AlgorithmEnum { | | class AlgorithmEnum { | |
| public: | | public: | |
|
| AlgorithmEnum(const int type, const char* name); | | /** | |
| | | * Create an AlgorithmEnum object. | |
| | | * | |
| | | * @param type | |
| | | * Defines the algorithm type | |
| | | * @param name | |
| | | * Set the names of the algorithm. The name is copied | |
| | | * and the call may reuse the space. | |
| | | * | |
| | | * @see AlgoTypes | |
| | | */ | |
| | | AlgorithmEnum(const AlgoTypes type, const char* name); | |
| | | | |
| | | /** | |
| | | * AlgorithmEnum destructor | |
| | | */ | |
| | | ~AlgorithmEnum(); | |
| | | | |
| | | /** | |
| | | * Get the algorihm's name | |
| | | * | |
| | | * @returns | |
| | | * Algorithm's name as null terminated C-string. The | |
| | | * application must not free this memory. | |
| | | */ | |
| const char* getName(); | | const char* getName(); | |
|
| int getAlgoType(); | | | |
| | | /** | |
| | | * Get the algorithm type of this AlgorithmEnum object. | |
| | | * | |
| | | * @returns | |
| | | * The algorithm type. | |
| | | * | |
| | | * @see AlgoTypes | |
| | | */ | |
| | | AlgoTypes getAlgoType(); | |
| | | | |
| | | /** | |
| | | * Check if this AlgorithmEnum object is valid | |
| | | * | |
| | | * @returns | |
| | | * @c true if the object is valid, @c false otherwise | |
| | | */ | |
| bool isValid(); | | bool isValid(); | |
| | | | |
| private: | | private: | |
|
| int algoType; | | AlgoTypes algoType; | |
| const char* algoName; | | std::string algoName; | |
| }; | | }; | |
| | | | |
| /** | | /** | |
|
| * EnumBase provides methods to access the algorithm enumerations. | | * EnumBase provides methods to store and access algorithm enumerations of | |
| | | * a specific algorithm type. | |
| | | * | |
| | | * An application shall use the get / check methods to retrieve information | |
| | | * from the preset Algorithm Enumerations. | |
| | | * | |
| | | * @see AlgoTypes | |
| | | * @see zrtpHashes | |
| | | * @see zrtpSymCiphers | |
| | | * @see zrtpPubKeys | |
| | | * @see zrtpSasTypes | |
| | | * @see zrtpAuthLengths | |
| */ | | */ | |
| class EnumBase { | | class EnumBase { | |
| public: | | public: | |
|
| | | /** | |
| | | * Get an AlgorithmEnum by its name | |
| | | * | |
| | | * @param name | |
| | | * The name of the AlgorithmEnum to search. | |
| | | * @returns | |
| | | * The AlgorithmEnum if found or an invalid AlgorithmEnum if the nam | |
| | | e | |
| | | * was not found | |
| | | */ | |
| AlgorithmEnum& getByName(const char* name); | | AlgorithmEnum& getByName(const char* name); | |
|
| | | | |
| | | /** | |
| | | * Return all names of all currently stored AlgorithmEnums | |
| | | * | |
| | | * @return | |
| | | * A C++ std::list of C++ std::strings that contain the names. | |
| | | */ | |
| std::list<std::string>* getAllNames(); | | std::list<std::string>* getAllNames(); | |
|
| | | | |
| | | /** | |
| | | * Get the number of currently stored AlgorithmEnums | |
| | | * | |
| | | * @return | |
| | | * The number of currently stored AlgorithmEnums | |
| | | */ | |
| int getSize(); | | int getSize(); | |
|
| | | | |
| | | /** | |
| | | * Get the AlgoTypes to which this EnumBase belongs. | |
| | | * | |
| | | * @return | |
| | | * The AlgoTypes of this EnumBase. | |
| | | * @see AlgoTypes. | |
| | | */ | |
| AlgoTypes getAlgoType(); | | AlgoTypes getAlgoType(); | |
|
| | | | |
| | | /** | |
| | | * Return the AlgorithmEnum by its ordinal number | |
| | | * | |
| | | * @param ord | |
| | | * The ordinal number of the AlgorithmEnum. | |
| | | * @return | |
| | | * The AlgorithmEnum if found, an invalid Algorithm otherwise. | |
| | | */ | |
| AlgorithmEnum& getByOrdinal(int ord); | | AlgorithmEnum& getByOrdinal(int ord); | |
|
| | | | |
| | | /** | |
| | | * Get the ordinal number of an AlgorithmEnum | |
| | | * | |
| | | * @param algo | |
| | | * Return toe ordinal numer of this AlgorithmEnum. | |
| | | * | |
| | | * @return | |
| | | * Return the ordinal number of this AlgorithmEnum if found, | |
| | | * -1 otherwise. | |
| | | */ | |
| int getOrdinal(AlgorithmEnum& algo); | | int getOrdinal(AlgorithmEnum& algo); | |
| | | | |
| protected: | | protected: | |
| EnumBase(AlgoTypes algo); | | EnumBase(AlgoTypes algo); | |
|
| | | ~EnumBase(); | |
| void insert(const char* name); | | void insert(const char* name); | |
| | | | |
| private: | | private: | |
| AlgoTypes algoType; | | AlgoTypes algoType; | |
| std::vector <AlgorithmEnum* > algos; | | std::vector <AlgorithmEnum* > algos; | |
| }; | | }; | |
| | | | |
| /** | | /** | |
| * The enumaration subclasses that contain the supported algorithm enumerat
ions. | | * The enumaration subclasses that contain the supported algorithm enumerat
ions. | |
| */ | | */ | |
| | | | |
| class HashEnum : public EnumBase { | | class HashEnum : public EnumBase { | |
| public: | | public: | |
| HashEnum(); | | HashEnum(); | |
|
| | | ~HashEnum(); | |
| }; | | }; | |
| | | | |
| class SymCipherEnum : public EnumBase { | | class SymCipherEnum : public EnumBase { | |
| public: | | public: | |
| SymCipherEnum(); | | SymCipherEnum(); | |
|
| | | ~SymCipherEnum(); | |
| }; | | }; | |
| | | | |
| class PubKeyEnum : public EnumBase { | | class PubKeyEnum : public EnumBase { | |
| public: | | public: | |
| PubKeyEnum(); | | PubKeyEnum(); | |
|
| | | ~PubKeyEnum(); | |
| }; | | }; | |
| | | | |
| class SasTypeEnum : public EnumBase { | | class SasTypeEnum : public EnumBase { | |
| public: | | public: | |
| SasTypeEnum(); | | SasTypeEnum(); | |
|
| | | ~SasTypeEnum(); | |
| }; | | }; | |
| | | | |
| class AuthLengthEnum : public EnumBase { | | class AuthLengthEnum : public EnumBase { | |
| public: | | public: | |
| AuthLengthEnum(); | | AuthLengthEnum(); | |
|
| | | ~AuthLengthEnum(); | |
| }; | | }; | |
| | | | |
| extern HashEnum zrtpHashes; | | extern HashEnum zrtpHashes; | |
| extern SymCipherEnum zrtpSymCiphers; | | extern SymCipherEnum zrtpSymCiphers; | |
| extern PubKeyEnum zrtpPubKeys; | | extern PubKeyEnum zrtpPubKeys; | |
| extern SasTypeEnum zrtpSasTypes; | | extern SasTypeEnum zrtpSasTypes; | |
| extern AuthLengthEnum zrtpAuthLengths; | | extern AuthLengthEnum zrtpAuthLengths; | |
| | | | |
| /** | | /** | |
| * ZRTP configuration data. | | * ZRTP configuration data. | |
| | | | |
| skipping to change at line 179 | | skipping to change at line 296 | |
| void setMandatoryOnly(); | | void setMandatoryOnly(); | |
| | | | |
| /** | | /** | |
| * Clear all configuration data. | | * Clear all configuration data. | |
| * | | * | |
| * The functions clears all configuration data. | | * The functions clears all configuration data. | |
| */ | | */ | |
| void clear(); | | void clear(); | |
| | | | |
| /** | | /** | |
|
| * Add a hash algorithm to configuration data. | | * Add an algorithm to configuration data. | |
| * | | * | |
| * Adds the specified algorithm to the configuration data. | | * Adds the specified algorithm to the configuration data. | |
| * If no free configuration data slot is available the | | * If no free configuration data slot is available the | |
|
| * function does not add the algorithm and return zero. The | | * function does not add the algorithm and returns -1. The | |
| * methods appends the algorithm to the existing algorithms. | | * methods appends the algorithm to the existing algorithms. | |
| * | | * | |
| * @param algoType | | * @param algoType | |
| * Specifies which algorithm type to select | | * Specifies which algorithm type to select | |
| * @param algo | | * @param algo | |
| * The enumeration of the algorithm to add. | | * The enumeration of the algorithm to add. | |
| * @return | | * @return | |
|
| * Number of free configuration data slots. | | * Number of free configuration data slots or -1 on error | |
| */ | | */ | |
| int32_t addAlgo(AlgoTypes algoType, AlgorithmEnum& algo); | | int32_t addAlgo(AlgoTypes algoType, AlgorithmEnum& algo); | |
| | | | |
| /** | | /** | |
|
| * Add a algorithm to configuration data. | | * Add an algorithm to configuration data at given index. | |
| * | | * | |
|
| * Adds the specified algorithm to the configuration data. | | * Adds the specified algorithm to the configuration data vector | |
| * If no free configuration data slot is available the | | * at a given index. If the index is larger than the actual size | |
| * function does not add the algorithm and return zero. | | * of the configuration vector the method just appends the algorithm. | |
| * | | * | |
| * @param algoType | | * @param algoType | |
| * Specifies which algorithm type to select | | * Specifies which algorithm type to select | |
| * @param algo | | * @param algo | |
| * The enumeration of the algorithm to add. | | * The enumeration of the algorithm to add. | |
| * @param index | | * @param index | |
| * The index where to add the algorihm | | * The index where to add the algorihm | |
| * @return | | * @return | |
|
| * Number of free configuration data slots. | | * Number of free configuration data slots or -1 on error | |
| */ | | */ | |
| int32_t addAlgoAt(AlgoTypes algoType, AlgorithmEnum& algo, int32_t inde
x); | | int32_t addAlgoAt(AlgoTypes algoType, AlgorithmEnum& algo, int32_t inde
x); | |
| | | | |
| /** | | /** | |
| * Remove a algorithm from configuration data. | | * Remove a algorithm from configuration data. | |
| * | | * | |
| * Removes the specified algorithm from configuration data. If | | * Removes the specified algorithm from configuration data. If | |
| * the algorithm was not configured previously the function does | | * the algorithm was not configured previously the function does | |
| * not modify the configuration data and returns the number of | | * not modify the configuration data and returns the number of | |
| * free configuration data slots. | | * free configuration data slots. | |
| | | | |
| skipping to change at line 312 | | skipping to change at line 429 | |
| void setSasSignature(bool yesNo); | | void setSasSignature(bool yesNo); | |
| | | | |
| /** | | /** | |
| * Check status of SAS signature processing. | | * Check status of SAS signature processing. | |
| * | | * | |
| * @return | | * @return | |
| * Returns true if certificate processing is enabled. | | * Returns true if certificate processing is enabled. | |
| */ | | */ | |
| bool isSasSignature(); | | bool isSasSignature(); | |
| | | | |
|
| | | /// Helper function to print some internal data | |
| void printConfiguredAlgos(AlgoTypes algoTyp); | | void printConfiguredAlgos(AlgoTypes algoTyp); | |
| | | | |
| private: | | private: | |
| std::vector<AlgorithmEnum* > hashes; | | std::vector<AlgorithmEnum* > hashes; | |
| std::vector<AlgorithmEnum* > symCiphers; | | std::vector<AlgorithmEnum* > symCiphers; | |
| std::vector<AlgorithmEnum* > publicKeyAlgos; | | std::vector<AlgorithmEnum* > publicKeyAlgos; | |
| std::vector<AlgorithmEnum* > sasTypes; | | std::vector<AlgorithmEnum* > sasTypes; | |
| std::vector<AlgorithmEnum* > authLengths; | | std::vector<AlgorithmEnum* > authLengths; | |
| | | | |
| bool enableTrustedMitM; | | bool enableTrustedMitM; | |
| | | | |
| skipping to change at line 339 | | skipping to change at line 457 | |
| bool containsAlgo(std::vector<AlgorithmEnum* >& a, AlgorithmEnum& algo)
; | | bool containsAlgo(std::vector<AlgorithmEnum* >& a, AlgorithmEnum& algo)
; | |
| std::vector<AlgorithmEnum* >& getEnum(AlgoTypes algoType); | | std::vector<AlgorithmEnum* >& getEnum(AlgoTypes algoType); | |
| | | | |
| void printConfiguredAlgos(std::vector<AlgorithmEnum* >& a); | | void printConfiguredAlgos(std::vector<AlgorithmEnum* >& a); | |
| | | | |
| protected: | | protected: | |
| | | | |
| public: | | public: | |
| }; | | }; | |
| | | | |
|
| | | /** | |
| | | * @} | |
| | | */ | |
| #endif | | #endif | |
| | | | |
| /** EMACS ** | | /** EMACS ** | |
| * Local variables: | | * Local variables: | |
| * mode: c++ | | * mode: c++ | |
| * c-default-style: ellemtel | | * c-default-style: ellemtel | |
| * c-basic-offset: 4 | | * c-basic-offset: 4 | |
| * End: | | * End: | |
| */ | | */ | |
| | | | |
End of changes. 28 change blocks. |
| 16 lines changed or deleted | | 139 lines changed or added | |
|