Commit c7da2266 authored by johan's avatar johan

Build Hello packet at channel init in order to be able to compute zrtp-hash

+add a get channel status function
parent f5a9d331
...@@ -142,6 +142,13 @@ typedef struct bzrtpCallbacks_struct { ...@@ -142,6 +142,13 @@ typedef struct bzrtpCallbacks_struct {
#define BZRTP_ERROR_HELLOHASH_MISMATCH 0x0080 #define BZRTP_ERROR_HELLOHASH_MISMATCH 0x0080
#define BZRTP_ERROR_CHANNELALREADYSTARTED 0x0100 #define BZRTP_ERROR_CHANNELALREADYSTARTED 0x0100
/* channel status definition */
#define BZRTP_CHANNEL_NOTFOUND 0x1000
#define BZRTP_CHANNEL_INITIALISED 0x1001
#define BZRTP_CHANNEL_ONGOING 0x1002
#define BZRTP_CHANNEL_SECURE 0x1004
#define BZRTP_CHANNEL_ERROR 0x1008
/** /**
* @brief bzrtpContext_t The ZRTP engine context * @brief bzrtpContext_t The ZRTP engine context
* Store current state, timers, HMAC and encryption keys * Store current state, timers, HMAC and encryption keys
...@@ -339,6 +346,20 @@ BZRTP_EXPORT int bzrtp_setPeerHelloHash(bzrtpContext_t *zrtpContext, uint32_t se ...@@ -339,6 +346,20 @@ BZRTP_EXPORT int bzrtp_setPeerHelloHash(bzrtpContext_t *zrtpContext, uint32_t se
*/ */
BZRTP_EXPORT int bzrtp_getSelfHelloHash(bzrtpContext_t *zrtpContext, uint32_t selfSSRC, uint8_t *output, size_t outputLength); BZRTP_EXPORT int bzrtp_getSelfHelloHash(bzrtpContext_t *zrtpContext, uint32_t selfSSRC, uint8_t *output, size_t outputLength);
/**
* @brief Get the channel status
*
* @param[in] zrtpContext The ZRTP context we're dealing with
* @param[in] selfSSRC The SSRC identifying the channel
*
* @return BZRTP_CHANNEL_NOTFOUND no channel matching this SSRC doesn't exists in the zrtp context
* BZRTP_CHANNEL_INITIALISED channel initialised but not started
* BZRTP_CHANNEL_ONGOING ZRTP key exchange in ongoing
* BZRTP_CHANNEL_SECURE Channel is secure
* BZRTP_CHANNEL_ERROR An error occured on this channel
*/
int bzrtp_getChannelStatus(bzrtpContext_t *zrtpContext, uint32_t selfSSRC);
#define BZRTP_CUSTOMCACHE_USEKDF 1 #define BZRTP_CUSTOMCACHE_USEKDF 1
#define BZRTP_CUSTOMCACHE_PLAINDATA 0 #define BZRTP_CUSTOMCACHE_PLAINDATA 0
......
...@@ -808,6 +808,39 @@ int bzrtp_getSelfHelloHash(bzrtpContext_t *zrtpContext, uint32_t selfSSRC, uint8 ...@@ -808,6 +808,39 @@ int bzrtp_getSelfHelloHash(bzrtpContext_t *zrtpContext, uint32_t selfSSRC, uint8
return 0; return 0;
} }
/**
* @brief Get the channel status
*
* @param[in] zrtpContext The ZRTP context we're dealing with
* @param[in] selfSSRC The SSRC identifying the channel
*
* @return BZRTP_CHANNEL_NOTFOUND no channel matching this SSRC doesn't exists in the zrtp context
* BZRTP_CHANNEL_INITIALISED channel initialised but not started
* BZRTP_CHANNEL_ONGOING ZRTP key exchange in ongoing
* BZRTP_CHANNEL_SECURE Channel is secure
* BZRTP_CHANNEL_ERROR An error occured on this channel
*/
int bzrtp_getChannelStatus(bzrtpContext_t *zrtpContext, uint32_t selfSSRC) {
/* get channel context */
bzrtpChannelContext_t *zrtpChannelContext = getChannelContext(zrtpContext, selfSSRC);
if (zrtpChannelContext == NULL) {
return BZRTP_CHANNEL_NOTFOUND;
}
if (zrtpChannelContext->stateMachine == NULL) {
return BZRTP_CHANNEL_INITIALISED;
}
if (zrtpChannelContext->isSecure == 1) {
return BZRTP_CHANNEL_SECURE;
}
return BZRTP_CHANNEL_ONGOING;
}
/* Local functions implementation */ /* Local functions implementation */
/** /**
...@@ -848,6 +881,9 @@ static bzrtpChannelContext_t *getChannelContext(bzrtpContext_t *zrtpContext, uin ...@@ -848,6 +881,9 @@ static bzrtpChannelContext_t *getChannelContext(bzrtpContext_t *zrtpContext, uin
*/ */
static int bzrtp_initChannelContext(bzrtpContext_t *zrtpContext, bzrtpChannelContext_t *zrtpChannelContext, uint32_t selfSSRC, uint8_t isMain) { static int bzrtp_initChannelContext(bzrtpContext_t *zrtpContext, bzrtpChannelContext_t *zrtpChannelContext, uint32_t selfSSRC, uint8_t isMain) {
int i; int i;
int retval;
bzrtpPacket_t *helloPacket;
if (zrtpChannelContext == NULL) { if (zrtpChannelContext == NULL) {
return BZRTP_ERROR_INVALIDCHANNELCONTEXT; return BZRTP_ERROR_INVALIDCHANNELCONTEXT;
} }
...@@ -922,6 +958,19 @@ static int bzrtp_initChannelContext(bzrtpContext_t *zrtpContext, bzrtpChannelCon ...@@ -922,6 +958,19 @@ static int bzrtp_initChannelContext(bzrtpContext_t *zrtpContext, bzrtpChannelCon
zrtpChannelContext->srtpSecrets.sas = NULL; zrtpChannelContext->srtpSecrets.sas = NULL;
zrtpChannelContext->srtpSecrets.sasLength = 0; zrtpChannelContext->srtpSecrets.sasLength = 0;
/* create the Hello packet and store it */
helloPacket = bzrtp_createZrtpPacket(zrtpContext, zrtpChannelContext, MSGTYPE_HELLO, &retval);
if (retval != 0) {
return retval;
}
/* build the packet string and store the packet */
if (bzrtp_packetBuild(zrtpContext, zrtpChannelContext, helloPacket, zrtpChannelContext->selfSequenceNumber) ==0) {
zrtpChannelContext->selfPackets[HELLO_MESSAGE_STORE_ID] = helloPacket;
} else {
bzrtp_freeZrtpPacket(helloPacket);
return retval;
}
return 0; return 0;
} }
......
...@@ -62,21 +62,25 @@ int state_discovery_init(bzrtpEvent_t event) { ...@@ -62,21 +62,25 @@ int state_discovery_init(bzrtpEvent_t event) {
int retval; int retval;
/*** Manage the first call to this function ***/ /*** Manage the first call to this function ***/
/* We are supposed to send Hello packet, check if we have one in the channel Context, the event type shall be INIT in this case */ /* We are supposed to send Hello packet, it shall be already present int the selfPackets(created at channel init) */
if ((event.eventType == BZRTP_EVENT_INIT) && (zrtpChannelContext->selfPackets[HELLO_MESSAGE_STORE_ID] == NULL)) { if (event.eventType == BZRTP_EVENT_INIT) {
int retval; if (zrtpChannelContext->selfPackets[HELLO_MESSAGE_STORE_ID] == NULL) {
/* create the Hello packet */ /* We shall never go through this one because Hello packet shall be created at channel init */
bzrtpPacket_t *helloPacket = bzrtp_createZrtpPacket(zrtpContext, zrtpChannelContext, MSGTYPE_HELLO, &retval); int retval;
if (retval != 0) { /* create the Hello packet */
return retval; bzrtpPacket_t *helloPacket = bzrtp_createZrtpPacket(zrtpContext, zrtpChannelContext, MSGTYPE_HELLO, &retval);
} if (retval != 0) {
return retval;
}
/* build the packet string */ /* build the packet string */
if (bzrtp_packetBuild(zrtpContext, zrtpChannelContext, helloPacket, zrtpChannelContext->selfSequenceNumber) ==0) { if (bzrtp_packetBuild(zrtpContext, zrtpChannelContext, helloPacket, zrtpChannelContext->selfSequenceNumber) ==0) {
zrtpChannelContext->selfPackets[HELLO_MESSAGE_STORE_ID] = helloPacket; zrtpChannelContext->selfPackets[HELLO_MESSAGE_STORE_ID] = helloPacket;
} else { } else {
bzrtp_freeZrtpPacket(helloPacket); bzrtp_freeZrtpPacket(helloPacket);
return retval; return retval;
}
/* TODO: Shall add a warning trace here */
} }
/* it is the first call to this function, so we must also set the timer for retransmissions */ /* it is the first call to this function, so we must also set the timer for retransmissions */
......
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