Commit 7781e465 authored by johan's avatar johan

Add tests specific to zrtp-hash attribute

parent a476fa1e
......@@ -99,6 +99,13 @@ uint8_t H87654321[4][32] = {
{0x8d, 0x0f, 0x5a, 0x20, 0x79, 0x97, 0x42, 0x01, 0x99, 0x45, 0x45, 0xf7, 0x0e, 0x31, 0x06, 0xe1, 0x05, 0xc0, 0xb9, 0x24, 0xe9, 0xc9, 0x78, 0xc7, 0x38, 0xf5, 0x97, 0x48, 0xef, 0x42, 0x6a, 0x3e}
};
/* Hello packet and matching zrtp-hash generated using libzrtpcpp */
#define ZRTPHASHPATTERN "1.10 3be3a5d605f6bc51951f6eb151a6ecbc071a9a2f4273ddd4affe5215d7300815"
#define ZRTPHASHPATTERN_WRONG "1.10 00e3a5d605f6bc51951f6eb151a6ecbc071a9a2f4273ddd4affe5215d7300815"
uint8_t HelloPacketZrtpHash[168] = {
0x10, 0x00, 0x00, 0x01, 0x5a, 0x52, 0x54, 0x50, 0x76, 0xdc, 0xa7, 0xbd, 0x50, 0x5a, 0x00, 0x26, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x20, 0x20, 0x31, 0x2e, 0x31, 0x30, 0x50, 0x4a, 0x53, 0x20, 0x5a, 0x52, 0x54, 0x50, 0x20, 0x33, 0x2e, 0x30, 0x2e, 0x30, 0x20, 0x20, 0xe4, 0xba, 0x78, 0xba, 0xa0, 0x2a, 0xd4, 0x36, 0x1a, 0xb8, 0xd2, 0xdd, 0x57, 0x8a, 0x68, 0x16, 0xbb, 0xe4, 0x05, 0xb8, 0x69, 0xb7, 0xaf, 0x06, 0x4d, 0x1c, 0x09, 0x53, 0x1c, 0xeb, 0xc6, 0x29, 0x20, 0x12, 0xa2, 0xf0, 0x6c, 0xfd, 0x0f, 0xfb, 0x88, 0xd8, 0xe6, 0x52, 0x00, 0x02, 0x44, 0x51, 0x53, 0x33, 0x38, 0x34, 0x53, 0x32, 0x35, 0x36, 0x32, 0x46, 0x53, 0x33, 0x41, 0x45, 0x53, 0x33, 0x32, 0x46, 0x53, 0x31, 0x41, 0x45, 0x53, 0x31, 0x53, 0x4b, 0x33, 0x32, 0x53, 0x4b, 0x36, 0x34, 0x48, 0x53, 0x33, 0x32, 0x48, 0x53, 0x38, 0x30, 0x45, 0x43, 0x32, 0x35, 0x44, 0x48, 0x33, 0x6b, 0x45, 0x43, 0x33, 0x38, 0x44, 0x48, 0x32, 0x6b, 0x4d, 0x75, 0x6c, 0x74, 0x42, 0x33, 0x32, 0x20, 0x05, 0xc9, 0xf1, 0x87, 0x2b, 0x41, 0xa9, 0x9a, 0x0a, 0x1d, 0xcd, 0x3c};
/* mac and zrtp keys */
uint8_t mackeyi[32] = {0xdc, 0x47, 0xe1, 0xc7, 0x48, 0x11, 0xb1, 0x54, 0x14, 0x2a, 0x91, 0x29, 0x9f, 0xa4, 0x8b, 0x45, 0x87, 0x16, 0x8d, 0x3a, 0xe6, 0xb0, 0x0c, 0x08, 0x4f, 0xa5, 0x48, 0xd5, 0x96, 0x67, 0x1a, 0x1b};
uint8_t mackeyr[32] = {0x3a, 0xa5, 0x22, 0x43, 0x26, 0x13, 0x8f, 0xd6, 0x54, 0x59, 0x40, 0xb8, 0x5c, 0xf4, 0x0f, 0x0c, 0xbc, 0x9c, 0x4f, 0x7d, 0x55, 0xeb, 0x4b, 0xa5, 0x1e, 0x1c, 0x42, 0xd0, 0x5e, 0xac, 0x12, 0x06};
......@@ -202,10 +209,6 @@ void test_parser_param(uint8_t hvi_trick) {
context87654321->channelContext[0]->peerPackets[HELLO_MESSAGE_STORE_ID] = zrtpPacket;
context12345678->channelContext[0]->selfPackets[HELLO_MESSAGE_STORE_ID] = zrtpPacket;
/* Set an incorrect peerHello Hash after the packet hello packet arrives */
retval = bzrtp_setPeerHelloHash(context87654321, 0x87654321, (uint8_t *)patternZRTPIncorrectHelloHash12345678, strlen((const char *)patternZRTPIncorrectHelloHash12345678));
CU_ASSERT_EQUAL_FATAL(retval,BZRTP_ERROR_HELLOHASH_MISMATCH);
/* Set the correct one */
retval = bzrtp_setPeerHelloHash(context87654321, 0x87654321, (uint8_t *)patternZRTPHelloHash12345678, strlen((const char *)patternZRTPHelloHash12345678));
CU_ASSERT_EQUAL_FATAL(retval,0);
......@@ -1900,3 +1903,43 @@ 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) {
bzrtpPacket_t *zrtpPacket;
int retval;
/* Create zrtp Context to use H0-H3 chains and others */
bzrtpContext_t *context12345678 = bzrtp_createBzrtpContext();
/* init the context so it's ready to receive a packet */
bzrtp_initBzrtpContext(context12345678, 0x12345678);
/* parse the hello packet */
zrtpPacket = bzrtp_packetCheck(HelloPacketZrtpHash, sizeof(HelloPacketZrtpHash), 0, &retval);
CU_ASSERT_EQUAL(retval, 0);
retval = bzrtp_packetParser(context12345678, context12345678->channelContext[0], HelloPacketZrtpHash, sizeof(HelloPacketZrtpHash), zrtpPacket);
CU_ASSERT_EQUAL(retval, 0);
/* store it in the peer hello hash structure so we can check it against the zrtp-hash */
context12345678->channelContext[0]->peerPackets[HELLO_MESSAGE_STORE_ID] = zrtpPacket;
retval = bzrtp_setPeerHelloHash(context12345678, 0x12345678, (uint8_t *)ZRTPHASHPATTERN, strlen((const char *)ZRTPHASHPATTERN));
CU_ASSERT_EQUAL(retval, 0);
/* set a wrong hello hash, this will also reset the session */
retval = bzrtp_setPeerHelloHash(context12345678, 0x12345678, (uint8_t *)ZRTPHASHPATTERN_WRONG, strlen((const char *)ZRTPHASHPATTERN));
CU_ASSERT_EQUAL(retval, BZRTP_ERROR_HELLOHASH_MISMATCH);
CU_ASSERT_TRUE(context12345678->channelContext[0]->peerPackets[HELLO_MESSAGE_STORE_ID]==NULL); /* session must have been reset, peer packets are cancelled */
/* Parse again the hello packet, the peer hello hash is still in the context and incorrect, so good packet must be rejected */
zrtpPacket = bzrtp_packetCheck(HelloPacketZrtpHash, sizeof(HelloPacketZrtpHash), 0, &retval);
CU_ASSERT_EQUAL(retval, 0);
retval = bzrtp_packetParser(context12345678, context12345678->channelContext[0], HelloPacketZrtpHash, sizeof(HelloPacketZrtpHash), zrtpPacket);
CU_ASSERT_EQUAL(retval, BZRTP_ERROR_HELLOHASH_MISMATCH);
/* set the correct peer hello hash(no packet in context so it just store it) and try again to parse the correct packet */
retval = bzrtp_setPeerHelloHash(context12345678, 0x12345678, (uint8_t *)ZRTPHASHPATTERN, strlen((const char *)ZRTPHASHPATTERN));
CU_ASSERT_EQUAL(retval, 0);
retval = bzrtp_packetParser(context12345678, context12345678->channelContext[0], HelloPacketZrtpHash, sizeof(HelloPacketZrtpHash), zrtpPacket);
CU_ASSERT_EQUAL(retval, 0);
}
......@@ -23,3 +23,4 @@ void test_parser(void);
void test_parser_hvi(void);
void test_parserComplete(void);
void test_stateMachine(void);
void test_zrtphash(void);
......@@ -78,6 +78,7 @@ int main(int argc, char *argv[] ) {
CU_add_test(parserTestSuite, "Parse hvi check fail", test_parser_hvi);
CU_add_test(parserTestSuite, "Parse Exchange", test_parserComplete);
CU_add_test(parserTestSuite, "State machine", test_stateMachine);
CU_add_test(parserTestSuite, "ZRTP-hash", test_zrtphash);
/* Run all suites */
for(i=0; suites[i]; i++){
......
......@@ -35,6 +35,7 @@ void bzrtp_message(const char *fmt, ...) {
va_start(args, fmt);
vprintf(fmt, args);
va_end(args);
fflush(NULL);
}
}
......@@ -46,6 +47,7 @@ void printHex(char *title, uint8_t *data, uint32_t length) {
printf ("0x%02x, ", data[i]);
}
printf ("\n");
fflush(NULL);
}
}
......@@ -189,6 +191,7 @@ void packetDump(bzrtpPacket_t *zrtpPacket, uint8_t addRawMessage) {
if (addRawMessage) {
printHex("Data", zrtpPacket->packetString, zrtpPacket->messageLength+16);
}
fflush(NULL);
}
}
......@@ -261,5 +264,6 @@ void dumpContext(char *title, bzrtpContext_t *zrtpContext) {
printHex("rs1ID", zrtpContext->responderCachedSecretHash.rs1ID, 8);
printHex("rs2ID", zrtpContext->responderCachedSecretHash.rs2ID, 8);
printHex("pbxID", zrtpContext->responderCachedSecretHash.pbxsecretID, 8);
fflush(NULL);
}
}
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