Commit d177fb87 authored by johan's avatar johan
Browse files

Add interfaces functions to send SRTP keys to the client.

And bug fixes
First functional version(not fully compliant with the RFC yet)
parent a6abf3e3
......@@ -26,7 +26,6 @@
typedef struct bzrtpContext_struct bzrtpContext_t;
#include <stdint.h>
/**
* Some defines used internally by zrtp but also needed by client to interpretate the cipher block and auth tag algorithms used by srtp */
#define ZRTP_UNSET_ALGO 0x00
......@@ -109,6 +108,8 @@ __attribute__ ((visibility ("default"))) void bzrtp_destroyBzrtpContext(bzrtpCon
#define ZRTP_CALLBACK_SETCACHEPOSITION 0x0104
#define ZRTP_CALLBACK_GETCACHEPOSITION 0x0108
#define ZRTP_CALLBACK_SENDDATA 0x0110
#define ZRTP_CALLBACK_SRTPSECRETSAVAILABLE 0x0120
#define ZRTP_CALLBACK_STARTSRTPSESSION 0x0140
/**
* @brief Allocate a function pointer to the callback function identified by his id
* @param[in/out] context The zrtp context to set the callback function
......@@ -165,6 +166,17 @@ __attribute__ ((visibility ("default"))) int bzrtp_startChannelEngine(bzrtpConte
__attribute__ ((visibility ("default"))) int bzrtp_iterate(bzrtpContext_t *zrtpContext, uint32_t selfSSRC, uint64_t timeReference);
/**
* @brief Return the status of current channel, 1 if SRTP secrets have been computed and confirmed, 0 otherwise
*
* @param[in] zrtpContext The ZRTP context hosting the channel
* @param[in] selfSSRC The SSRC identifying the channel
*
* @return 0 if this channel is not ready to secure SRTP communication, 1 if it is ready
*/
__attribute__ ((visibility ("default"))) int bzrtp_isSecure(bzrtpContext_t *zrtpContext, uint32_t selfSSRC);
/**
* @brief Process a received message
*
......
......@@ -108,6 +108,10 @@ typedef struct zrtpCallbacks_struct {
/* sending packets */
int (* bzrtp_sendData)(void *clientData, uint8_t *packetString, uint16_t packetLength); /**< Send a ZRTP packet to peer. Shall return 0 on success */
/* dealing with SRTP session */
int (* bzrtp_srtpSecretsAvailable)(void *clientData, bzrtpSrtpSecrets_t *srtpSecrets); /**< Send the srtp secrets to the client, it may wait for the end of ZRTP process before using it */
int (* bzrtp_startSrtpSession)(void *clientData, char* sas, int32_t verified); /**< ZRTP process ended well, client is given the SAS and may start his SRTP session if not done when calling srtpSecretsAvailable */
} zrtpCallbacks_t;
/**
......@@ -129,6 +133,9 @@ typedef struct bzrtpChannelContext_struct {
uint8_t peerSSRCAssociated; /**< true if this channel is already associated with a peer SSRC, false otherwise */
/* USELESS?? */
/* flags */
uint8_t isSecure; /**< This flag is set to 1 when the ZRTP negociation ends and SRTP secrets are generated and confirmed for this channel */
/* Hash chains, self is generated at channel context init */
uint8_t selfH[4][32]; /**< Store self 256 bits Hash images H0-H3 used to generate messages MAC */
uint8_t peerH[4][32]; /**< Store peer 256 bits Hash images H0-H3 used to check messages authenticity */
......@@ -172,6 +179,8 @@ typedef struct bzrtpChannelContext_struct {
uint8_t initiatorAuxsecretID[8]; /**< initiator auxiliary secret Hash */
uint8_t responderAuxsecretID[8]; /**< responder auxiliary secret Hash */
} bzrtpChannelContext_t;
/**
......
......@@ -69,6 +69,9 @@ bzrtpContext_t *bzrtp_createBzrtpContext(uint32_t selfSSRC)
context->zrtpCallbacks.bzrtp_writeCache = NULL;
context->zrtpCallbacks.bzrtp_setCachePosition = NULL;
context->zrtpCallbacks.bzrtp_getCachePosition = NULL;
context->zrtpCallbacks.bzrtp_sendData = NULL;
context->zrtpCallbacks.bzrtp_srtpSecretsAvailable = NULL;
context->zrtpCallbacks.bzrtp_startSrtpSession = NULL;
/* allocate 1 channel context, set all the others pointers to NULL */
context->channelContext[0] = (bzrtpChannelContext_t *)malloc(sizeof(bzrtpChannelContext_t));
......@@ -182,6 +185,12 @@ int bzrtp_setCallback(bzrtpContext_t *context, int (*functionPointer)(), uint16_
case ZRTP_CALLBACK_SENDDATA:
context->zrtpCallbacks.bzrtp_sendData = (int (*)(void *, uint8_t *, uint16_t))functionPointer;
break;
case ZRTP_CALLBACK_SRTPSECRETSAVAILABLE:
context->zrtpCallbacks.bzrtp_srtpSecretsAvailable = (int (*)(void *, bzrtpSrtpSecrets_t *))functionPointer;
break;
case ZRTP_CALLBACK_STARTSRTPSESSION:
context->zrtpCallbacks.bzrtp_startSrtpSession = (int (*)(void *, char*, int32_t))functionPointer;
break;
default:
return BZRTP_ERROR_INVALIDCALLBACKID;
break;
......@@ -231,7 +240,6 @@ int bzrtp_addChannel(bzrtpContext_t *zrtpContext, uint32_t selfSSRC) {
/* attach the created channel to the ZRTP context */
zrtpContext->channelContext[i] = zrtpChannelContext;
printf ("Added channel index %d\n", i);
return 0;
......@@ -285,6 +293,7 @@ int bzrtp_startChannelEngine(bzrtpContext_t *zrtpContext, uint32_t selfSSRC) {
int bzrtp_iterate(bzrtpContext_t *zrtpContext, uint32_t selfSSRC, uint64_t timeReference) {
/* get channel context */
bzrtpChannelContext_t *zrtpChannelContext = getChannelContext(zrtpContext, selfSSRC);
fflush(NULL);
if (zrtpChannelContext == NULL) {
return BZRTP_ERROR_INVALIDCONTEXT;
......@@ -295,6 +304,7 @@ int bzrtp_iterate(bzrtpContext_t *zrtpContext, uint32_t selfSSRC, uint64_t timeR
if (zrtpChannelContext->timer.status == BZRTP_TIMER_ON) {
if (zrtpChannelContext->timer.firingTime<=timeReference) { /* we must trig the timer */
zrtpChannelContext->timer.firingCount++;
/* create a timer event */
......@@ -362,7 +372,28 @@ int bzrtp_processMessage(bzrtpContext_t *zrtpContext, uint32_t selfSSRC, uint8_t
event.zrtpContext = zrtpContext;
event.zrtpChannelContext = zrtpChannelContext;
return zrtpChannelContext->stateMachine(event);
int retval = zrtpChannelContext->stateMachine(event);
return retval;
}
/*
* @brief Return the status of current channel, 1 if SRTP secrets have been computed and confirmed, 0 otherwise
*
* @param[in] zrtpContext The ZRTP context hosting the channel
* @param[in] selfSSRC The SSRC identifying the channel
*
* @return 0 if this channel is not ready to secure SRTP communication, 1 if it is ready
*/
int bzrtp_isSecure(bzrtpContext_t *zrtpContext, uint32_t selfSSRC) {
/* get channel context */
bzrtpChannelContext_t *zrtpChannelContext = getChannelContext(zrtpContext, selfSSRC);
if (zrtpChannelContext == NULL) {
return 0; /* can't find the channel, return it as non secure */
}
return zrtpChannelContext->isSecure;
}
......@@ -418,6 +449,9 @@ int bzrtp_initChannelContext(bzrtpContext_t *zrtpContext, bzrtpChannelContext_t
zrtpChannelContext->selfSSRC = selfSSRC;
/* flags */
zrtpChannelContext->isSecure = 0;
/* initialise as initiator, switch to responder later if needed */
zrtpChannelContext->role = INITIATOR;
......
......@@ -124,8 +124,6 @@ int state_discovery_init(bzrtpEvent_t event) {
/* if we have a HelloACK packet, stop the timer and set next state to state_discovery_waitingForHello */
if (zrtpPacket->messageType == MSGTYPE_HELLOACK) {
printf ("Receive a Hello ACK packet\n");
/* stop the timer */
zrtpChannelContext->timer.status = BZRTP_TIMER_OFF;
......@@ -157,8 +155,10 @@ int state_discovery_init(bzrtpEvent_t event) {
/* We must resend a Hello packet */
retval = bzrtp_packetUpdateSequenceNumber(zrtpChannelContext->selfPackets[HELLO_MESSAGE_STORE_ID], zrtpChannelContext->selfSequenceNumber);
if (retval == 0) {
zrtpContext->zrtpCallbacks.bzrtp_sendData(zrtpChannelContext->clientData, zrtpChannelContext->selfPackets[HELLO_MESSAGE_STORE_ID]->packetString, zrtpChannelContext->selfPackets[HELLO_MESSAGE_STORE_ID]->messageLength+ZRTP_PACKET_OVERHEAD);
zrtpChannelContext->selfSequenceNumber++;
if (zrtpContext->zrtpCallbacks.bzrtp_sendData!=NULL) {
zrtpContext->zrtpCallbacks.bzrtp_sendData(zrtpChannelContext->clientData, zrtpChannelContext->selfPackets[HELLO_MESSAGE_STORE_ID]->packetString, zrtpChannelContext->selfPackets[HELLO_MESSAGE_STORE_ID]->messageLength+ZRTP_PACKET_OVERHEAD);
zrtpChannelContext->selfSequenceNumber++;
}
} else {
return retval;
}
......@@ -184,7 +184,6 @@ int state_discovery_waitingForHello(bzrtpEvent_t event) {
bzrtpContext_t *zrtpContext = event.zrtpContext;
bzrtpChannelContext_t *zrtpChannelContext = event.zrtpChannelContext;
printf("Entering waiting for Hello state\n");
/*** Manage the first call to this function ***/
/* no init event for this state */
......@@ -258,7 +257,6 @@ int state_discovery_waitingForHelloAck(bzrtpEvent_t event) {
bzrtpContext_t *zrtpContext = event.zrtpContext;
bzrtpChannelContext_t *zrtpChannelContext = event.zrtpChannelContext;
printf("Enter waiting for Hello Ack state\n");
int retval;
/*** Manage message event ***/
if (event.eventType == BZRTP_EVENT_MESSAGE) {
......@@ -277,17 +275,21 @@ int state_discovery_waitingForHelloAck(bzrtpEvent_t event) {
/* We do not need to parse the packet if it is an Hello one as it shall be the duplicate of one we received earlier */
/* we must check it is the same we initially received, and send a HelloACK */
if (zrtpPacket->messageType == MSGTYPE_HELLO) {
if (memcmp(zrtpPacket->packetString+ZRTP_PACKET_HEADER_LENGTH, zrtpChannelContext->peerPackets[HELLO_MESSAGE_STORE_ID]+ZRTP_PACKET_HEADER_LENGTH, zrtpChannelContext->peerPackets[HELLO_MESSAGE_STORE_ID]->messageLength) != 0) {
if (zrtpChannelContext->peerPackets[HELLO_MESSAGE_STORE_ID]->messageLength != zrtpPacket->messageLength) {
bzrtp_freeZrtpPacket(zrtpPacket);
return BZRTP_ERROR_UNMATCHINGPACKETREPETITION;
}
if (memcmp(event.bzrtpPacketString+ZRTP_PACKET_HEADER_LENGTH, zrtpChannelContext->peerPackets[HELLO_MESSAGE_STORE_ID]+ZRTP_PACKET_HEADER_LENGTH, zrtpChannelContext->peerPackets[HELLO_MESSAGE_STORE_ID]->messageLength) != 0) {
bzrtp_freeZrtpPacket(zrtpPacket);
return BZRTP_ERROR_UNMATCHINGPACKETREPETITION;
}
/* free the incoming packet */
bzrtp_freeZrtpPacket(zrtpPacket);
/* incoming packet is valid, set the sequence Number in channel context */
zrtpChannelContext->peerSequenceNumber = zrtpPacket->sequenceNumber;
/* free the incoming packet */
bzrtp_freeZrtpPacket(zrtpPacket);
/* build and send the HelloACK packet */
bzrtpPacket_t *helloACKPacket = bzrtp_createZrtpPacket(zrtpContext, zrtpChannelContext, MSGTYPE_HELLOACK, &retval);
if (retval != 0) {
......@@ -396,7 +398,6 @@ int state_discovery_waitingForHelloAck(bzrtpEvent_t event) {
*
*/
int state_keyAgreement_sendingCommit(bzrtpEvent_t event) {
printf ("Enter Sending Commit state\n");
/* get the contextes from the event */
bzrtpContext_t *zrtpContext = event.zrtpContext;
......@@ -485,7 +486,6 @@ int state_keyAgreement_sendingCommit(bzrtpEvent_t event) {
/* we have a DHPart1 - so we are initiator in DHM mode - stop timer and go to state_keyAgreement_initiatorSendingDHPart2 */
if(zrtpPacket->messageType == MSGTYPE_DHPART1) {
printf("Here is the DHPart1 we're looking for\n");
/* stop the timer */
zrtpChannelContext->timer.status = BZRTP_TIMER_OFF;
......@@ -526,11 +526,11 @@ int state_keyAgreement_sendingCommit(bzrtpEvent_t event) {
zrtpChannelContext->peerPackets[DHPART_MESSAGE_STORE_ID] = zrtpPacket;
/* Compute the shared DH secret */
zrtpContext->DHMContext->peer = dhPart1Message->pv;
zrtpContext->DHMContext->peer = (uint8_t *)malloc(zrtpChannelContext->keyAgreementLength*sizeof(uint8_t));
memcpy (zrtpContext->DHMContext->peer, dhPart1Message->pv, zrtpChannelContext->keyAgreementLength);
bzrtpCrypto_DHMComputeSecret(zrtpContext->DHMContext, (int (*)(void *, uint8_t *, uint16_t))bzrtpCrypto_getRandom, (void *)zrtpContext->RNGContext);
/* Derive the s0 key */
printf("Sending commit compute s0\n");
bzrtp_computeS0DHMMode(zrtpContext, zrtpChannelContext);
/* set next state to state_keyAgreement_initiatorSendingDHPart2 */
......@@ -648,7 +648,6 @@ int state_keyAgreement_sendingCommit(bzrtpEvent_t event) {
*
*/
int state_keyAgreement_responderSendingDHPart1(bzrtpEvent_t event) {
printf ("Enter responder sending DHPart1 state\n");
/* get the contextes from the event */
bzrtpContext_t *zrtpContext = event.zrtpContext;
......@@ -687,17 +686,21 @@ int state_keyAgreement_responderSendingDHPart1(bzrtpEvent_t event) {
/* we have a Commit, check it is the same as received previously and resend the DHPart1 packet */
if(zrtpPacket->messageType == MSGTYPE_COMMIT) {
if (memcmp(zrtpPacket->packetString+ZRTP_PACKET_HEADER_LENGTH, zrtpChannelContext->peerPackets[COMMIT_MESSAGE_STORE_ID]+ZRTP_PACKET_HEADER_LENGTH, zrtpChannelContext->peerPackets[COMMIT_MESSAGE_STORE_ID]->messageLength) != 0) {
if (zrtpChannelContext->peerPackets[COMMIT_MESSAGE_STORE_ID]->messageLength != zrtpPacket->messageLength) {
bzrtp_freeZrtpPacket(zrtpPacket);
return BZRTP_ERROR_UNMATCHINGPACKETREPETITION;
}
if (memcmp(event.bzrtpPacketString+ZRTP_PACKET_HEADER_LENGTH, zrtpChannelContext->peerPackets[COMMIT_MESSAGE_STORE_ID]+ZRTP_PACKET_HEADER_LENGTH, zrtpChannelContext->peerPackets[COMMIT_MESSAGE_STORE_ID]->messageLength) != 0) {
bzrtp_freeZrtpPacket(zrtpPacket);
return BZRTP_ERROR_UNMATCHINGPACKETREPETITION;
}
/* free the incoming packet */
bzrtp_freeZrtpPacket(zrtpPacket);
/* incoming packet is valid, set the sequence Number in channel context */
zrtpChannelContext->peerSequenceNumber = zrtpPacket->sequenceNumber;
/* free the incoming packet */
bzrtp_freeZrtpPacket(zrtpPacket);
/* update and send the DHPart1 packet */
retval = bzrtp_packetUpdateSequenceNumber(zrtpChannelContext->selfPackets[DHPART_MESSAGE_STORE_ID], zrtpChannelContext->selfSequenceNumber);
if (retval != 0) {
......@@ -798,8 +801,6 @@ int state_keyAgreement_responderSendingDHPart1(bzrtpEvent_t event) {
*
*/
int state_keyAgreement_initiatorSendingDHPart2(bzrtpEvent_t event) {
printf ("Enter initiator sending DHPart2 state\n");
int retval;
/* get the contextes from the event */
......@@ -845,17 +846,22 @@ int state_keyAgreement_initiatorSendingDHPart2(bzrtpEvent_t event) {
/* we have DHPart1 packet, just check it is the same we received previously and do nothing */
if (zrtpPacket->messageType == MSGTYPE_DHPART1) {
if (memcmp(zrtpPacket->packetString+ZRTP_PACKET_HEADER_LENGTH, zrtpChannelContext->peerPackets[DHPART_MESSAGE_STORE_ID]+ZRTP_PACKET_HEADER_LENGTH, zrtpChannelContext->peerPackets[DHPART_MESSAGE_STORE_ID]->messageLength) != 0) {
if (zrtpChannelContext->peerPackets[DHPART_MESSAGE_STORE_ID]->messageLength != zrtpPacket->messageLength) {
bzrtp_freeZrtpPacket(zrtpPacket);
return BZRTP_ERROR_UNMATCHINGPACKETREPETITION;
}
if (memcmp(event.bzrtpPacketString+ZRTP_PACKET_HEADER_LENGTH, zrtpChannelContext->peerPackets[DHPART_MESSAGE_STORE_ID]+ZRTP_PACKET_HEADER_LENGTH, zrtpChannelContext->peerPackets[DHPART_MESSAGE_STORE_ID]->messageLength) != 0) {
bzrtp_freeZrtpPacket(zrtpPacket);
return BZRTP_ERROR_UNMATCHINGPACKETREPETITION;
}
/* free the incoming packet */
bzrtp_freeZrtpPacket(zrtpPacket);
/* incoming packet is valid, set the sequence Number in channel context */
zrtpChannelContext->peerSequenceNumber = zrtpPacket->sequenceNumber;
/* free the incoming packet */
bzrtp_freeZrtpPacket(zrtpPacket);
return 0;
}
......@@ -940,7 +946,6 @@ int state_keyAgreement_initiatorSendingDHPart2(bzrtpEvent_t event) {
*
*/
int state_confirmation_responderSendingConfirm1(bzrtpEvent_t event) {
printf ("Enter responder sending confirm1 state\n");
int retval;
/* get the contextes from the event */
......@@ -1013,17 +1018,21 @@ int state_confirmation_responderSendingConfirm1(bzrtpEvent_t event) {
}
/* Check the commit packet is the same we already had */
if (memcmp(zrtpPacket->packetString+ZRTP_PACKET_HEADER_LENGTH, zrtpChannelContext->peerPackets[COMMIT_MESSAGE_STORE_ID]+ZRTP_PACKET_HEADER_LENGTH, zrtpChannelContext->peerPackets[COMMIT_MESSAGE_STORE_ID]->messageLength) != 0) {
if (zrtpChannelContext->peerPackets[COMMIT_MESSAGE_STORE_ID]->messageLength != zrtpPacket->messageLength) {
bzrtp_freeZrtpPacket(zrtpPacket);
return BZRTP_ERROR_UNMATCHINGPACKETREPETITION;
}
if (memcmp(event.bzrtpPacketString+ZRTP_PACKET_HEADER_LENGTH, zrtpChannelContext->peerPackets[COMMIT_MESSAGE_STORE_ID]+ZRTP_PACKET_HEADER_LENGTH, zrtpChannelContext->peerPackets[COMMIT_MESSAGE_STORE_ID]->messageLength) != 0) {
bzrtp_freeZrtpPacket(zrtpPacket);
return BZRTP_ERROR_UNMATCHINGPACKETREPETITION;
}
/* free the incoming packet */
bzrtp_freeZrtpPacket(zrtpPacket);
/* incoming packet is valid, set the sequence Number in channel context */
zrtpChannelContext->peerSequenceNumber = zrtpPacket->sequenceNumber;
/* free the incoming packet */
bzrtp_freeZrtpPacket(zrtpPacket);
/* update sequence number and resend confirm1 packet */
retval = bzrtp_packetUpdateSequenceNumber(zrtpChannelContext->selfPackets[CONFIRM_MESSAGE_STORE_ID], zrtpChannelContext->selfSequenceNumber);
if (retval!=0) {
......@@ -1036,23 +1045,27 @@ int state_confirmation_responderSendingConfirm1(bzrtpEvent_t event) {
/* We have a DHPart2 packet, check we are in DHM mode, that the DHPart2 is identical to the one we already had and resend the Confirm1 packet */
if (zrtpPacket->messageType == MSGTYPE_DHPART2) {
/* Check we are not DHM mode */
if ((zrtpChannelContext->keyAgreementAlgo == ZRTP_KEYAGREEMENT_Prsh) || (zrtpChannelContext->keyAgreementAlgo != ZRTP_KEYAGREEMENT_Mult)) {
if ((zrtpChannelContext->keyAgreementAlgo == ZRTP_KEYAGREEMENT_Prsh) || (zrtpChannelContext->keyAgreementAlgo == ZRTP_KEYAGREEMENT_Mult)) {
bzrtp_freeZrtpPacket(zrtpPacket);
return BZRTP_PARSER_ERROR_UNEXPECTEDMESSAGE;
}
/* Check the commit packet is the same we already had */
if (memcmp(zrtpPacket->packetString+ZRTP_PACKET_HEADER_LENGTH, zrtpChannelContext->peerPackets[DHPART_MESSAGE_STORE_ID]+ZRTP_PACKET_HEADER_LENGTH, zrtpChannelContext->peerPackets[DHPART_MESSAGE_STORE_ID]->messageLength) != 0) {
/* Check the DHPart2 packet is the same we already had */
if (zrtpChannelContext->peerPackets[DHPART_MESSAGE_STORE_ID]->messageLength != zrtpPacket->messageLength) {
bzrtp_freeZrtpPacket(zrtpPacket);
return BZRTP_ERROR_UNMATCHINGPACKETREPETITION;
}
if (memcmp(event.bzrtpPacketString+ZRTP_PACKET_HEADER_LENGTH, zrtpChannelContext->peerPackets[DHPART_MESSAGE_STORE_ID]+ZRTP_PACKET_HEADER_LENGTH, zrtpChannelContext->peerPackets[DHPART_MESSAGE_STORE_ID]->messageLength) != 0) {
bzrtp_freeZrtpPacket(zrtpPacket);
return BZRTP_ERROR_UNMATCHINGPACKETREPETITION;
}
/* free the incoming packet */
bzrtp_freeZrtpPacket(zrtpPacket);
/* incoming packet is valid, set the sequence Number in channel context */
zrtpChannelContext->peerSequenceNumber = zrtpPacket->sequenceNumber;
/* free the incoming packet */
bzrtp_freeZrtpPacket(zrtpPacket);
/* update sequence number and resend confirm1 packet */
retval = bzrtp_packetUpdateSequenceNumber(zrtpChannelContext->selfPackets[CONFIRM_MESSAGE_STORE_ID], zrtpChannelContext->selfSequenceNumber);
if (retval!=0) {
......@@ -1087,6 +1100,11 @@ int state_confirmation_responderSendingConfirm1(bzrtpEvent_t event) {
return retval;
}
/* send them to the environment */
if (zrtpContext->zrtpCallbacks.bzrtp_srtpSecretsAvailable != NULL) {
zrtpContext->zrtpCallbacks.bzrtp_srtpSecretsAvailable(zrtpChannelContext->clientData, &zrtpChannelContext->srtpSecrets);
}
/* create and send a conf2ACK packet */
bzrtpPacket_t *conf2ACKPacket = bzrtp_createZrtpPacket(zrtpContext, zrtpChannelContext, MSGTYPE_CONF2ACK, &retval);
if (retval!=0) {
......@@ -1141,7 +1159,6 @@ int state_confirmation_responderSendingConfirm1(bzrtpEvent_t event) {
*
*/
int state_confirmation_initiatorSendingConfirm2(bzrtpEvent_t event) {
printf ("Enter initiator sending confirm2 state\n");
int retval;
/* get the contextes from the event */
......@@ -1182,6 +1199,12 @@ int state_confirmation_initiatorSendingConfirm2(bzrtpEvent_t event) {
if (retval!=0) {
return retval;
}
/* send them to the environment */
if (zrtpContext->zrtpCallbacks.bzrtp_srtpSecretsAvailable != NULL) {
zrtpContext->zrtpCallbacks.bzrtp_srtpSecretsAvailable(zrtpChannelContext->clientData, &zrtpChannelContext->srtpSecrets);
}
/* it is the first call to this state function, so we must set the timer for retransmissions */
zrtpChannelContext->timer.status = BZRTP_TIMER_ON;
zrtpChannelContext->timer.firingTime = zrtpContext->timeReference + NON_HELLO_BASE_RETRANSMISSION_STEP;
......@@ -1206,17 +1229,21 @@ int state_confirmation_initiatorSendingConfirm2(bzrtpEvent_t event) {
/* we have confirm1 packet, just check it is the same we received previously and do nothing */
if (zrtpPacket->messageType == MSGTYPE_CONFIRM1) {
if (memcmp(zrtpPacket->packetString+ZRTP_PACKET_HEADER_LENGTH, zrtpChannelContext->peerPackets[CONFIRM_MESSAGE_STORE_ID]+ZRTP_PACKET_HEADER_LENGTH, zrtpChannelContext->peerPackets[CONFIRM_MESSAGE_STORE_ID]->messageLength) != 0) {
if (zrtpChannelContext->peerPackets[CONFIRM_MESSAGE_STORE_ID]->messageLength != zrtpPacket->messageLength) {
bzrtp_freeZrtpPacket(zrtpPacket);
return BZRTP_ERROR_UNMATCHINGPACKETREPETITION;
}
if (memcmp(event.bzrtpPacketString+ZRTP_PACKET_HEADER_LENGTH, zrtpChannelContext->peerPackets[CONFIRM_MESSAGE_STORE_ID]+ZRTP_PACKET_HEADER_LENGTH, zrtpChannelContext->peerPackets[CONFIRM_MESSAGE_STORE_ID]->messageLength) != 0) {
bzrtp_freeZrtpPacket(zrtpPacket);
return BZRTP_ERROR_UNMATCHINGPACKETREPETITION;
}
/* free the incoming packet */
bzrtp_freeZrtpPacket(zrtpPacket);
/* incoming packet is valid, set the sequence Number in channel context */
zrtpChannelContext->peerSequenceNumber = zrtpPacket->sequenceNumber;
/* free the incoming packet */
bzrtp_freeZrtpPacket(zrtpPacket);
return 0;
}
......@@ -1294,13 +1321,17 @@ int state_confirmation_initiatorSendingConfirm2(bzrtpEvent_t event) {
*
*/
int state_secure(bzrtpEvent_t event) {
printf ("Enter secure state\n");
/* get the contextes from the event */
bzrtpContext_t *zrtpContext = event.zrtpContext;
/*bzrtpChannelContext_t *zrtpChannelContext = event.zrtpChannelContext;*/
bzrtpChannelContext_t *zrtpChannelContext = event.zrtpChannelContext;
zrtpContext->isSecure = 1;
zrtpChannelContext->isSecure = 1;
/* call the environment to signal we're ready to operate */
if (zrtpContext->zrtpCallbacks.bzrtp_startSrtpSession!= NULL) {
zrtpContext->zrtpCallbacks.bzrtp_startSrtpSession(zrtpChannelContext->clientData, zrtpChannelContext->srtpSecrets.sas, 0); /* TODO: last param is the verified flag but we are cacheless for now so always 0*/
}
return 0;
}
......@@ -1485,7 +1516,6 @@ int bzrtp_responseToHelloMessage(bzrtpContext_t *zrtpContext, bzrtpChannelContex
} else { /* when in DHM mode : Create the DHPart2 packet (that we then may change to DHPart1 if we ended to be the responder)*/
printf("Generate the DHPart2 packet\n");
bzrtpPacket_t *selfDHPartPacket = bzrtp_createZrtpPacket(zrtpContext, zrtpChannelContext, MSGTYPE_DHPART2, &retval);
if (retval != 0) {
return retval; /* no need to free the Hello message as it is attached to the context, it will be freed when destroying it */
......
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