Commit 580cc66e authored by Matthieu Tanon's avatar Matthieu Tanon Committed by johan

Improve bzrtp API for LIMEv2 peer device status implementation

parent 1d1d7604
...@@ -419,6 +419,13 @@ BZRTP_EXPORT int bzrtp_getChannelStatus(bzrtpContext_t *zrtpContext, uint32_t se ...@@ -419,6 +419,13 @@ BZRTP_EXPORT int bzrtp_getChannelStatus(bzrtpContext_t *zrtpContext, uint32_t se
*/ */
BZRTP_EXPORT int bzrtp_setAuxiliarySharedSecret(bzrtpContext_t *zrtpContext, const uint8_t *auxSecret, size_t auxSecretLength); BZRTP_EXPORT int bzrtp_setAuxiliarySharedSecret(bzrtpContext_t *zrtpContext, const uint8_t *auxSecret, size_t auxSecretLength);
/**
* @brief Get the ZRTP auxiliary shared secret mismatch status
* @param[in] ctx MSZRTP context
* @return 0 on match, 1 otherwise
*/
BZRTP_EXPORT uint8_t bzrtp_getAuxiliarySharedSecretMismatch(bzrtpContext_t *zrtpContext);
/*** Cache related functions ***/ /*** Cache related functions ***/
/** /**
* @brief Check the given sqlite3 DB and create requested tables if needed * @brief Check the given sqlite3 DB and create requested tables if needed
......
...@@ -953,7 +953,7 @@ int bzrtp_getSelfHelloHash(bzrtpContext_t *zrtpContext, uint32_t selfSSRC, uint8 ...@@ -953,7 +953,7 @@ int bzrtp_getSelfHelloHash(bzrtpContext_t *zrtpContext, uint32_t selfSSRC, uint8
* *
* @return 0 on success, error code otherwise * @return 0 on success, error code otherwise
*/ */
BZRTP_EXPORT int bzrtp_setAuxiliarySharedSecret(bzrtpContext_t *zrtpContext, const uint8_t *auxSecret, size_t auxSecretLength) { int bzrtp_setAuxiliarySharedSecret(bzrtpContext_t *zrtpContext, const uint8_t *auxSecret, size_t auxSecretLength) {
if (zrtpContext == NULL) { if (zrtpContext == NULL) {
return BZRTP_ERROR_INVALIDCONTEXT; return BZRTP_ERROR_INVALIDCONTEXT;
} }
...@@ -975,6 +975,16 @@ BZRTP_EXPORT int bzrtp_setAuxiliarySharedSecret(bzrtpContext_t *zrtpContext, con ...@@ -975,6 +975,16 @@ BZRTP_EXPORT int bzrtp_setAuxiliarySharedSecret(bzrtpContext_t *zrtpContext, con
return 0; return 0;
} }
/**
* @brief Get the ZRTP auxiliary shared secret mismatch status
*
* @param[in] zrtpContext The ZRTP context we're dealing with
* @return 0 on match, 1 on mismatch, 2 if auxiliary shared secret is unused
*/
uint8_t bzrtp_getAuxiliarySharedSecretMismatch(bzrtpContext_t *zrtpContext) {
return zrtpContext->channelContext[0]->srtpSecrets.auxSecretMismatch;
}
/** /**
* @brief Get the channel status * @brief Get the channel status
* *
...@@ -1127,7 +1137,7 @@ static int bzrtp_initChannelContext(bzrtpContext_t *zrtpContext, bzrtpChannelCon ...@@ -1127,7 +1137,7 @@ static int bzrtp_initChannelContext(bzrtpContext_t *zrtpContext, bzrtpChannelCon
zrtpChannelContext->srtpSecrets.keyAgreementAlgo = ZRTP_UNSET_ALGO; zrtpChannelContext->srtpSecrets.keyAgreementAlgo = ZRTP_UNSET_ALGO;
zrtpChannelContext->srtpSecrets.sasAlgo = ZRTP_UNSET_ALGO; zrtpChannelContext->srtpSecrets.sasAlgo = ZRTP_UNSET_ALGO;
zrtpChannelContext->srtpSecrets.cacheMismatch = 0; zrtpChannelContext->srtpSecrets.cacheMismatch = 0;
zrtpChannelContext->srtpSecrets.auxSecretMismatch = 1; /* default is mismatch, explicitely set it to zero if we have a match */ zrtpChannelContext->srtpSecrets.auxSecretMismatch = 2; /* default is 2, explicitely set it to 0 if we have a match or 1 if we have a mismatch */
/* create the Hello packet and store it */ /* create the Hello packet and store it */
helloPacket = bzrtp_createZrtpPacket(zrtpContext, zrtpChannelContext, MSGTYPE_HELLO, &retval); helloPacket = bzrtp_createZrtpPacket(zrtpContext, zrtpChannelContext, MSGTYPE_HELLO, &retval);
......
...@@ -532,11 +532,12 @@ int state_keyAgreement_sendingCommit(bzrtpEvent_t event) { ...@@ -532,11 +532,12 @@ int state_keyAgreement_sendingCommit(bzrtpEvent_t event) {
/* if we have an aux secret check it match peer's one */ /* if we have an aux secret check it match peer's one */
if (zrtpContext->cachedSecret.auxsecret!=NULL) { if (zrtpContext->cachedSecret.auxsecret!=NULL) {
if (memcmp(zrtpChannelContext->responderAuxsecretID, dhPart1Message->auxsecretID,8) != 0) { // they do not match, delete the aux secret as we must not use it if (memcmp(zrtpChannelContext->responderAuxsecretID, dhPart1Message->auxsecretID,8) != 0) { // they do not match, set flag to 1, delete the aux secret as we must not use it
free(zrtpContext->cachedSecret.auxsecret); free(zrtpContext->cachedSecret.auxsecret);
zrtpContext->cachedSecret.auxsecret= NULL; zrtpContext->cachedSecret.auxsecret= NULL;
zrtpContext->cachedSecret.auxsecretLength = 0; zrtpContext->cachedSecret.auxsecretLength = 0;
} else { // they do match, set the flag to 0 (its default is 1) zrtpChannelContext->srtpSecrets.auxSecretMismatch=1;
} else { // they do match, set the flag to 0 (default is 2)
zrtpChannelContext->srtpSecrets.auxSecretMismatch=0; zrtpChannelContext->srtpSecrets.auxSecretMismatch=0;
} }
} }
...@@ -836,11 +837,12 @@ int state_keyAgreement_responderSendingDHPart1(bzrtpEvent_t event) { ...@@ -836,11 +837,12 @@ int state_keyAgreement_responderSendingDHPart1(bzrtpEvent_t event) {
/* if we have an auxiliary secret, check it match peer's one */ /* if we have an auxiliary secret, check it match peer's one */
if (zrtpContext->cachedSecret.auxsecret!=NULL) { if (zrtpContext->cachedSecret.auxsecret!=NULL) {
if (memcmp(zrtpChannelContext->initiatorAuxsecretID, dhPart2Message->auxsecretID,8) != 0) { // they do not match, delete the aux secret as we must not use it if (memcmp(zrtpChannelContext->initiatorAuxsecretID, dhPart2Message->auxsecretID,8) != 0) { // they do not match, set flag to 1, delete the aux secret as we must not use it
free(zrtpContext->cachedSecret.auxsecret); free(zrtpContext->cachedSecret.auxsecret);
zrtpContext->cachedSecret.auxsecret= NULL; zrtpContext->cachedSecret.auxsecret= NULL;
zrtpContext->cachedSecret.auxsecretLength = 0; zrtpContext->cachedSecret.auxsecretLength = 0;
} else { // they do match, set the flag to 0 (its default is 1) zrtpChannelContext->srtpSecrets.auxSecretMismatch=1;
} else { // they do match, set the flag to 0 (default is 2)
zrtpChannelContext->srtpSecrets.auxSecretMismatch=0; zrtpChannelContext->srtpSecrets.auxSecretMismatch=0;
} }
} }
......
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