blob: 39e20a796788e3c73a205771ad729a2dcd686568 [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>
21#include <libzrtpcpp/zrtpccrtp.h>
22#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);
491// tx->initialize("test_t.zid", true, &config);
492 tx->initialize("test_t.zid", true);
493 tx->setMultiStrParams(multiParams);
494
495 prefix = "TX Multi: ";
496 mcb = new MyUserCallbackMulti(tx);
497 mcb->setPrefix(prefix);
498 }
499 else {
500 tx = new SymmetricZRTPSession(pattern.getDestinationAddress(),
501 pattern.getDestinationPort()+2);
502 //config.addHashAlgo(Sha384);
503// tx->initialize("test_t.zid", true, &config);
504 if (mitm) { // Act as trusted MitM - could be enrolled
505 tx->setMitmMode(true);
506 }
507
508 tx->setSignSas(signsas);
509 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.
521 cout << prefix << "Hello hash: " << tx->getHelloHash() << endl;
522 cout << prefix << "Hello hash length: " << tx->getHelloHash().length() << endl;
523 tx->setUserCallback(mcb);
524 tx->setSchedulingTimeout(10000);
525 tx->setExpireTimeout(1000000);
526
527 tx->startRunning();
528
529 tx->setPayloadFormat(StaticPayloadFormat(sptPCMU));
530
531 if (!multiParams.empty()) {
532 if (!tx->addDestination(pattern.getDestinationAddress(),
533 pattern.getDestinationPort()+10) ) {
534 return 1;
535 }
536 }
537 else {
538 if (!tx->addDestination(pattern.getDestinationAddress(),
539 pattern.getDestinationPort()) ) {
540 return 1;
541 }
542 }
543 tx->startZrtp();
544
545 // 2 packets per second (packet duration of 500ms)
546 uint32 period = 500;
547 uint16 inc = tx->getCurrentRTPClockRate()/2;
548 TimerPort::setTimer(period);
549 uint32 i;
550 for (i = 0; i < pattern.getPacketsNumber(); i++ ) {
551 tx->putData(i*inc,
552 pattern.getPacketData(i),
553 pattern.getPacketSize(i));
554 cout << prefix << "Sent some data: " << i << endl;
555 Thread::sleep(TimerPort::getTimer());
556 TimerPort::incTimer(period);
557 }
558 tx->putData(i*inc, (unsigned char*)"exit", 5);
559 Thread::sleep(TimerPort::getTimer());
560 delete tx;
561 return 0;
562}
563
564
565int ZrtpRecvPacketTransmissionTestCB::doTest() {
566
567 ZrtpConfigure config;
568
569 MyUserCallback* mcb;
570 if (!multiParams.empty()) {
571 rx = new SymmetricZRTPSession(pattern.getDestinationAddress(),
572 pattern.getDestinationPort()+10);
573
574// rx->initialize("test_r.zid", true, &config);
575 rx->initialize("test_r.zid", true);
576 rx->setMultiStrParams(multiParams);
577
578 prefix = "RX Multi: ";
579 mcb = new MyUserCallbackMulti(rx);
580 mcb->setPrefix(prefix);
581 }
582 else {
583 rx = new SymmetricZRTPSession(pattern.getDestinationAddress(),
584 pattern.getDestinationPort());
585 config.setStandardConfig();
586 if (enroll)
587 config.setTrustedMitM(true); // allow a trusted MitM to start enrollment process
588
589 rx->setSignSas(signsas);
590
591 // config.addHashAlgo(Sha384);
592 rx->initialize("test_r.zid", true, &config);
593// rx->initialize("test_r.zid", true);
594
595 prefix = "RX: ";
596 mcb = new MyUserCallback(rx);
597 mcb->setPrefix(prefix);
598 }
599 // At this point the Hello hash is available. See ZRTP specification
600 // chapter 9.1 for further information when an how to use the Hello
601 // hash.
602 cout << prefix << "Hello hash: " << rx->getHelloHash() << endl;
603 cout << prefix << "Hello hash length: " << rx->getHelloHash().length() << endl;
604 rx->setUserCallback(mcb);
605 rx->setSchedulingTimeout(10000);
606 rx->setExpireTimeout(1000000);
607
608 rx->startRunning();
609 rx->setPayloadFormat(StaticPayloadFormat(sptPCMU));
610 // arbitrary number of loops to provide time to start transmitter
611 if (!multiParams.empty()) {
612 if (!rx->addDestination(pattern.getDestinationAddress(),
613 pattern.getDestinationPort()+2+10) ) {
614 return 1;
615 }
616 }
617 else {
618 if (!rx->addDestination(pattern.getDestinationAddress(),
619 pattern.getDestinationPort()+2) ) {
620 return 1;
621 }
622 }
623// rx->startZrtp();
624
625 for ( int i = 0; i < 5000 ; i++ ) {
626 const AppDataUnit* adu;
627 while ( (adu = rx->getData(rx->getFirstTimestamp())) ) {
628 cerr << prefix << "got some data: " << adu->getData() << endl;
629 if (*adu->getData() == 'e') {
630 delete adu;
631 delete rx;
632 return 0;
633 }
634 delete adu;
635 }
636 Thread::sleep(70);
637 }
638 delete rx;
639 return 0;
640}
641
642
643int main(int argc, char *argv[])
644{
645 int result = 0;
646
647 char c;
648
649 /* check args */
650 while (1) {
651 c = getopt(argc, argv, "rsSmeu");
652 if (c == -1) {
653 break;
654 }
655 switch (c) {
656 case 'r':
657 recver = true;
658 break;
659 case 's':
660 sender = true;
661 break;
662 case 'm':
663 mitm = true;
664 break;
665 case 'e':
666 enroll = true;
667 break;
668 case 'u':
669 untrusted = true;
670 break;
671 case 'S':
672 signsas = true;
673 break;
674 default:
675 cerr << "Wrong Arguments, only -s and -r are accepted" << endl;
676 }
677 }
678
679 if (sender || recver) {
680 if (sender) {
681 cout << "Running as sender" << endl;
682 }
683 else {
684 cout << "Running as receiver" << endl;
685 }
686 }
687 else {
688 cerr << "No send or receive argument specificied" << endl;
689 exit(1);
690 }
691
692 if ( sender ) {
693 ztxcb = new ZrtpSendPacketTransmissionTestCB();
694 ztxcbMulti = new ZrtpSendPacketTransmissionTestCB();
695 ztxcb->start();
696 ztxcb->join();
697 ztxcbMulti->join();
698 } else if ( recver ) {
699 zrxcb = new ZrtpRecvPacketTransmissionTestCB();
700 zrxcbMulti = new ZrtpRecvPacketTransmissionTestCB();
701 zrxcb->start();
702 zrxcb->join();
703 zrxcbMulti->join();
704 }
705
706 exit(result);
707}
708
709/** EMACS **
710 * Local variables:
711 * mode: c++
712 * c-default-style: ellemtel
713 * c-basic-offset: 4
714 * End:
715 */