Commit c6c2e6db authored by johan's avatar johan

Improve message callback

- allow passing also a string
- add peer version obsolete message
+ add cache mismatch information in the secrets structure
parent 8e9b45db
......@@ -114,6 +114,7 @@ typedef struct bzrtpSrtpSecrets_struct {
uint8_t hashAlgo; /**< The hash algo selected during ZRTP negotiation */
uint8_t keyAgreementAlgo; /**< The key agreement algo selected during ZRTP negotiation */
uint8_t sasAlgo; /**< The SAS rendering algo selected during ZRTP negotiation */
uint8_t cacheMismatch; /**< Flag set to 1 in case of ZRTP cache mismatch, may occurs only on first channel(the one computing SAS) */
} bzrtpSrtpSecrets_t;
......@@ -124,7 +125,8 @@ typedef struct bzrtpSrtpSecrets_struct {
#define BZRTP_MESSAGE_DEBUG 0x03
/* define message codes */
#define BZRTP_MESSAGE_CACHEMISMATCH 0x01
#define BZRTP_MESSAGE_CACHEMISMATCH 0x01
#define BZRTP_MESSAGE_PEERVERSIONOBSOLETE 0x02
/**
* Function pointer used by bzrtp to free memory allocated by callbacks.
......@@ -135,7 +137,7 @@ typedef void (*zrtpFreeBuffer_callback)(void *);
*/
typedef struct bzrtpCallbacks_struct {
/* messaging status and warnings */
int (* bzrtp_statusMessage)(void *clientData, const uint8_t messageLevel, const uint8_t messageId); /**< Sending messages to caller: error, warnings, logs */
int (* bzrtp_statusMessage)(void *clientData, const uint8_t messageLevel, const uint8_t messageId, const char *messageString); /**< Sending messages to caller: error, warnings, logs, the messageString can be NULL or a NULL terminated string */
int bzrtp_messageLevel; /**< Filter calls to this callback to levels inferiors to this setting (BZRTP_MESSAGE_ERROR, BZRTP_MESSAGE_WARNING, BZRTP_MESSAGE_LOG, BZRTP_MESSAGE_DEBUG )*/
/* sending packets */
......
......@@ -96,7 +96,7 @@ typedef struct bzrtpPacket_struct {
*/
typedef struct bzrtpHelloMessage_struct {
uint8_t version[4]; /**< a string defining the current version, shall be 1.10 */
uint8_t clientIdentifier[16]; /**< a string identifing the vendor and release of ZRTP software */
uint8_t clientIdentifier[17]; /**< a string identifing the vendor and release of ZRTP software, actual content is 16, but last character forced to '\0' */
uint8_t H3[32]; /**< the hash image H3 (256 bits) */
uint8_t ZID[12]; /**< unique identifier for ZRTP endpoint (96 bits) */
uint8_t S; /**< The signature-capable flag. If signatures are not supported, the (S) flag MUST be set to zero (1 bit) */
......
......@@ -1052,6 +1052,7 @@ static int bzrtp_initChannelContext(bzrtpContext_t *zrtpContext, bzrtpChannelCon
zrtpChannelContext->srtpSecrets.hashAlgo = ZRTP_UNSET_ALGO;
zrtpChannelContext->srtpSecrets.keyAgreementAlgo = ZRTP_UNSET_ALGO;
zrtpChannelContext->srtpSecrets.sasAlgo = ZRTP_UNSET_ALGO;
zrtpChannelContext->srtpSecrets.cacheMismatch = 0;
/* create the Hello packet and store it */
helloPacket = bzrtp_createZrtpPacket(zrtpContext, zrtpChannelContext, MSGTYPE_HELLO, &retval);
......
......@@ -232,6 +232,7 @@ int bzrtp_packetParser(bzrtpContext_t *zrtpContext, bzrtpChannelContext_t *zrtpC
memcpy(messageData->version, messageContent, 4);
messageContent +=4;
memcpy(messageData->clientIdentifier, messageContent, 16);
messageData->clientIdentifier[16] = '\0'; /* be sure the clientIdentifier is a NULL terminated string */
messageContent +=16;
memcpy(messageData->H3, messageContent, 32);
messageContent +=32;
......@@ -1135,6 +1136,7 @@ bzrtpPacket_t *bzrtp_createZrtpPacket(bzrtpContext_t *zrtpContext, bzrtpChannelC
/* initialise some fields using zrtp context data */
memcpy(zrtpHelloMessage->version, ZRTP_VERSION, 4);
strncpy((char*)zrtpHelloMessage->clientIdentifier, ZRTP_CLIENT_IDENTIFIER, 16);
zrtpHelloMessage->clientIdentifier[16]='\0'; /* be sure the clientIdentifier filed is a NULL terminated string */
memcpy(zrtpHelloMessage->H3, zrtpChannelContext->selfH[3], 32);
memcpy(zrtpHelloMessage->ZID, zrtpContext->selfZID, 12);
/* set all S,M,P flags to zero as we're not able to verify signatures, we're not a PBX(TODO: implement?), we're not passive */
......
......@@ -557,7 +557,7 @@ int state_keyAgreement_sendingCommit(bzrtpEvent_t event) {
/* if we have a statusMessage callback, use it to warn user */
if (zrtpContext->zrtpCallbacks.bzrtp_statusMessage!=NULL && zrtpContext->zrtpCallbacks.bzrtp_messageLevel>=BZRTP_MESSAGE_ERROR) { /* use error level as this one MUST (RFC section 4.3.2) be warned */
zrtpContext->zrtpCallbacks.bzrtp_statusMessage(zrtpChannelContext->clientData, BZRTP_MESSAGE_ERROR, BZRTP_MESSAGE_CACHEMISMATCH);
zrtpContext->zrtpCallbacks.bzrtp_statusMessage(zrtpChannelContext->clientData, BZRTP_MESSAGE_ERROR, BZRTP_MESSAGE_CACHEMISMATCH, NULL);
}
}
......@@ -852,7 +852,7 @@ int state_keyAgreement_responderSendingDHPart1(bzrtpEvent_t event) {
/* if we have a statusMessage callback, use it to warn user */
if (zrtpContext->zrtpCallbacks.bzrtp_statusMessage!=NULL && zrtpContext->zrtpCallbacks.bzrtp_messageLevel>=BZRTP_MESSAGE_ERROR) { /* use error level as this one MUST (RFC section 4.3.2) be warned */
zrtpContext->zrtpCallbacks.bzrtp_statusMessage(zrtpChannelContext->clientData, BZRTP_MESSAGE_ERROR, BZRTP_MESSAGE_CACHEMISMATCH);
zrtpContext->zrtpCallbacks.bzrtp_statusMessage(zrtpChannelContext->clientData, BZRTP_MESSAGE_ERROR, BZRTP_MESSAGE_CACHEMISMATCH, NULL);
}
}
......@@ -1665,8 +1665,11 @@ int bzrtp_responseToHelloMessage(bzrtpContext_t *zrtpContext, bzrtpChannelContex
/* If not, it may be earlier version or an other library, so compute the exported keys old style just in case we need them */
if (strncmp(ZRTP_CLIENT_IDENTIFIERv1_1, (char *)helloMessage->clientIdentifier, 16)==0) {
zrtpContext->peerBzrtpVersion=10100;
} else { /* this is not version 1.1 of bzrtp, set it to 1.0 */
} else { /* this is not version 1.1 of bzrtp(can be another zrtp lib or and older version of bzrtp), set it to 1.0 */
zrtpContext->peerBzrtpVersion=10000;
if (zrtpContext->zrtpCallbacks.bzrtp_statusMessage!=NULL && zrtpContext->zrtpCallbacks.bzrtp_messageLevel>=BZRTP_MESSAGE_LOG) { /* use error level as this one MUST (RFC section 4.3.2) be warned */
zrtpContext->zrtpCallbacks.bzrtp_statusMessage(zrtpChannelContext->clientData, BZRTP_MESSAGE_LOG, BZRTP_MESSAGE_PEERVERSIONOBSOLETE, (const char *)helloMessage->clientIdentifier);
}
}
/* now select mode according to context */
......@@ -2132,6 +2135,11 @@ int bzrtp_deriveSrtpKeysFromS0(bzrtpContext_t *zrtpContext, bzrtpChannelContext_
zrtpChannelContext->srtpSecrets.sas = (char *)malloc((zrtpChannelContext->sasLength)*sizeof(char)); /*this shall take in account the selected representation algo for SAS */
zrtpChannelContext->sasFunction(sasValue, zrtpChannelContext->srtpSecrets.sas, zrtpChannelContext->sasLength);
/* set also the cache mismtach flag in srtpSecrets structure, may occurs only on the first channel */
if (zrtpContext->cacheMismatchFlag!=0) {
zrtpChannelContext->srtpSecrets.cacheMismatch = 1;
}
}
return 0;
......
......@@ -151,7 +151,7 @@ int getSAS(void *clientData, bzrtpSrtpSecrets_t *secrets, int32_t pvs) {
return 0;
}
int getMessage(void *clientData, const uint8_t level, const uint8_t message) {
int getMessage(void *clientData, const uint8_t level, const uint8_t message, const char *messageString) {
/* get the client context */
clientContext_t *clientContext = (clientContext_t *)clientData;
if (level == BZRTP_MESSAGE_ERROR && message == BZRTP_MESSAGE_CACHEMISMATCH) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment