void GnuPG::sendPublicKey() { QAction *action = qobject_cast<QAction*>(sender()); QString fingerprint = "0x" + action->data().toString(); GpgProcess gpg; QStringList arguments; arguments << "--armor" << "--export" << fingerprint; gpg.start(arguments); gpg.waitForFinished(); // do nothing if error is occurred if (gpg.exitCode()) { return; } QString key = QString::fromUtf8(gpg.readAllStandardOutput()); QString jid = _activeTab->getYourJid(); QString jidToSend = _activeTab->getJid(); int account = 0; QString tmpJid; while (jid != (tmpJid = _accountInfo->getJid(account))) { ++account; if (tmpJid == "-1") { return; } } _stanzaSending->sendMessage(account, jidToSend, key, "", "chat"); _accountHost->appendSysMsg(account, jidToSend, _stanzaSending->escape(QString(tr("Public key %1 sent")).arg(action->text()))); }
bool GnuPG::incomingStanza(int account, const QDomElement& stanza) { if (!_enabled) { return false; } if (!_optionHost->getPluginOption("auto-import", true).toBool()) { return false; } if (stanza.tagName() != "message" && stanza.attribute("type") != "chat") { return false; } QString body = stanza.firstChildElement("body").text(); int start = body.indexOf("-----BEGIN PGP PUBLIC KEY BLOCK-----"); if (start == -1) { return false; } int end = body.indexOf("-----END PGP PUBLIC KEY BLOCK-----", start); if (end == -1) { return false; } QString key = body.mid(start, end - start); GpgProcess gpg; QStringList arguments; arguments << "--batch" << "--import"; gpg.start(arguments); gpg.waitForStarted(); gpg.write(key.toUtf8()); gpg.closeWriteChannel(); gpg.waitForFinished(); QString from = stanza.attribute("from"); // Cut trash from gpg command output QString res = QString::fromUtf8(gpg.readAllStandardError()); res = _stanzaSending->escape(res.mid(0, res.indexOf('\n'))); _accountHost->appendSysMsg(account, from, res); // Don't hide message if an error occurred if (gpg.exitCode()) { return false; } if (!_optionHost->getPluginOption("hide-key-message", true).toBool()) { return false; } else { return true; } }