Commit 40faa2f3 authored by johan's avatar johan

Add tests

- perform actual exchange with all available crypto configurations
- packet lost simulation
parent 13bbfe95
......@@ -322,9 +322,8 @@ int bzrtp_startChannelEngine(bzrtpContext_t *zrtpContext, uint32_t selfSSRC) {
initEvent.bzrtpPacketStringLength = 0;
initEvent.zrtpContext = zrtpContext;
initEvent.zrtpChannelContext = zrtpChannelContext;
zrtpChannelContext->stateMachine(initEvent);
return 0;
return zrtpChannelContext->stateMachine(initEvent);
}
/*
......@@ -594,7 +593,7 @@ int bzrtp_resetRetransmissionTimer(bzrtpContext_t *zrtpContext, uint32_t selfSSR
return BZRTP_ERROR_INVALIDCONTEXT;
}
/* reset timer only when not in secure mode yet and for initiator(engine start as initiator so if we call this function in discovery phase, it will reset the timer */
if ((zrtpContext->isSecure == 0) && (zrtpChannelContext->role == INITIATOR)) {
if ((zrtpChannelContext->isSecure == 0) && (zrtpChannelContext->role == INITIATOR)) {
zrtpChannelContext->timer.status = BZRTP_TIMER_ON;
zrtpChannelContext->timer.firingTime = 0; /* be sure it will trigger at next call to bzrtp_iterate*/
zrtpChannelContext->timer.firingCount = -1; /* -1 to count the initial packet and then retransmit the regular number of packets */
......
......@@ -23,6 +23,7 @@
set(TEST_SOURCES
bzrtpCryptoTest.c
bzrtpParserTest.c
bzrtpConfigsTest.c
bzrtpTest.c
testUtils.c
......
This diff is collapsed.
/**
@file bzrtpConfigsTest.h
@author Johan Pascal
@copyright Copyright (C) 2017 Belledonne Communications, Grenoble, France
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
void test_cacheless_exchange(void);
void test_loosy_network(void);
......@@ -23,6 +23,7 @@
#include <stdio.h>
#include "bzrtpCryptoTest.h"
#include "bzrtpParserTest.h"
#include "bzrtpConfigsTest.h"
#include "typedef.h"
#include "testUtils.h"
#include <bctoolbox/logging.h>
......@@ -69,6 +70,21 @@ test_suite_t packet_parser_test_suite = {
packet_parser_tests
};
test_t key_exchange_tests[] = {
TEST_NO_TAG("Cacheless multi channel", test_cacheless_exchange),
TEST_NO_TAG("Loosy network", test_loosy_network)
};
test_suite_t key_exchange_test_suite = {
"Key exchange",
NULL,
NULL,
NULL,
NULL,
sizeof(key_exchange_tests) / sizeof(key_exchange_tests[0]),
key_exchange_tests
};
void bzrtp_tester_init(void) {
#ifdef HAVE_LIBXML2
xmlInitParser();
......@@ -77,6 +93,7 @@ void bzrtp_tester_init(void) {
bc_tester_add_suite(&crypto_utils_test_suite);
bc_tester_add_suite(&packet_parser_test_suite);
bc_tester_add_suite(&key_exchange_test_suite);
}
void bzrtp_tester_uninit(void) {
......
......@@ -29,6 +29,66 @@
#include "cryptoUtils.h"
int verbose = 0;
/* trace functions: bzrtp algo code to string */
const char *bzrtp_hash_toString(uint8_t hashAlgo) {
switch(hashAlgo) {
case(ZRTP_UNSET_ALGO): return "unset";
case(ZRTP_HASH_S256): return "SHA-256";
case(ZRTP_HASH_S384): return "SHA-384";
case(ZRTP_HASH_N256): return "SHA3-256";
case(ZRTP_HASH_N384): return "SHA3-384";
default: return "Unknown Algo";
}
}
const char *bzrtp_keyAgreement_toString(uint8_t keyAgreementAlgo) {
switch(keyAgreementAlgo) {
case(ZRTP_UNSET_ALGO): return "unset";
case(ZRTP_KEYAGREEMENT_DH2k): return "DHM-2048";
case(ZRTP_KEYAGREEMENT_EC25): return "ECDH-256";
case(ZRTP_KEYAGREEMENT_DH3k): return "DHM-3072";
case(ZRTP_KEYAGREEMENT_EC38): return "ECDH-384";
case(ZRTP_KEYAGREEMENT_EC52): return "ECDH-521";
case(ZRTP_KEYAGREEMENT_Prsh): return "PreShared";
case(ZRTP_KEYAGREEMENT_Mult): return "MultiStream";
default: return "Unknown Algo";
}
}
const char *bzrtp_cipher_toString(uint8_t cipherAlgo) {
switch(cipherAlgo) {
case(ZRTP_UNSET_ALGO): return "unset";
case(ZRTP_CIPHER_AES1): return "AES-128";
case(ZRTP_CIPHER_AES2): return "AES-192";
case(ZRTP_CIPHER_AES3): return "AES-256";
case(ZRTP_CIPHER_2FS1): return "TwoFish-128";
case(ZRTP_CIPHER_2FS2): return "TwoFish-192";
case(ZRTP_CIPHER_2FS3): return "TwoFish-256";
default: return "Unknown Algo";
}
}
const char *bzrtp_authtag_toString(uint8_t authtagAlgo) {
switch(authtagAlgo) {
case(ZRTP_UNSET_ALGO): return "unset";
case(ZRTP_AUTHTAG_HS32): return "HMAC-SHA1-32";
case(ZRTP_AUTHTAG_HS80): return "HMAC-SHA1-80";
case(ZRTP_AUTHTAG_SK32): return "Skein-32";
case(ZRTP_AUTHTAG_SK64): return "Skein-64";
default: return "Unknown Algo";
}
}
const char *bzrtp_sas_toString(uint8_t sasAlgo) {
switch(sasAlgo) {
case(ZRTP_UNSET_ALGO): return "unset";
case(ZRTP_SAS_B32): return "Base32";
case(ZRTP_SAS_B256): return "PGP-WordList";
default: return "Unknown Algo";
}
}
void bzrtp_message(const char *fmt, ...) {
if (verbose) {
va_list args;
......
......@@ -30,3 +30,8 @@ void printHex(char *title, uint8_t *data, uint32_t length);
void packetDump(bzrtpPacket_t *zrtpPacket, uint8_t addRawMessage);
void dumpContext(char *title, bzrtpContext_t *zrtpContext);
const char *bzrtp_hash_toString(uint8_t hashAlgo);
const char *bzrtp_keyAgreement_toString(uint8_t keyAgreementAlgo);
const char *bzrtp_cipher_toString(uint8_t cipherAlgo);
const char *bzrtp_authtag_toString(uint8_t authtagAlgo);
const char *bzrtp_sas_toString(uint8_t sasAlgo);
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