Commit d177fb87 authored by johan's avatar johan

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;
......
This diff is collapsed.
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