blob: d7042ed0b0f1b798b113401caafa622cd8de95d8 [file] [log] [blame]
Alexandre Lision51140e12013-12-02 10:54:09 -05001// Test ZRTP extension for ccRTP
2//
3// Copyright (C) 2008 Werner Dittmann <Werner.Dittmann@t-online.de>
4//
5// This program is free software; you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation; either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program; if not, write to the Free Software
17// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19#include <cstdlib>
20#include <map>
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -050021#include <zrtpccrtp.h>
Alexandre Lision51140e12013-12-02 10:54:09 -050022#include <libzrtpcpp/ZrtpUserCallback.h>
23#include <libzrtpcpp/ZrtpConfigure.h>
24
25using namespace ost;
26using namespace std;
27using namespace GnuZrtpCodes;
28
29/* maybe should be by special define...
30static void hexdump(const char* title, const unsigned char *s, int l) {
31 int n=0;
32
33 if (s == NULL) return;
34
35 fprintf(stderr, "%s",title);
36 for( ; n < l ; ++n)
37 {
38 if((n%16) == 0)
39 fprintf(stderr, "\n%04x",n);
40 fprintf(stderr, " %02x",s[n]);
41 }
42 fprintf(stderr, "\n");
43}
44*/
45
46class PacketsPattern
47{
48public:
49 inline const InetHostAddress&
50 getDestinationAddress() const
51 {
52 return destinationAddress;
53 }
54
55 inline const tpport_t
56 getDestinationPort() const
57 {
58 return destinationPort;
59 }
60
61 uint32
62 getPacketsNumber() const
63 {
64 return packetsNumber;
65 }
66
67 uint32
68 getSsrc() const
69 {
70 return 0xdeadbeef;
71 }
72
73 const unsigned char*
74 getPacketData(uint32 i)
75 {
76 return data[i%2];
77 }
78
79 const size_t
80 getPacketSize(uint32 i)
81 {
82 return strlen((char*)data[i%2]) + 1 ;
83 }
84
85private:
86 static const InetHostAddress destinationAddress;
87 static const uint16 destinationPort = 5002;
88 static const uint32 packetsNumber = 10;
89 static const uint32 packetsSize = 12;
90 static const unsigned char* data[];
91};
92
93const InetHostAddress PacketsPattern::destinationAddress =
94 InetHostAddress("localhost");
95
96const unsigned char* PacketsPattern::data[] = {
97 (unsigned char*)"0123456789\n",
98 (unsigned char*)"987654321\n"
99};
100
101PacketsPattern pattern;
102
103class ZrtpRecvPacketTransmissionTestCB;
104class ZrtpSendPacketTransmissionTestCB;
105class MyUserCallback;
106class MyUserCallbackMulti;
107
108static ZrtpRecvPacketTransmissionTestCB* zrxcb = NULL;
109static ZrtpSendPacketTransmissionTestCB* ztxcb = NULL;
110
111static ZrtpRecvPacketTransmissionTestCB* zrxcbMulti = NULL;
112static ZrtpSendPacketTransmissionTestCB* ztxcbMulti = NULL;
113
114static bool enroll = false;
115static bool mitm = false;
116static bool untrusted = false;
117static bool sender = false;
118static bool recver = false;
119static bool signsas = false;
120
121
122/**
123 * SymmetricZRTPSession in security mode and using a callback class.
124 *
125 * The next two classes show how to use <code>SymmetricZRTPSession</code>
126 * using the standard ZRTP handshake an switching to encrypted (SRTP) mode.
127 * The application enables this by calling <code>initialize(...)</code>.
128 * In addition the application sets a callback class (see above). ZRTP calls
129 * the methods of the callback class and the application may implement
130 * appropriate methods to deal with these triggers.
131 */
132
133class
134 ZrtpSendPacketTransmissionTestCB : public Thread, public TimerPort {
135
136private:
137 SymmetricZRTPSession* tx;
138 string multiParams;
139 string prefix;
140
141public:
142
143 ZrtpSendPacketTransmissionTestCB(): tx(NULL), multiParams("") {};
144
145 void run() {
146 doTest();
147 }
148
149 int doTest();
150
151 string getMultiStrParams() {
152 return tx->getMultiStrParams();
153 }
154
155 void setMultiStrParams(string params) {
156 multiParams = params;
157 return;
158 }
159};
160
161
162class
163 ZrtpRecvPacketTransmissionTestCB: public Thread {
164
165private:
166 SymmetricZRTPSession* rx;
167 string multiParams;
168 string prefix;
169
170public:
171 ZrtpRecvPacketTransmissionTestCB(): rx(NULL), multiParams("") {};
172
173 void run() {
174 doTest();
175 }
176
177 int doTest();
178
179 string getMultiStrParams() {
180 return rx->getMultiStrParams();
181 }
182
183 void setMultiStrParams(string params) {
184 multiParams = params;
185 return;
186 }
187};
188
189/**
190 * Simple User Callback class
191 *
192 * This class overwrite some methods from ZrtpUserCallback to get information
193 * about ZRTP processing and information about ZRTP results. The standard
194 * implementation of this class just perform return, thus effectively
195 * supressing any callback or trigger.
196 */
197class MyUserCallback: public ZrtpUserCallback {
198
199protected:
200 static map<int32, std::string*> infoMap;
201 static map<int32, std::string*> warningMap;
202 static map<int32, std::string*> severeMap;
203 static map<int32, std::string*> zrtpMap;
204 static map<int32, std::string*> enrollMap;
205
206
207 static bool initialized;
208
209 SymmetricZRTPSession* session;
210
211 std::string prefix;
212
213public:
214 MyUserCallback(SymmetricZRTPSession* s): session(s), prefix("default: ") {
215
216 if (initialized) {
217 return;
218 }
219 infoMap.insert(pair<int32, std::string*>(InfoHelloReceived, new string("Hello received, preparing a Commit")));
220 infoMap.insert(pair<int32, std::string*>(InfoCommitDHGenerated, new string("Commit: Generated a public DH key")));
221 infoMap.insert(pair<int32, std::string*>(InfoRespCommitReceived, new string("Responder: Commit received, preparing DHPart1")));
222 infoMap.insert(pair<int32, std::string*>(InfoDH1DHGenerated, new string("DH1Part: Generated a public DH key")));
223 infoMap.insert(pair<int32, std::string*>(InfoInitDH1Received, new string("Initiator: DHPart1 received, preparing DHPart2")));
224 infoMap.insert(pair<int32, std::string*>(InfoRespDH2Received, new string("Responder: DHPart2 received, preparing Confirm1")));
225 infoMap.insert(pair<int32, std::string*>(InfoInitConf1Received, new string("Initiator: Confirm1 received, preparing Confirm2")));
226 infoMap.insert(pair<int32, std::string*>(InfoRespConf2Received, new string("Responder: Confirm2 received, preparing Conf2Ack")));
227 infoMap.insert(pair<int32, std::string*>(InfoRSMatchFound, new string("At least one retained secrets matches - security OK")));
228 infoMap.insert(pair<int32, std::string*>(InfoSecureStateOn, new string("Entered secure state")));
229 infoMap.insert(pair<int32, std::string*>(InfoSecureStateOff, new string("No more security for this session")));
230
231 warningMap.insert(pair<int32, std::string*>(WarningDHAESmismatch,
232 new string("Commit contains an AES256 cipher but does not offer a Diffie-Helman 4096")));
233 warningMap.insert(pair<int32, std::string*>(WarningGoClearReceived, new string("Received a GoClear message")));
234 warningMap.insert(pair<int32, std::string*>(WarningDHShort,
235 new string("Hello offers an AES256 cipher but does not offer a Diffie-Helman 4096")));
236 warningMap.insert(pair<int32, std::string*>(WarningNoRSMatch, new string("No retained secret matches - verify SAS")));
237 warningMap.insert(pair<int32, std::string*>(WarningCRCmismatch, new string("Internal ZRTP packet checksum mismatch - packet dropped")));
238 warningMap.insert(pair<int32, std::string*>(WarningSRTPauthError, new string("Dropping packet because SRTP authentication failed!")));
239 warningMap.insert(pair<int32, std::string*>(WarningSRTPreplayError, new string("Dropping packet because SRTP replay check failed!")));
240 warningMap.insert(pair<int32, std::string*>(WarningNoExpectedRSMatch,
241 new string("Valid retained shared secrets availabe but no matches found - must verify SAS")));
242
243 severeMap.insert(pair<int32, std::string*>(SevereHelloHMACFailed, new string("Hash HMAC check of Hello failed!")));
244 severeMap.insert(pair<int32, std::string*>(SevereCommitHMACFailed, new string("Hash HMAC check of Commit failed!")));
245 severeMap.insert(pair<int32, std::string*>(SevereDH1HMACFailed, new string("Hash HMAC check of DHPart1 failed!")));
246 severeMap.insert(pair<int32, std::string*>(SevereDH2HMACFailed, new string("Hash HMAC check of DHPart2 failed!")));
247 severeMap.insert(pair<int32, std::string*>(SevereCannotSend, new string("Cannot send data - connection or peer down?")));
248 severeMap.insert(pair<int32, std::string*>(SevereProtocolError, new string("Internal protocol error occured!")));
249 severeMap.insert(pair<int32, std::string*>(SevereNoTimer, new string("Cannot start a timer - internal resources exhausted?")));
250 severeMap.insert(pair<int32, std::string*>(SevereTooMuchRetries,
251 new string("Too much retries during ZRTP negotiation - connection or peer down?")));
252
253 zrtpMap.insert(pair<int32, std::string*>(MalformedPacket, new string("Malformed packet (CRC OK, but wrong structure)")));
254 zrtpMap.insert(pair<int32, std::string*>(CriticalSWError, new string("Critical software error")));
255 zrtpMap.insert(pair<int32, std::string*>(UnsuppZRTPVersion, new string("Unsupported ZRTP version")));
256 zrtpMap.insert(pair<int32, std::string*>(HelloCompMismatch, new string("Hello components mismatch")));
257 zrtpMap.insert(pair<int32, std::string*>(UnsuppHashType, new string("Hash type not supported")));
258 zrtpMap.insert(pair<int32, std::string*>(UnsuppCiphertype, new string("Cipher type not supported")));
259 zrtpMap.insert(pair<int32, std::string*>(UnsuppPKExchange, new string("Public key exchange not supported")));
260 zrtpMap.insert(pair<int32, std::string*>(UnsuppSRTPAuthTag, new string("SRTP auth. tag not supported")));
261 zrtpMap.insert(pair<int32, std::string*>(UnsuppSASScheme, new string("SAS scheme not supported")));
262 zrtpMap.insert(pair<int32, std::string*>(NoSharedSecret, new string("No shared secret available, DH mode required")));
263 zrtpMap.insert(pair<int32, std::string*>(DHErrorWrongPV, new string("DH Error: bad pvi or pvr ( == 1, 0, or p-1)")));
264 zrtpMap.insert(pair<int32, std::string*>(DHErrorWrongHVI, new string("DH Error: hvi != hashed data")));
265 zrtpMap.insert(pair<int32, std::string*>(SASuntrustedMiTM, new string("Received relayed SAS from untrusted MiTM")));
266 zrtpMap.insert(pair<int32, std::string*>(ConfirmHMACWrong, new string("Auth. Error: Bad Confirm pkt HMAC")));
267 zrtpMap.insert(pair<int32, std::string*>(NonceReused, new string("Nonce reuse")));
268 zrtpMap.insert(pair<int32, std::string*>(EqualZIDHello, new string("Equal ZIDs in Hello")));
269 zrtpMap.insert(pair<int32, std::string*>(GoCleatNotAllowed, new string("GoClear packet received, but not allowed")));
270
271 enrollMap.insert(pair<int32, std::string*>(EnrollmentRequest, new string("Trusted MitM enrollment requested")));
272 enrollMap.insert(pair<int32, std::string*>(EnrollmentCanceled, new string("Trusted MitM enrollment canceled by user")));
273 enrollMap.insert(pair<int32, std::string*>(EnrollmentFailed, new string("Trusted MitM enrollment failed")));
274 enrollMap.insert(pair<int32, std::string*>(EnrollmentOk, new string("Trusted MitM enrollment OK")));
275
276 initialized = true;
277 }
278
279 void showMessage(GnuZrtpCodes::MessageSeverity sev, int32_t subCode) {
280 string* msg;
281 uint8_t sasHash[32];
282
283 if (sev == Info) {
284 msg = infoMap[subCode];
285 if (msg != NULL) {
286 cout << prefix << *msg << endl;
287 }
288 // this sets up and starts off the multi-stream test
289 if (subCode == InfoSecureStateOn) {
290 if (zrxcbMulti != NULL) {
291 zrxcbMulti->setMultiStrParams(session->getMultiStrParams());
292 zrxcbMulti->start();
293 }
294 if (ztxcbMulti != NULL) {
295 ztxcbMulti->setMultiStrParams(session->getMultiStrParams());
296 ztxcbMulti->start();
297 }
298 if (sender) {
299 if (mitm && !enroll) { // sender now acts as trusted PBX in normal mode, not in enrollement service
300 std::string render = session->getSasType();
301 for (int i = 0; i < 32; i++) {
302 sasHash[i] = 0;
303 }
304 if (untrusted) { // treat receiver as non-enrolled receiver
305 cout << prefix << "send SAS relay to non-enrolled receiver" << endl;
306 session->sendSASRelayPacket(sasHash, render);
307 }
308 else {
309 sasHash[0] = 0x11;
310 sasHash[1] = 0x22;
311 sasHash[2] = 0x33;
312 sasHash[4] = 0x44;
313 cout << prefix << "send SAS relay to enrolled receiver" << endl;
314 session->sendSASRelayPacket(sasHash, render);
315 }
316 }
317 }
318 }
319 }
320 if (sev == Warning) {
321 msg = warningMap[subCode];
322 if (msg != NULL) {
323 cout << prefix << *msg << endl;
324 }
325 }
326 if (sev == Severe) {
327 msg = severeMap[subCode];
328 if (msg != NULL) {
329 cout << prefix << *msg << endl;
330 }
331 }
332 if (sev == ZrtpError) {
333 if (subCode < 0) { // received an error packet from peer
334 subCode *= -1;
335 cout << prefix << "Received error packet: ";
336 }
337 else {
338 cout << prefix << "Sent error packet: ";
339 }
340 msg = zrtpMap[subCode];
341 if (msg != NULL) {
342 cout << prefix << *msg << endl;
343 }
344 }
345 }
346
347 void zrtpNegotiationFailed(GnuZrtpCodes::MessageSeverity sev, int32_t subCode) {
348 string* msg;
349 if (sev == ZrtpError) {
350 if (subCode < 0) { // received an error packet from peer
351 subCode *= -1;
352 cout << prefix << "Received error packet: ";
353 }
354 else {
355 cout << prefix << "Sent error packet: ";
356 }
357 msg = zrtpMap[subCode];
358 if (msg != NULL) {
359 cout << prefix << *msg << endl;
360 }
361 }
362 else {
363 msg = severeMap[subCode];
364 cout << prefix << *msg << endl;
365 }
366 }
367
368 void zrtpAskEnrollment(GnuZrtpCodes::InfoEnrollment info) {
369 string* msg = enrollMap[info];
370 cout << prefix << *msg << endl;
371 session->acceptEnrollment(true);
372 }
373
374 void zrtpInformEnrollment(GnuZrtpCodes::InfoEnrollment info) {
375 string* msg = enrollMap[info];
376 cout << prefix << *msg << endl;
377 }
378
379 void secureOn(std::string cipher) {
380 cout << prefix << "Using cipher:" << cipher << endl;
381 cout << prefix << "peer hello hash: " << session->getPeerHelloHash() << endl;
382 }
383
384 void showSAS(std::string sas, bool verified) {
385 cout << prefix << "SAS is: " << sas << endl;
386
387 }
388
389 void signSAS(uint8_t* sasHash) {
390 cout << prefix << "SAS to sign" << endl;
391 uint8_t sign[12];
392 sign[0] = sasHash[0];
393 sign[1] = sasHash[1];
394 sign[2] = sasHash[2];
395 sign[3] = sasHash[3];
396 if (recver) {
397 sign[4] = 'R';
398 sign[5] = 'E';
399 sign[6] = 'C';
400 sign[7] = 'E';
401 sign[8] = 'I';
402 sign[9] = 'V';
403 sign[10] = 'E';
404 sign[11] = 'R';
405 }
406 else {
407 sign[4] = 'T';
408 sign[5] = 'R';
409 sign[6] = 'A';
410 sign[7] = 'N';
411 sign[8] = 'S';
412 sign[9] = 'M';
413 sign[10] = 'I';
414 sign[11] = 'T';
415 }
416 cout << prefix << "set signature data result: " << session->setSignatureData(sign, 12) << endl;
417 }
418
419 bool checkSASSignature(uint8_t* sasHash) {
420 cout << prefix << "check signature" << endl;
421 const uint8_t* sign = session->getSignatureData();
422 cout << prefix << "signature: " << sign << endl;
423 return true;
424 }
425
426 void setPrefix(std::string p) {
427 prefix = p;
428 }
429};
430
431map<int32, std::string*>MyUserCallback::infoMap;
432map<int32, std::string*>MyUserCallback::warningMap;
433map<int32, std::string*>MyUserCallback::severeMap;
434map<int32, std::string*>MyUserCallback::zrtpMap;
435map<int32, std::string*>MyUserCallback::enrollMap;
436
437bool MyUserCallback::initialized = false;
438
439
440class MyUserCallbackMulti: public MyUserCallback {
441
442public:
443
444 MyUserCallbackMulti(SymmetricZRTPSession* s): MyUserCallback(s) {
445 }
446
447 void showMessage(GnuZrtpCodes::MessageSeverity sev, int32_t subCode) {
448 string* msg;
449 if (sev == Info) {
450 msg = infoMap[subCode];
451 if (msg != NULL) {
452 cout << prefix << *msg << endl;
453 }
454 }
455 if (sev == Warning) {
456 msg = warningMap[subCode];
457 if (msg != NULL) {
458 cout << prefix << *msg << endl;
459 }
460 }
461 if (sev == Severe) {
462 msg = severeMap[subCode];
463 if (msg != NULL) {
464 cout << prefix << *msg << endl;
465 }
466 }
467 if (sev == ZrtpError) {
468 if (subCode < 0) { // received an error packet from peer
469 subCode *= -1;
470 cout << prefix << "Received error packet: ";
471 }
472 else {
473 cout << prefix << "Sent error packet: ";
474 }
475 msg = zrtpMap[subCode];
476 if (msg != NULL) {
477 cout << prefix << *msg << endl;
478 }
479 }
480 }
481};
482
483int ZrtpSendPacketTransmissionTestCB::doTest() {
484
485 ZrtpConfigure config;
486
487 MyUserCallback* mcb;
488 if (!multiParams.empty()) {
489 tx = new SymmetricZRTPSession(pattern.getDestinationAddress(),
490 pattern.getDestinationPort()+2+10);
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500491
492 // tx->initialize("test_t.zid", true, &config);
Alexandre Lision51140e12013-12-02 10:54:09 -0500493 tx->initialize("test_t.zid", true);
494 tx->setMultiStrParams(multiParams);
495
496 prefix = "TX Multi: ";
497 mcb = new MyUserCallbackMulti(tx);
498 mcb->setPrefix(prefix);
499 }
500 else {
501 tx = new SymmetricZRTPSession(pattern.getDestinationAddress(),
502 pattern.getDestinationPort()+2);
Alexandre Lision51140e12013-12-02 10:54:09 -0500503 if (mitm) { // Act as trusted MitM - could be enrolled
504 tx->setMitmMode(true);
505 }
506
507 tx->setSignSas(signsas);
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500508// tx->initialize("test_t.zid", true, &config);
Alexandre Lision51140e12013-12-02 10:54:09 -0500509 tx->initialize("test_t.zid", true);
510
511 if (enroll) // act as PBX enrollement service
512 tx->setEnrollmentMode(true);
513
514 prefix = "TX: ";
515 mcb = new MyUserCallback(tx);
516 mcb->setPrefix(prefix);
517 }
518 // At this point the Hello hash is available. See ZRTP specification
519 // chapter 9.1 for further information when an how to use the Hello
520 // hash.
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500521 int numSupportedVersion = tx->getNumberSupportedVersions();
522 cout << "TX Hello hash 0: " << tx->getHelloHash(0) << endl;
523 cout << "TX Hello hash 0 length: " << tx->getHelloHash(0).length() << endl;
524 if (numSupportedVersion > 1) {
525 cout << "TX Hello hash 1: " << tx->getHelloHash(1) << endl;
526 cout << "TX Hello hash 1 length: " << tx->getHelloHash(1).length() << endl;
527 }
Alexandre Lision51140e12013-12-02 10:54:09 -0500528 tx->setUserCallback(mcb);
529 tx->setSchedulingTimeout(10000);
530 tx->setExpireTimeout(1000000);
531
532 tx->startRunning();
533
534 tx->setPayloadFormat(StaticPayloadFormat(sptPCMU));
535
536 if (!multiParams.empty()) {
537 if (!tx->addDestination(pattern.getDestinationAddress(),
538 pattern.getDestinationPort()+10) ) {
539 return 1;
540 }
541 }
542 else {
543 if (!tx->addDestination(pattern.getDestinationAddress(),
544 pattern.getDestinationPort()) ) {
545 return 1;
546 }
547 }
548 tx->startZrtp();
549
550 // 2 packets per second (packet duration of 500ms)
551 uint32 period = 500;
552 uint16 inc = tx->getCurrentRTPClockRate()/2;
553 TimerPort::setTimer(period);
554 uint32 i;
555 for (i = 0; i < pattern.getPacketsNumber(); i++ ) {
556 tx->putData(i*inc,
557 pattern.getPacketData(i),
558 pattern.getPacketSize(i));
559 cout << prefix << "Sent some data: " << i << endl;
560 Thread::sleep(TimerPort::getTimer());
561 TimerPort::incTimer(period);
562 }
563 tx->putData(i*inc, (unsigned char*)"exit", 5);
564 Thread::sleep(TimerPort::getTimer());
565 delete tx;
566 return 0;
567}
568
569
570int ZrtpRecvPacketTransmissionTestCB::doTest() {
571
572 ZrtpConfigure config;
573
574 MyUserCallback* mcb;
575 if (!multiParams.empty()) {
576 rx = new SymmetricZRTPSession(pattern.getDestinationAddress(),
577 pattern.getDestinationPort()+10);
578
579// rx->initialize("test_r.zid", true, &config);
580 rx->initialize("test_r.zid", true);
581 rx->setMultiStrParams(multiParams);
582
583 prefix = "RX Multi: ";
584 mcb = new MyUserCallbackMulti(rx);
585 mcb->setPrefix(prefix);
586 }
587 else {
588 rx = new SymmetricZRTPSession(pattern.getDestinationAddress(),
589 pattern.getDestinationPort());
590 config.setStandardConfig();
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500591// config.clear();
592// config.addAlgo(SasType, zrtpSasTypes.getByName("B256"));
593
Alexandre Lision51140e12013-12-02 10:54:09 -0500594 if (enroll)
595 config.setTrustedMitM(true); // allow a trusted MitM to start enrollment process
596
597 rx->setSignSas(signsas);
598
Alexandre Lision51140e12013-12-02 10:54:09 -0500599 rx->initialize("test_r.zid", true, &config);
600// rx->initialize("test_r.zid", true);
601
602 prefix = "RX: ";
603 mcb = new MyUserCallback(rx);
604 mcb->setPrefix(prefix);
605 }
606 // At this point the Hello hash is available. See ZRTP specification
607 // chapter 9.1 for further information when an how to use the Hello
608 // hash.
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500609 int numSupportedVersion = rx->getNumberSupportedVersions();
610 cout << "RX Hello hash 0: " << rx->getHelloHash(0) << endl;
611 cout << "RX Hello hash 0 length: " << rx->getHelloHash(0).length() << endl;
612 if (numSupportedVersion > 1) {
613 cout << "RX Hello hash 1: " << rx->getHelloHash(1) << endl;
614 cout << "RX Hello hash 1 length: " << rx->getHelloHash(1).length() << endl;
615 }
Alexandre Lision51140e12013-12-02 10:54:09 -0500616 rx->setUserCallback(mcb);
617 rx->setSchedulingTimeout(10000);
618 rx->setExpireTimeout(1000000);
619
620 rx->startRunning();
621 rx->setPayloadFormat(StaticPayloadFormat(sptPCMU));
622 // arbitrary number of loops to provide time to start transmitter
623 if (!multiParams.empty()) {
624 if (!rx->addDestination(pattern.getDestinationAddress(),
625 pattern.getDestinationPort()+2+10) ) {
626 return 1;
627 }
628 }
629 else {
630 if (!rx->addDestination(pattern.getDestinationAddress(),
631 pattern.getDestinationPort()+2) ) {
632 return 1;
633 }
634 }
635// rx->startZrtp();
636
637 for ( int i = 0; i < 5000 ; i++ ) {
638 const AppDataUnit* adu;
639 while ( (adu = rx->getData(rx->getFirstTimestamp())) ) {
640 cerr << prefix << "got some data: " << adu->getData() << endl;
641 if (*adu->getData() == 'e') {
642 delete adu;
643 delete rx;
644 return 0;
645 }
646 delete adu;
647 }
648 Thread::sleep(70);
649 }
650 delete rx;
651 return 0;
652}
653
654
655int main(int argc, char *argv[])
656{
657 int result = 0;
658
659 char c;
660
661 /* check args */
662 while (1) {
663 c = getopt(argc, argv, "rsSmeu");
664 if (c == -1) {
665 break;
666 }
667 switch (c) {
668 case 'r':
669 recver = true;
670 break;
671 case 's':
672 sender = true;
673 break;
674 case 'm':
675 mitm = true;
676 break;
677 case 'e':
678 enroll = true;
679 break;
680 case 'u':
681 untrusted = true;
682 break;
683 case 'S':
684 signsas = true;
685 break;
686 default:
687 cerr << "Wrong Arguments, only -s and -r are accepted" << endl;
688 }
689 }
690
691 if (sender || recver) {
692 if (sender) {
693 cout << "Running as sender" << endl;
694 }
695 else {
696 cout << "Running as receiver" << endl;
697 }
698 }
699 else {
700 cerr << "No send or receive argument specificied" << endl;
701 exit(1);
702 }
703
704 if ( sender ) {
705 ztxcb = new ZrtpSendPacketTransmissionTestCB();
706 ztxcbMulti = new ZrtpSendPacketTransmissionTestCB();
707 ztxcb->start();
708 ztxcb->join();
709 ztxcbMulti->join();
710 } else if ( recver ) {
711 zrxcb = new ZrtpRecvPacketTransmissionTestCB();
712 zrxcbMulti = new ZrtpRecvPacketTransmissionTestCB();
713 zrxcb->start();
714 zrxcb->join();
715 zrxcbMulti->join();
716 }
717
718 exit(result);
719}
720
721/** EMACS **
722 * Local variables:
723 * mode: c++
724 * c-default-style: ellemtel
725 * c-basic-offset: 4
726 * End:
727 */