Commit f3de0484 authored by Johan Pascal's avatar Johan Pascal

Improve tests

- better trace
- fix bug in ECDH specifics tests
parent 0e6a06ab
......@@ -25,7 +25,7 @@
#include <time.h>
#include "bzrtp/bzrtp.h"
#include <bctoolbox/tester.h>
#include "bzrtpTest.h"
#include "testUtils.h"
#define MAX_PACKET_LENGTH 1000
......@@ -540,7 +540,7 @@ uint32_t multichannel_exchange(cryptoParams_t *aliceCryptoParams, cryptoParams_t
}
void test_cacheless_exchange(void) {
static void test_cacheless_exchange(void) {
cryptoParams_t *pattern;
/* Reset Global Static settings */
......@@ -554,21 +554,41 @@ void test_cacheless_exchange(void) {
{{ZRTP_CIPHER_AES1},1,{ZRTP_HASH_S256},1,{ZRTP_KEYAGREEMENT_DH3k},1,{ZRTP_SAS_B256},1,{ZRTP_AUTHTAG_HS32},1,0},
{{ZRTP_CIPHER_AES1},1,{ZRTP_HASH_S256},1,{ZRTP_KEYAGREEMENT_DH3k},1,{ZRTP_SAS_B256},1,{ZRTP_AUTHTAG_HS80},1,0},
{{ZRTP_CIPHER_AES1},1,{ZRTP_HASH_S384},1,{ZRTP_KEYAGREEMENT_DH3k},1,{ZRTP_SAS_B32},1,{ZRTP_AUTHTAG_HS32},1,0},
{{ZRTP_CIPHER_AES1},1,{ZRTP_HASH_S384},1,{ZRTP_KEYAGREEMENT_DH3k},1,{ZRTP_SAS_B32},1,{ZRTP_AUTHTAG_HS80},1,0},
{{ZRTP_CIPHER_AES1},1,{ZRTP_HASH_S384},1,{ZRTP_KEYAGREEMENT_DH3k},1,{ZRTP_SAS_B256},1,{ZRTP_AUTHTAG_HS32},1,0},
{{ZRTP_CIPHER_AES1},1,{ZRTP_HASH_S384},1,{ZRTP_KEYAGREEMENT_DH3k},1,{ZRTP_SAS_B256},1,{ZRTP_AUTHTAG_HS80},1,0},
{{ZRTP_CIPHER_AES1},1,{ZRTP_HASH_S256},1,{ZRTP_KEYAGREEMENT_DH2k},1,{ZRTP_SAS_B32},1,{ZRTP_AUTHTAG_HS32},1,0},
{{ZRTP_CIPHER_AES1},1,{ZRTP_HASH_S256},1,{ZRTP_KEYAGREEMENT_DH2k},1,{ZRTP_SAS_B32},1,{ZRTP_AUTHTAG_HS80},1,0},
{{ZRTP_CIPHER_AES1},1,{ZRTP_HASH_S256},1,{ZRTP_KEYAGREEMENT_DH2k},1,{ZRTP_SAS_B256},1,{ZRTP_AUTHTAG_HS32},1,0},
{{ZRTP_CIPHER_AES1},1,{ZRTP_HASH_S256},1,{ZRTP_KEYAGREEMENT_DH2k},1,{ZRTP_SAS_B256},1,{ZRTP_AUTHTAG_HS80},1,0},
{{ZRTP_CIPHER_AES1},1,{ZRTP_HASH_S384},1,{ZRTP_KEYAGREEMENT_DH2k},1,{ZRTP_SAS_B32},1,{ZRTP_AUTHTAG_HS32},1,0},
{{ZRTP_CIPHER_AES1},1,{ZRTP_HASH_S384},1,{ZRTP_KEYAGREEMENT_DH2k},1,{ZRTP_SAS_B32},1,{ZRTP_AUTHTAG_HS80},1,0},
{{ZRTP_CIPHER_AES1},1,{ZRTP_HASH_S384},1,{ZRTP_KEYAGREEMENT_DH2k},1,{ZRTP_SAS_B256},1,{ZRTP_AUTHTAG_HS32},1,0},
{{ZRTP_CIPHER_AES1},1,{ZRTP_HASH_S384},1,{ZRTP_KEYAGREEMENT_DH2k},1,{ZRTP_SAS_B256},1,{ZRTP_AUTHTAG_HS80},1,0},
{{ZRTP_CIPHER_AES3},1,{ZRTP_HASH_S256},1,{ZRTP_KEYAGREEMENT_DH3k},1,{ZRTP_SAS_B32},1,{ZRTP_AUTHTAG_HS32},1,0},
{{ZRTP_CIPHER_AES3},1,{ZRTP_HASH_S256},1,{ZRTP_KEYAGREEMENT_DH3k},1,{ZRTP_SAS_B32},1,{ZRTP_AUTHTAG_HS80},1,0},
{{ZRTP_CIPHER_AES3},1,{ZRTP_HASH_S256},1,{ZRTP_KEYAGREEMENT_DH3k},1,{ZRTP_SAS_B256},1,{ZRTP_AUTHTAG_HS32},1,0},
{{ZRTP_CIPHER_AES3},1,{ZRTP_HASH_S256},1,{ZRTP_KEYAGREEMENT_DH3k},1,{ZRTP_SAS_B256},1,{ZRTP_AUTHTAG_HS80},1,0},
{{ZRTP_CIPHER_AES3},1,{ZRTP_HASH_S384},1,{ZRTP_KEYAGREEMENT_DH3k},1,{ZRTP_SAS_B32},1,{ZRTP_AUTHTAG_HS32},1,0},
{{ZRTP_CIPHER_AES3},1,{ZRTP_HASH_S384},1,{ZRTP_KEYAGREEMENT_DH3k},1,{ZRTP_SAS_B32},1,{ZRTP_AUTHTAG_HS80},1,0},
{{ZRTP_CIPHER_AES3},1,{ZRTP_HASH_S384},1,{ZRTP_KEYAGREEMENT_DH3k},1,{ZRTP_SAS_B256},1,{ZRTP_AUTHTAG_HS32},1,0},
{{ZRTP_CIPHER_AES3},1,{ZRTP_HASH_S384},1,{ZRTP_KEYAGREEMENT_DH3k},1,{ZRTP_SAS_B256},1,{ZRTP_AUTHTAG_HS80},1,0},
{{ZRTP_CIPHER_AES3},1,{ZRTP_HASH_S256},1,{ZRTP_KEYAGREEMENT_DH2k},1,{ZRTP_SAS_B32},1,{ZRTP_AUTHTAG_HS32},1,0},
{{ZRTP_CIPHER_AES3},1,{ZRTP_HASH_S256},1,{ZRTP_KEYAGREEMENT_DH2k},1,{ZRTP_SAS_B32},1,{ZRTP_AUTHTAG_HS80},1,0},
{{ZRTP_CIPHER_AES3},1,{ZRTP_HASH_S256},1,{ZRTP_KEYAGREEMENT_DH2k},1,{ZRTP_SAS_B256},1,{ZRTP_AUTHTAG_HS32},1,0},
{{ZRTP_CIPHER_AES3},1,{ZRTP_HASH_S256},1,{ZRTP_KEYAGREEMENT_DH2k},1,{ZRTP_SAS_B256},1,{ZRTP_AUTHTAG_HS80},1,0},
{{ZRTP_CIPHER_AES3},1,{ZRTP_HASH_S384},1,{ZRTP_KEYAGREEMENT_DH2k},1,{ZRTP_SAS_B32},1,{ZRTP_AUTHTAG_HS32},1,0},
{{ZRTP_CIPHER_AES3},1,{ZRTP_HASH_S384},1,{ZRTP_KEYAGREEMENT_DH2k},1,{ZRTP_SAS_B32},1,{ZRTP_AUTHTAG_HS80},1,0},
{{ZRTP_CIPHER_AES3},1,{ZRTP_HASH_S384},1,{ZRTP_KEYAGREEMENT_DH2k},1,{ZRTP_SAS_B256},1,{ZRTP_AUTHTAG_HS32},1,0},
{{ZRTP_CIPHER_AES3},1,{ZRTP_HASH_S384},1,{ZRTP_KEYAGREEMENT_DH2k},1,{ZRTP_SAS_B256},1,{ZRTP_AUTHTAG_HS80},1,0},
{{0},0,{0},0,{0},0,{0},0,{0},0,0}, /* this pattern will end the run because cipher nb is 0 */
};
......@@ -579,21 +599,41 @@ void test_cacheless_exchange(void) {
{{ZRTP_CIPHER_AES1},1,{ZRTP_HASH_S256},1,{ZRTP_KEYAGREEMENT_X448},1,{ZRTP_SAS_B256},1,{ZRTP_AUTHTAG_HS32},1,0},
{{ZRTP_CIPHER_AES1},1,{ZRTP_HASH_S256},1,{ZRTP_KEYAGREEMENT_X448},1,{ZRTP_SAS_B256},1,{ZRTP_AUTHTAG_HS80},1,0},
{{ZRTP_CIPHER_AES1},1,{ZRTP_HASH_S384},1,{ZRTP_KEYAGREEMENT_X448},1,{ZRTP_SAS_B32},1,{ZRTP_AUTHTAG_HS32},1,0},
{{ZRTP_CIPHER_AES1},1,{ZRTP_HASH_S384},1,{ZRTP_KEYAGREEMENT_X448},1,{ZRTP_SAS_B32},1,{ZRTP_AUTHTAG_HS80},1,0},
{{ZRTP_CIPHER_AES1},1,{ZRTP_HASH_S384},1,{ZRTP_KEYAGREEMENT_X448},1,{ZRTP_SAS_B256},1,{ZRTP_AUTHTAG_HS32},1,0},
{{ZRTP_CIPHER_AES1},1,{ZRTP_HASH_S384},1,{ZRTP_KEYAGREEMENT_X448},1,{ZRTP_SAS_B256},1,{ZRTP_AUTHTAG_HS80},1,0},
{{ZRTP_CIPHER_AES1},1,{ZRTP_HASH_S256},1,{ZRTP_KEYAGREEMENT_X255},1,{ZRTP_SAS_B32},1,{ZRTP_AUTHTAG_HS32},1,0},
{{ZRTP_CIPHER_AES1},1,{ZRTP_HASH_S256},1,{ZRTP_KEYAGREEMENT_X255},1,{ZRTP_SAS_B32},1,{ZRTP_AUTHTAG_HS80},1,0},
{{ZRTP_CIPHER_AES1},1,{ZRTP_HASH_S256},1,{ZRTP_KEYAGREEMENT_X255},1,{ZRTP_SAS_B256},1,{ZRTP_AUTHTAG_HS32},1,0},
{{ZRTP_CIPHER_AES1},1,{ZRTP_HASH_S256},1,{ZRTP_KEYAGREEMENT_X255},1,{ZRTP_SAS_B256},1,{ZRTP_AUTHTAG_HS80},1,0},
{{ZRTP_CIPHER_AES1},1,{ZRTP_HASH_S384},1,{ZRTP_KEYAGREEMENT_X255},1,{ZRTP_SAS_B32},1,{ZRTP_AUTHTAG_HS32},1,0},
{{ZRTP_CIPHER_AES1},1,{ZRTP_HASH_S384},1,{ZRTP_KEYAGREEMENT_X255},1,{ZRTP_SAS_B32},1,{ZRTP_AUTHTAG_HS80},1,0},
{{ZRTP_CIPHER_AES1},1,{ZRTP_HASH_S384},1,{ZRTP_KEYAGREEMENT_X255},1,{ZRTP_SAS_B256},1,{ZRTP_AUTHTAG_HS32},1,0},
{{ZRTP_CIPHER_AES1},1,{ZRTP_HASH_S384},1,{ZRTP_KEYAGREEMENT_X255},1,{ZRTP_SAS_B256},1,{ZRTP_AUTHTAG_HS80},1,0},
{{ZRTP_CIPHER_AES3},1,{ZRTP_HASH_S256},1,{ZRTP_KEYAGREEMENT_X448},1,{ZRTP_SAS_B32},1,{ZRTP_AUTHTAG_HS32},1,0},
{{ZRTP_CIPHER_AES3},1,{ZRTP_HASH_S256},1,{ZRTP_KEYAGREEMENT_X448},1,{ZRTP_SAS_B32},1,{ZRTP_AUTHTAG_HS80},1,0},
{{ZRTP_CIPHER_AES3},1,{ZRTP_HASH_S256},1,{ZRTP_KEYAGREEMENT_X448},1,{ZRTP_SAS_B256},1,{ZRTP_AUTHTAG_HS32},1,0},
{{ZRTP_CIPHER_AES3},1,{ZRTP_HASH_S256},1,{ZRTP_KEYAGREEMENT_X448},1,{ZRTP_SAS_B256},1,{ZRTP_AUTHTAG_HS80},1,0},
{{ZRTP_CIPHER_AES3},1,{ZRTP_HASH_S384},1,{ZRTP_KEYAGREEMENT_X448},1,{ZRTP_SAS_B32},1,{ZRTP_AUTHTAG_HS32},1,0},
{{ZRTP_CIPHER_AES3},1,{ZRTP_HASH_S384},1,{ZRTP_KEYAGREEMENT_X448},1,{ZRTP_SAS_B32},1,{ZRTP_AUTHTAG_HS80},1,0},
{{ZRTP_CIPHER_AES3},1,{ZRTP_HASH_S384},1,{ZRTP_KEYAGREEMENT_X448},1,{ZRTP_SAS_B256},1,{ZRTP_AUTHTAG_HS32},1,0},
{{ZRTP_CIPHER_AES3},1,{ZRTP_HASH_S384},1,{ZRTP_KEYAGREEMENT_X448},1,{ZRTP_SAS_B256},1,{ZRTP_AUTHTAG_HS80},1,0},
{{ZRTP_CIPHER_AES3},1,{ZRTP_HASH_S256},1,{ZRTP_KEYAGREEMENT_X255},1,{ZRTP_SAS_B32},1,{ZRTP_AUTHTAG_HS32},1,0},
{{ZRTP_CIPHER_AES3},1,{ZRTP_HASH_S256},1,{ZRTP_KEYAGREEMENT_X255},1,{ZRTP_SAS_B32},1,{ZRTP_AUTHTAG_HS80},1,0},
{{ZRTP_CIPHER_AES3},1,{ZRTP_HASH_S256},1,{ZRTP_KEYAGREEMENT_X255},1,{ZRTP_SAS_B256},1,{ZRTP_AUTHTAG_HS32},1,0},
{{ZRTP_CIPHER_AES3},1,{ZRTP_HASH_S256},1,{ZRTP_KEYAGREEMENT_X255},1,{ZRTP_SAS_B256},1,{ZRTP_AUTHTAG_HS80},1,0},
{{ZRTP_CIPHER_AES3},1,{ZRTP_HASH_S384},1,{ZRTP_KEYAGREEMENT_X255},1,{ZRTP_SAS_B32},1,{ZRTP_AUTHTAG_HS32},1,0},
{{ZRTP_CIPHER_AES3},1,{ZRTP_HASH_S384},1,{ZRTP_KEYAGREEMENT_X255},1,{ZRTP_SAS_B32},1,{ZRTP_AUTHTAG_HS80},1,0},
{{ZRTP_CIPHER_AES3},1,{ZRTP_HASH_S384},1,{ZRTP_KEYAGREEMENT_X255},1,{ZRTP_SAS_B256},1,{ZRTP_AUTHTAG_HS32},1,0},
{{ZRTP_CIPHER_AES3},1,{ZRTP_HASH_S384},1,{ZRTP_KEYAGREEMENT_X255},1,{ZRTP_SAS_B256},1,{ZRTP_AUTHTAG_HS80},1,0},
{{0},0,{0},0,{0},0,{0},0,{0},0,0}, /* this pattern will end the run because cipher nb is 0 */
};
......@@ -606,15 +646,18 @@ void test_cacheless_exchange(void) {
/* with ECDH agreement types if available */
if (bctbx_key_agreement_algo_list()&BCTBX_ECDH_X25519) {
printf("Oh yeah\n");
pattern = &ecdh_patterns[0]; /* pattern is a pointer to current pattern */
BC_ASSERT_EQUAL(multichannel_exchange(pattern, pattern, pattern, NULL, NULL, NULL, NULL), 0, int, "%x");
pattern++; /* point to next row in the array of patterns */
while (pattern->cipherNb!=0) {
BC_ASSERT_EQUAL(multichannel_exchange(pattern, pattern, pattern, NULL, NULL, NULL, NULL), 0, int, "%x");
pattern++; /* point to next row in the array of patterns */
}
}
BC_ASSERT_EQUAL(multichannel_exchange(NULL, NULL, defaultCryptoAlgoSelection(), NULL, NULL, NULL, NULL), 0, int, "%x");
}
void test_loosy_network(void) {
static void test_loosy_network(void) {
int i,j;
resetGlobalParams();
srand((unsigned int)time(NULL));
......@@ -630,7 +673,7 @@ void test_loosy_network(void) {
}
}
void test_cache_enabled_exchange(void) {
static void test_cache_enabled_exchange(void) {
#ifdef ZIDCACHE_ENABLED
sqlite3 *aliceDB=NULL;
sqlite3 *bobDB=NULL;
......@@ -714,7 +757,7 @@ void test_cache_enabled_exchange(void) {
}
/* first perform an exchange to establish a correct shared cache, then modify one of them and perform an other exchange to check we have a cache mismatch warning */
void test_cache_mismatch_exchange(void) {
static void test_cache_mismatch_exchange(void) {
#ifdef ZIDCACHE_ENABLED
sqlite3 *aliceDB=NULL;
sqlite3 *bobDB=NULL;
......@@ -826,7 +869,7 @@ void test_cache_mismatch_exchange(void) {
#endif /* ZIDCACHE_ENABLED */
}
void test_cache_sas_not_confirmed(void) {
static void test_cache_sas_not_confirmed(void) {
#ifdef ZIDCACHE_ENABLED
sqlite3 *aliceDB=NULL;
sqlite3 *bobDB=NULL;
......@@ -927,3 +970,21 @@ void test_cache_sas_not_confirmed(void) {
#endif /* ZIDCACHE_ENABLED */
}
static test_t key_exchange_tests[] = {
TEST_NO_TAG("Cacheless multi channel", test_cacheless_exchange),
TEST_NO_TAG("Cached Simple", test_cache_enabled_exchange),
TEST_NO_TAG("Cached mismatch", test_cache_mismatch_exchange),
TEST_NO_TAG("Loosy network", test_loosy_network),
TEST_NO_TAG("Cached PVS", test_cache_sas_not_confirmed)
};
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
};
/**
@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);
void test_cache_enabled_exchange(void);
void test_cache_mismatch_exchange(void);
void test_cache_sas_not_confirmed(void);
......@@ -35,7 +35,7 @@
#include "bzrtp/bzrtp.h"
#include "cryptoUtils.h"
#include "testUtils.h"
#include <bctoolbox/tester.h>
#include "bzrtpTest.h"
/**
*
......@@ -73,7 +73,7 @@ uint8_t patternKDFContext[KDF_TEST_NUMBER][56] = {
{0xf0, 0x1f, 0x24, 0x02, 0x00, 0x00, 0x00, 0x00, 0x80, 0x24, 0xad, 0xfb, 0x94, 0xa9, 0x06, 0x90, 0xcf, 0x9c, 0xed, 0x13, 0x99, 0x8c, 0x51, 0x34, 0x7d, 0xc4, 0x35, 0xa7, 0x4d, 0x75, 0x25, 0x44, 0x80, 0xc2, 0x11, 0xf2, 0xd3, 0x20, 0x5e, 0xa7, 0x1b, 0x4b, 0xa4, 0xee, 0xc7, 0x8e, 0xb7, 0x35, 0x75, 0x28, 0xe5, 0x6f, 0xcf, 0x4f, 0x74, 0x9f}
};
void test_zrtpKDF(void) {
static void test_zrtpKDF(void) {
int i;
uint8_t keyKDF[32] = {0x33, 0xe6, 0x6c, 0x01, 0xca, 0x6f, 0xe6, 0x4f, 0xb7, 0x6f, 0xfd, 0xe3, 0x1c, 0xab, 0xc0, 0xfb, 0xad, 0x3d, 0x31, 0x02, 0x67, 0x6b, 0x0c, 0x09, 0x0f, 0xc9, 0x96, 0x38, 0x1e, 0x0a, 0x8c, 0x2f};
......@@ -109,7 +109,7 @@ uint32_t patternCRCoutput[CRC_TEST_NUMBER] = {0x5065ab04, 0x9c9edccd, 0xda5c92ea
* Pattern generated using GNU-ZRTP C++
*
*/
void test_CRC32(void) {
static void test_CRC32(void) {
int i;
for (i=0; i<CRC_TEST_NUMBER; i++) {
BC_ASSERT_TRUE(bzrtp_CRC32(patterCRCinput[i], patternCRCLength[i]) == patternCRCoutput[i]);
......@@ -227,7 +227,7 @@ struct st_algo_type {
uint8_t expectedType;
};
void test_algoAgreement(void) {
static void test_algoAgreement(void) {
struct st_algo_type_with_packet agreement_types_with_packet[] = {
{ {ZRTP_KEYAGREEMENT_DH2k}, 1, ZRTP_KEYAGREEMENT_DH2k },
{ {ZRTP_KEYAGREEMENT_DH3k}, 1, ZRTP_KEYAGREEMENT_DH3k },
......@@ -377,7 +377,7 @@ struct st_algo_setter_getter {
uint8_t expectedTypesCount;
};
void test_algoSetterGetter(void) {
static void test_algoSetterGetter(void) {
struct st_algo_setter_getter agreement_types[] = {
{ {ZRTP_KEYAGREEMENT_DH2k}, 1, {ZRTP_KEYAGREEMENT_DH2k, ZRTP_KEYAGREEMENT_DH3k, ZRTP_KEYAGREEMENT_Mult}, 3 },
{ {ZRTP_KEYAGREEMENT_DH3k}, 1, {ZRTP_KEYAGREEMENT_DH3k, ZRTP_KEYAGREEMENT_Mult}, 2 },
......@@ -469,7 +469,7 @@ struct st_add_crypto {
uint8_t expectedTypesCount;
};
void test_addMandatoryCryptoTypesIfNeeded(void) {
static void test_addMandatoryCryptoTypesIfNeeded(void) {
struct st_add_crypto crypto_types[] = {
/* mandatory types */
{ ZRTP_HASH_TYPE, {ZRTP_UNSET_ALGO}, 0, {ZRTP_HASH_S256}, 1 },
......@@ -507,3 +507,21 @@ void test_addMandatoryCryptoTypesIfNeeded(void) {
crypto_type++;
}
}
static test_t crypto_utils_tests[] = {
TEST_NO_TAG("zrtpKDF", test_zrtpKDF),
TEST_NO_TAG("CRC32", test_CRC32),
TEST_NO_TAG("algo agreement", test_algoAgreement),
TEST_NO_TAG("context algo setter and getter", test_algoSetterGetter),
TEST_NO_TAG("adding mandatory crypto algorithms if needed", test_addMandatoryCryptoTypesIfNeeded)
};
test_suite_t crypto_utils_test_suite = {
"Crypto Utils",
NULL,
NULL,
NULL,
NULL,
sizeof(crypto_utils_tests) / sizeof(crypto_utils_tests[0]),
crypto_utils_tests
};
/**
@file bzrtpCryptoTests.h
@author Johan Pascal
@copyright Copyright (C) 2014 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_RNG(void);
void test_sha256(void);
void test_hmacSha256(void);
void test_aes128CFB(void);
void test_dhm2048(void);
void test_dhm3072(void);
void test_zrtpKDF(void);
void test_CRC32(void);
void test_algoAgreement(void);
void test_algoSetterGetter(void);
void test_addMandatoryCryptoTypesIfNeeded(void);
......@@ -31,7 +31,7 @@
#include "cryptoUtils.h"
#include "zidCache.h"
#include "testUtils.h"
#include <bctoolbox/tester.h>
#include "bzrtpTest.h"
#ifndef _WIN32
#include <time.h>
......@@ -267,11 +267,11 @@ error:
bzrtp_destroyBzrtpContext(context12345678, 0x12345678);
}
void test_parser(void) {
static void test_parser(void) {
test_parser_param(0);
}
void test_parser_hvi(void) {
static void test_parser_hvi(void) {
test_parser_param(1);
}
......@@ -283,7 +283,7 @@ typedef struct my_Context_struct {
} my_Context_t;
void test_parserComplete() {
static void test_parserComplete() {
int retval;
/* alice's maintained packet */
......@@ -1634,7 +1634,7 @@ static void sleepMs(int ms){
/* Ping message length is 24 bytes (already define in packetParser.c out of this scope) */
#define ZRTP_PINGMESSAGE_FIXED_LENGTH 24
void test_stateMachine() {
static void test_stateMachine() {
int retval;
my_Context_t aliceClientData, bobClientData;
uint64_t initialTime;
......@@ -1845,7 +1845,7 @@ void test_stateMachine() {
}
/* first parse a packet and then try good and bad zrtp-hash, then do it the other way : set the zrtp-hash and then parse packet */
void test_zrtphash(void) {
static void test_zrtphash(void) {
bzrtpPacket_t *zrtpPacket;
int retval;
......@@ -1883,3 +1883,21 @@ void test_zrtphash(void) {
retval = bzrtp_packetParser(context12345678, context12345678->channelContext[0], HelloPacketZrtpHash, sizeof(HelloPacketZrtpHash), zrtpPacket);
BC_ASSERT_EQUAL(retval, 0, int, "%d");
}
static test_t packet_parser_tests[] = {
TEST_NO_TAG("Parse", test_parser),
TEST_NO_TAG("Parse hvi check fail", test_parser_hvi),
TEST_NO_TAG("Parse Exchange", test_parserComplete),
TEST_NO_TAG("State machine", test_stateMachine),
TEST_NO_TAG("ZRTP-hash", test_zrtphash)
};
test_suite_t packet_parser_test_suite = {
"Packet Parser",
NULL,
NULL,
NULL,
NULL,
sizeof(packet_parser_tests) / sizeof(packet_parser_tests[0]),
packet_parser_tests
};
/**
@file bzrtpCryptoTests.h
@author Johan Pascal
@copyright Copyright (C) 2014 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_parser(void);
void test_parser_hvi(void);
void test_parserComplete(void);
void test_stateMachine(void);
void test_zrtphash(void);
......@@ -21,87 +21,34 @@
*/
#include <stdio.h>
#include "bzrtpCryptoTest.h"
#include "bzrtpParserTest.h"
#include "bzrtpConfigsTest.h"
#include "bzrtpZidCacheTest.h"
#include "bzrtpTest.h"
#include "typedef.h"
#include "testUtils.h"
#include <bctoolbox/logging.h>
#include <bctoolbox/tester.h>
test_t crypto_utils_tests[] = {
TEST_NO_TAG("zrtpKDF", test_zrtpKDF),
TEST_NO_TAG("CRC32", test_CRC32),
TEST_NO_TAG("algo agreement", test_algoAgreement),
TEST_NO_TAG("context algo setter and getter", test_algoSetterGetter),
TEST_NO_TAG("adding mandatory crypto algorithms if needed", test_addMandatoryCryptoTypesIfNeeded)
};
test_suite_t crypto_utils_test_suite = {
"Crypto Utils",
NULL,
NULL,
NULL,
NULL,
sizeof(crypto_utils_tests) / sizeof(crypto_utils_tests[0]),
crypto_utils_tests
};
test_t packet_parser_tests[] = {
TEST_NO_TAG("Parse", test_parser),
TEST_NO_TAG("Parse hvi check fail", test_parser_hvi),
TEST_NO_TAG("Parse Exchange", test_parserComplete),
TEST_NO_TAG("State machine", test_stateMachine),
TEST_NO_TAG("ZRTP-hash", test_zrtphash)
};
test_suite_t packet_parser_test_suite = {
"Packet Parser",
NULL,
NULL,
NULL,
NULL,
sizeof(packet_parser_tests) / sizeof(packet_parser_tests[0]),
packet_parser_tests
};
test_t zidcache_tests[] = {
TEST_NO_TAG("SelfZID", test_cache_getSelfZID),
TEST_NO_TAG("ZRTP secrets", test_cache_zrtpSecrets),
TEST_NO_TAG("Migration", test_cache_migration),
};
test_suite_t zidcache_test_suite = {
"ZID Cache",
NULL,
NULL,
NULL,
NULL,
sizeof(zidcache_tests) / sizeof(zidcache_tests[0]),
zidcache_tests
};
test_t key_exchange_tests[] = {
TEST_NO_TAG("Cacheless multi channel", test_cacheless_exchange),
TEST_NO_TAG("Cached Simple", test_cache_enabled_exchange),
TEST_NO_TAG("Cached mismatch", test_cache_mismatch_exchange),
TEST_NO_TAG("Loosy network", test_loosy_network),
TEST_NO_TAG("Cached PVS", test_cache_sas_not_confirmed)
};
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) {
bc_tester_init(NULL, BCTBX_LOG_MESSAGE, BCTBX_LOG_ERROR, NULL);
static FILE * log_file = NULL;
static const char *log_domain = "bzrtp-tester";
static void log_handler(int lev, const char *fmt, va_list args) {
#ifdef _WIN32
/* We must use stdio to avoid log formatting (for autocompletion etc.) */
vfprintf(lev == BCTBX_LOG_ERROR ? stderr : stdout, fmt, args);
fprintf(lev == BCTBX_LOG_ERROR ? stderr : stdout, "\n");
#else
va_list cap;
va_copy(cap,args);
vfprintf(lev == BCTBX_LOG_ERROR ? stderr : stdout, fmt, cap);
fprintf(lev == BCTBX_LOG_ERROR ? stderr : stdout, "\n");
va_end(cap);
#endif
if (log_file){
bctbx_logv(log_domain, (BctbxLogLevel)lev, fmt, args);
}
}
void bzrtp_tester_init(void(*ftester_printf)(int level, const char *fmt, va_list args)) {
if (ftester_printf == NULL) ftester_printf = log_handler;
bc_tester_init(ftester_printf, BCTBX_LOG_MESSAGE, BCTBX_LOG_ERROR, NULL);
bc_tester_add_suite(&crypto_utils_test_suite);
bc_tester_add_suite(&packet_parser_test_suite);
......@@ -113,25 +60,76 @@ void bzrtp_tester_uninit(void) {
bc_tester_uninit();
}
int bzrtp_tester_set_log_file(const char *filename) {
bctbx_log_handler_t* filehandler;
char* dir;
char* base;
if (log_file) {
fclose(log_file);
}
log_file = fopen(filename, "w");
if (!log_file) {
bctbx_error("Cannot open file [%s] for writing logs because [%s]", filename, strerror(errno));
return -1;
}
dir = bctbx_dirname(filename);
base = bctbx_basename(filename);
bctbx_message("Redirecting traces to file [%s]", filename);
filehandler = bctbx_create_file_log_handler(0, dir, base, log_file);
bctbx_add_log_handler(filehandler);
if (dir) bctbx_free(dir);
if (base) bctbx_free(base);
return 0;
}
#if !defined(__ANDROID__) && !(defined(BCTBX_WINDOWS_PHONE) || defined(BCTBX_WINDOWS_UNIVERSAL))
static const char* lime_helper =
"\t\t\t--verbose\n"
"\t\t\t--silent\n"
"\t\t\t--log-file <output log file path>\n";
int main(int argc, char *argv[]) {
int i;
int ret;
bzrtp_tester_init();
bzrtp_tester_init(NULL);
for (i = 1; i < argc; ++i) {
int ret = bc_tester_parse_args(argc, argv, i);
if (ret > 0) {
i += ret - 1;
continue;
} else if (ret < 0) {
bc_tester_helper(argv[0], "");
}
return ret;
if (strstr(argv[0], ".libs")) {
int prefix_length = (int)(strstr(argv[0], ".libs") - argv[0]) + 1;
char prefix[200];
sprintf(prefix, "%s%.*s", argv[0][0] == '/' ? "" : "./", prefix_length, argv[0]);
bc_tester_set_resource_dir_prefix(prefix);
bc_tester_set_writable_dir_prefix(prefix);
}
for(i = 1; i < argc; ++i) {
if (strcmp(argv[i],"--verbose")==0){
bctbx_set_log_level(log_domain, BCTBX_LOG_DEBUG);
bctbx_set_log_level(BCTBX_LOG_DOMAIN,BCTBX_LOG_DEBUG);
verbose = 1;
} else if (strcmp(argv[i],"--silent")==0){
bctbx_set_log_level(log_domain, BCTBX_LOG_FATAL);
bctbx_set_log_level(BCTBX_LOG_DOMAIN, BCTBX_LOG_FATAL);
verbose = 0;
} else if (strcmp(argv[i],"--log-file")==0){
CHECK_ARG("--log-file", ++i, argc);
if (bzrtp_tester_set_log_file(argv[i]) < 0) return -2;
}else {
int ret = bc_tester_parse_args(argc, argv, i);
if (ret>0) {
i += ret - 1;
continue;
} else if (ret<0) {
bc_tester_helper(argv[0], lime_helper);
}
return ret;
}
}
ret = bc_tester_start(argv[0]);
bzrtp_tester_uninit();
bctbx_uninit_logger();
return ret;
}
#endif
/*
@fiel bzrtpTest.h
@author Johan Pascal
@copyright Copyright (C) 2017 Belledonne Communications SARL
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 3 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef bzrtpTester_h
#define bzrtpTester_h
#define BCTOOLBOX_LOG_DOMAIN "bzrtp-tester"
#include <bctoolbox/logging.h>
#define bzrtp_message bctbx_message
#include <bctoolbox/tester.h>
extern test_suite_t crypto_utils_test_suite;
extern test_suite_t packet_parser_test_suite;
extern test_suite_t zidcache_test_suite;
extern test_suite_t key_exchange_test_suite;
extern int verbose;
#endif // bzrtpTester_h
......@@ -24,9 +24,9 @@
#include <stdlib.h>
#include "bzrtp/bzrtp.h"
#include <bctoolbox/tester.h>
#include "testUtils.h"
#include "zidCache.h"
#include "bzrtpTest.h"
#ifdef ZIDCACHE_ENABLED
#include "sqlite3.h"
......@@ -40,7 +40,7 @@ static const char *xmlCacheMigration = "<?xml version=\"1.0\" encoding=\"UTF-8\"
void test_cache_getSelfZID(void) {
static void test_cache_getSelfZID(void) {
#ifdef ZIDCACHE_ENABLED
bzrtpContext_t *aliceContext;
sqlite3 *aliceDB=NULL;
......@@ -143,7 +143,7 @@ void test_cache_getSelfZID(void) {
#endif
}
void test_cache_zrtpSecrets(void) {
static void test_cache_zrtpSecrets(void) {
#ifdef ZIDCACHE_ENABLED
bzrtpContext_t *aliceContext;
sqlite3 *aliceDB=NULL;
......@@ -198,7 +198,7 @@ void test_cache_zrtpSecrets(void) {
#endif /* ZIDCACHE_ENABLED */
}
void test_cache_migration(void) {
static void test_cache_migration(void) {
#ifdef ZIDCACHE_ENABLED
#ifdef HAVE_LIBXML2
uint8_t pattern_selfZIDalice[12] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb};
......@@ -231,3 +231,19 @@ void test_cache_migration(void) {
bzrtp_message("Test skipped as ZID cache is disabled\n");
#endif /* ZIDCACHE_ENABLED */
}
static test_t zidcache_tests[] = {
TEST_NO_TAG("SelfZID", test_cache_getSelfZID),
TEST_NO_TAG("ZRTP secrets", test_cache_zrtpSecrets),
TEST_NO_TAG("Migration", test_cache_migration),
};
test_suite_t zidcache_test_suite = {
"ZID Cache",
NULL,
NULL,
NULL,
NULL,
sizeof(zidcache_tests) / sizeof(zidcache_tests[0]),
zidcache_tests
};
/**
@file bzrtpZidCacheTest.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_cache_getSelfZID(void);
void test_cache_zrtpSecrets(void);
void test_cache_migration(void);
......@@ -28,6 +28,8 @@
#include "testUtils.h"
#include "cryptoUtils.h"
#include "bzrtpTest.h"
#ifndef _WIN32
#if !defined(__QNXNTO__) && !(defined(__ANDROID__) && defined(__LP64__))