/** * Read private keys and fingerprints into the userstate. */ void OtrConnection::loadConfig() { keysFile = plugin->homeDir() + "/otr.keys"; fingerprintFile = plugin->homeDir() + "/otr.fingerprints"; otrl_privkey_read(userstate, keysFile.toStdString().c_str()); otrl_privkey_read_fingerprints(userstate, fingerprintFile.toStdString().c_str(), NULL, NULL); }
void ReadPrivkeyFiles() { DEBUGOUT_T("READ privkey"); lib_cs_lock(); otrl_privkey_read(otr_user_state, _T2A(g_private_key_filename)); otrl_privkey_read_fingerprints(otr_user_state, _T2A(g_fingerprint_store_filename), set_context_contact, 0); otrl_instag_read(otr_user_state, _T2A(g_instag_filename)); }
void OtrFingerprintService::readFingerprints() const { if (!UserStateService) return; OtrlUserState userState = UserStateService->userState(); otrl_privkey_read_fingerprints(userState, PathService->fingerprintsStoreFilePath().toUtf8().data(), 0, 0); emit fingerprintsUpdated(); }
OtrInternal::OtrInternal(psiotr::OtrCallback* callback, psiotr::OtrPolicy& policy) : m_userstate(), m_uiOps(), m_callback(callback), m_otrPolicy(policy), is_generating(false) { QDir profileDir(callback->dataDir()); m_keysFile = profileDir.filePath(OTR_KEYS_FILE); m_instagsFile = profileDir.filePath(OTR_INSTAGS_FILE); m_fingerprintFile = profileDir.filePath(OTR_FINGERPRINTS_FILE); OTRL_INIT; m_userstate = otrl_userstate_create(); m_uiOps.policy = (*OtrInternal::cb_policy); m_uiOps.create_privkey = (*OtrInternal::cb_create_privkey); m_uiOps.is_logged_in = (*OtrInternal::cb_is_logged_in); m_uiOps.inject_message = (*OtrInternal::cb_inject_message); m_uiOps.update_context_list = (*OtrInternal::cb_update_context_list); m_uiOps.new_fingerprint = (*OtrInternal::cb_new_fingerprint); m_uiOps.write_fingerprints = (*OtrInternal::cb_write_fingerprints); m_uiOps.gone_secure = (*OtrInternal::cb_gone_secure); m_uiOps.gone_insecure = (*OtrInternal::cb_gone_insecure); m_uiOps.still_secure = (*OtrInternal::cb_still_secure); #if (OTRL_VERSION_MAJOR > 3 || (OTRL_VERSION_MAJOR == 3 && OTRL_VERSION_MINOR >= 2)) m_uiOps.max_message_size = NULL; m_uiOps.account_name = (*OtrInternal::cb_account_name); m_uiOps.account_name_free = (*OtrInternal::cb_account_name_free); #endif #if (OTRL_VERSION_MAJOR >= 4) m_uiOps.handle_msg_event = (*OtrInternal::cb_handle_msg_event); m_uiOps.handle_smp_event = (*OtrInternal::cb_handle_smp_event); m_uiOps.create_instag = (*OtrInternal::cb_create_instag); #else m_uiOps.log_message = (*OtrInternal::cb_log_message); m_uiOps.notify = (*OtrInternal::cb_notify); m_uiOps.display_otr_message = (*OtrInternal::cb_display_otr_message); m_uiOps.protocol_name = (*OtrInternal::cb_protocol_name); m_uiOps.protocol_name_free = (*OtrInternal::cb_protocol_name_free); #endif otrl_privkey_read(m_userstate, QFile::encodeName(m_keysFile).constData()); otrl_privkey_read_fingerprints(m_userstate, QFile::encodeName(m_fingerprintFile).constData(), NULL, NULL); #if (OTRL_VERSION_MAJOR >= 4) otrl_instag_read(m_userstate, QFile::encodeName(m_instagsFile).constData()); #endif }
OtrInternal::OtrInternal(qutim_sdk_0_2::PluginSystemInterface *plugin, qutimotr::OtrPolicy& policy, OtrlUserState userstate) : m_userstate(), m_uiOps(), m_plugin(plugin), m_keysFile(plugin->getProfilePath() + QDir::separator () + OTR_KEYS_FILE), m_fingerprintFile(plugin->getProfilePath() + QDir::separator () + OTR_FINGERPRINTS_FILE), m_otrPolicy(policy), m_mutex() { //m_userstate = otrl_userstate_create(); m_userstate = userstate; m_uiOps.policy = (OtrInternal::cb_policy); m_uiOps.create_privkey = (OtrInternal::cb_create_privkey); m_uiOps.is_logged_in = (OtrInternal::cb_is_logged_in); m_uiOps.inject_message = (OtrInternal::cb_inject_message); m_uiOps.notify = (OtrInternal::cb_notify); m_uiOps.display_otr_message = (OtrInternal::cb_display_otr_message); m_uiOps.update_context_list = (OtrInternal::cb_update_context_list); m_uiOps.protocol_name = (OtrInternal::cb_protocol_name); m_uiOps.protocol_name_free = (OtrInternal::cb_protocol_name_free); m_uiOps.new_fingerprint = (OtrInternal::cb_new_fingerprint); m_uiOps.write_fingerprints = (OtrInternal::cb_write_fingerprints); m_uiOps.gone_secure = (OtrInternal::cb_gone_secure); m_uiOps.gone_insecure = (OtrInternal::cb_gone_insecure); m_uiOps.still_secure = (OtrInternal::cb_still_secure); m_uiOps.log_message = (OtrInternal::cb_log_message); m_uiOps.max_message_size = (OtrInternal::cb_max_message_size); #if not (OTRL_VERSION_MAJOR==3 && OTRL_VERSION_MINOR==0) m_uiOps.account_name = NULL; m_uiOps.account_name_free = NULL; #endif otrl_privkey_read(m_userstate, m_keysFile.toLocal8Bit().data()); otrl_privkey_read_fingerprints(m_userstate, m_fingerprintFile.toLocal8Bit().data(), NULL, NULL); }
// static void OTR_Wrapper::init() { otrwui_trace("OTR_Wrapper::init()"); if (! gOTR) { gOTR = new OTR_Wrapper; if (!gOTR) { llwarns << "$PLOTR$ Can't new otr_wrapper." << llendl; } else { llinfos << "$PLOTR$ newed otr_wrapper." << llendl; gOTR->uistate.policy = &otrwui_policy; gOTR->uistate.create_privkey = &otrwui_create_privkey; gOTR->uistate.is_logged_in = &otrwui_is_logged_in; gOTR->uistate.inject_message = &otrwui_inject_message; gOTR->uistate.notify = &otrwui_notify; gOTR->uistate.display_otr_message = &otrwui_display_otr_message; gOTR->uistate.update_context_list = &otrwui_update_context_list; gOTR->uistate.protocol_name = &otrwui_protocol_name; gOTR->uistate.protocol_name_free = &otrwui_protocol_name_free; gOTR->uistate.new_fingerprint = &otrwui_new_fingerprint; gOTR->uistate.write_fingerprints = &otrwui_write_fingerprints; gOTR->uistate.gone_secure = &otrwui_gone_secure; gOTR->uistate.gone_insecure = &otrwui_gone_insecure; gOTR->uistate.still_secure = &otrwui_still_secure; gOTR->uistate.log_message = &otrwui_log_message; gOTR->uistate.max_message_size = &otrwui_max_message_size; gOTR->uistate.account_name = &otrwui_account_name; gOTR->uistate.account_name_free = &otrwui_account_name_free; OTRL_INIT; gOTR->userstate = otrl_userstate_create(); std::string privpath = gDirUtilp->getExpandedFilename( LL_PATH_PER_SL_ACCOUNT, OTR_PRIVATE_KEYS_FILE); otrl_privkey_read(gOTR->userstate, privpath.c_str()); std::string pubpath = gDirUtilp->getExpandedFilename( LL_PATH_PER_SL_ACCOUNT, OTR_PUBLIC_KEYS_FILE); otrl_privkey_read_fingerprints(gOTR->userstate, pubpath.c_str(), NULL, NULL); #if 0 // this will gen a key, if the user doesn't have one, at init() time if (gOTR && gOTR->userstate) { OtrlPrivKey *r = gOTR->userstate->privkey_root; OtrlPrivKey *k = gOTR->userstate->privkey_root; while (k && (k != r)) { if (0 == strcmp(gOTR->get_protocolid(), k->protocol)) { return; } } char my_uuid[UUID_STR_SIZE]; gAgent.getID().toString(&(my_uuid[0])); otrl_privkey_generate(gOTR->userstate, privpath.c_str(), my_uuid, gOTR->get_protocolid()); } #endif } } }
void otr_keygen(ProfAccount *account) { if (data_loaded) { cons_show("OTR key already generated."); return; } if (jid) { free(jid); } jid = strdup(account->jid); log_info("Generating OTR key for %s", jid); gchar *data_home = xdg_get_data_home(); GString *basedir = g_string_new(data_home); free(data_home); gchar *account_dir = str_replace(jid, "@", "_at_"); g_string_append(basedir, "/profanity/otr/"); g_string_append(basedir, account_dir); g_string_append(basedir, "/"); free(account_dir); if (!mkdir_recursive(basedir->str)) { log_error("Could not create %s for account %s.", basedir->str, jid); cons_show_error("Could not create %s for account %s.", basedir->str, jid); g_string_free(basedir, TRUE); return; } gcry_error_t err = 0; GString *keysfilename = g_string_new(basedir->str); g_string_append(keysfilename, "keys.txt"); log_debug("Generating private key file %s for %s", keysfilename->str, jid); cons_show("Generating private key, this may take some time."); cons_show("Moving the mouse randomly around the screen may speed up the process!"); ui_update(); err = otrl_privkey_generate(user_state, keysfilename->str, account->jid, "xmpp"); if (!err == GPG_ERR_NO_ERROR) { g_string_free(basedir, TRUE); g_string_free(keysfilename, TRUE); log_error("Failed to generate private key"); cons_show_error("Failed to generate private key"); return; } log_info("Private key generated"); cons_show(""); cons_show("Private key generation complete."); GString *fpsfilename = g_string_new(basedir->str); g_string_append(fpsfilename, "fingerprints.txt"); log_debug("Generating fingerprints file %s for %s", fpsfilename->str, jid); err = otrl_privkey_write_fingerprints(user_state, fpsfilename->str); if (!err == GPG_ERR_NO_ERROR) { g_string_free(basedir, TRUE); g_string_free(keysfilename, TRUE); log_error("Failed to create fingerprints file"); cons_show_error("Failed to create fingerprints file"); return; } log_info("Fingerprints file created"); err = otrl_privkey_read(user_state, keysfilename->str); if (!err == GPG_ERR_NO_ERROR) { g_string_free(basedir, TRUE); g_string_free(keysfilename, TRUE); log_error("Failed to load private key"); data_loaded = FALSE; return; } err = otrl_privkey_read_fingerprints(user_state, fpsfilename->str, NULL, NULL); if (!err == GPG_ERR_NO_ERROR) { g_string_free(basedir, TRUE); g_string_free(keysfilename, TRUE); log_error("Failed to load fingerprints"); data_loaded = FALSE; return; } data_loaded = TRUE; g_string_free(basedir, TRUE); g_string_free(keysfilename, TRUE); g_string_free(fpsfilename, TRUE); return; }
void otr_on_connect(ProfAccount *account) { if (jid) { free(jid); } jid = strdup(account->jid); log_info("Loading OTR key for %s", jid); gchar *data_home = xdg_get_data_home(); GString *basedir = g_string_new(data_home); free(data_home); gchar *account_dir = str_replace(jid, "@", "_at_"); g_string_append(basedir, "/profanity/otr/"); g_string_append(basedir, account_dir); g_string_append(basedir, "/"); free(account_dir); if (!mkdir_recursive(basedir->str)) { log_error("Could not create %s for account %s.", basedir->str, jid); cons_show_error("Could not create %s for account %s.", basedir->str, jid); g_string_free(basedir, TRUE); return; } user_state = otrl_userstate_create(); gcry_error_t err = 0; GString *keysfilename = g_string_new(basedir->str); g_string_append(keysfilename, "keys.txt"); if (!g_file_test(keysfilename->str, G_FILE_TEST_IS_REGULAR)) { log_info("No OTR private key file found %s", keysfilename->str); data_loaded = FALSE; } else { log_info("Loading OTR private key %s", keysfilename->str); err = otrl_privkey_read(user_state, keysfilename->str); if (!err == GPG_ERR_NO_ERROR) { log_warning("Failed to read OTR private key file: %s", keysfilename->str); cons_show_error("Failed to read OTR private key file: %s", keysfilename->str); g_string_free(basedir, TRUE); g_string_free(keysfilename, TRUE); return; } OtrlPrivKey* privkey = otrl_privkey_find(user_state, jid, "xmpp"); if (!privkey) { log_warning("No OTR private key found for account \"%s\", protocol \"xmpp\" in file: %s", jid, keysfilename->str); cons_show_error("No OTR private key found for account \"%s\", protocol \"xmpp\" in file: %s", jid, keysfilename->str); g_string_free(basedir, TRUE); g_string_free(keysfilename, TRUE); return; } log_info("Loaded OTR private key"); data_loaded = TRUE; } GString *fpsfilename = g_string_new(basedir->str); g_string_append(fpsfilename, "fingerprints.txt"); if (!g_file_test(fpsfilename->str, G_FILE_TEST_IS_REGULAR)) { log_info("No OTR fingerprints file found %s", fpsfilename->str); data_loaded = FALSE; } else { log_info("Loading OTR fingerprints %s", fpsfilename->str); err = otrl_privkey_read_fingerprints(user_state, fpsfilename->str, NULL, NULL); if (!err == GPG_ERR_NO_ERROR) { log_error("Failed to load OTR fingerprints file: %s", fpsfilename->str); g_string_free(basedir, TRUE); g_string_free(keysfilename, TRUE); g_string_free(fpsfilename, TRUE); return; } else { log_info("Loaded OTR fingerprints"); data_loaded = TRUE; } } if (data_loaded) { cons_show("Loaded OTR private key for %s", jid); } g_string_free(basedir, TRUE); g_string_free(keysfilename, TRUE); g_string_free(fpsfilename, TRUE); return; }
/** * Read fingerprints from the file into the userstate. */ void OtrConnection::readFingerprints(char* file) { otrl_privkey_read_fingerprints(userstate, file, NULL, NULL); }
static void read_fingerprint(char *file) { if (otrl_privkey_read_fingerprints(us, file, NULL, NULL)) { fprintf(stderr, "Error reading fingerprints"); } }