int CtZrtpSession::init(bool audio, bool video, int32_t callId, ZrtpConfigure* config) { int32_t ret = 1; synchEnter(); ZrtpConfigure* configOwn = NULL; if (config == NULL) { config = configOwn = new ZrtpConfigure(); setupConfiguration(config); config->setTrustedMitM(false); #if defined AXO_SUPPORT config->setSasSignature(true); #endif } config->setParanoidMode(enableParanoidMode); callId_ = callId; ZIDCache* zf = getZidCacheInstance(); if (!zf->isOpen()) { ret = -1; } if (ret > 0) { const uint8_t* ownZid = zf->getZid(); CtZrtpStream *stream; // Create CTZrtpStream object only once, they are availbe for the whole // lifetime of the session. if (audio) { if (streams[AudioStream] == NULL) streams[AudioStream] = new CtZrtpStream(); stream = streams[AudioStream]; stream->zrtpEngine = new ZRtp((uint8_t*)ownZid, stream, clientIdString, config, mitmMode, signSas); stream->type = Master; stream->index = AudioStream; stream->session = this; stream->discriminatorMode = discriminatorMode; } if (video) { if (streams[VideoStream] == NULL) streams[VideoStream] = new CtZrtpStream(); stream = streams[VideoStream]; stream->zrtpEngine = new ZRtp((uint8_t*)ownZid, stream, clientIdString, config); stream->type = Slave; stream->index = VideoStream; stream->session = this; stream->discriminatorMode = discriminatorMode; } isReady = true; } if (configOwn != NULL) { delete configOwn; } synchLeave(); return ret; }
void CtZrtpSession::setLastPeerNameVerify(const char *name, int iIsMitm) { CtZrtpStream *stream = streams[AudioStream]; if (!isReady || !stream || stream->isStopped) return; uint8_t peerZid[IDENTIFIER_LEN]; std::string nm(name); stream->zrtpEngine->getPeerZid(peerZid); getZidCacheInstance()->putPeerName(peerZid, nm); setVerify(1); }
static int32_t zrtp_initZidFile(const char* zidFilename) { ZIDCache* zf = getZidCacheInstance(); if (!zf->isOpen()) { std::string fname; if (zidFilename == NULL) { char *home = getenv("HOME"); std::string baseDir = (home != NULL) ? (std::string(home) + std::string("/.")) : std::string("."); fname = baseDir + std::string("GNUccRTP.zid"); zidFilename = fname.c_str(); } return zf->open((char *)zidFilename); } return 0; }
int CtZrtpSession::initCache(const char *zidFilename) { ZIDCache* zf = getZidCacheInstance(); if (!zf->isOpen()) { std::string fname; if (zidFilename == NULL) { char *home = getenv("HOME"); std::string baseDir = (home != NULL) ? (std::string(home) + std::string("/.")) : std::string("."); fname = baseDir + std::string("GNUZRTP.zid"); zidFilename = fname.c_str(); } if (zf->open((char *)zidFilename) < 0) { return -1; } } return 1; }
void zrtp_initializeZrtpEngine(ZrtpContext* zrtpContext, zrtp_Callbacks *cb, const char* id, const char* zidFilename, void* userData, int32_t mitmMode) { std::string clientIdString(id); zrtpContext->zrtpCallback = new ZrtpCallbackWrapper(cb, zrtpContext); zrtpContext->userData = userData; if (zrtpContext->configure == 0) { zrtpContext->configure = new ZrtpConfigure(); zrtpContext->configure->setStandardConfig(); } // Initialize ZID file (cache) and get my own ZID zrtp_initZidFile(zidFilename); const unsigned char* myZid = getZidCacheInstance()->getZid(); zrtpContext->zrtpEngine = new ZRtp((uint8_t*)myZid, zrtpContext->zrtpCallback, clientIdString, zrtpContext->configure, mitmMode == 0 ? false : true); }
void CtZrtpSession::cleanCache() { getZidCacheInstance()->cleanup(); }