27 #include <KMessageBox>
30 #include <gpgme++/context.h>
31 #include <gpgme++/data.h>
32 #include <gpgme++/importresult.h>
33 #include <qgpgme/dataprovider.h>
57 if (fingerprint.isEmpty() || (!sig && !mirrorFailed)) {
61 if (!fingerprint.startsWith(QLatin1String(
"0x"))) {
62 fingerprint =
"0x" + fingerprint;
65 if (m_downloading.contains(fingerprint) && !mirrorFailed) {
66 if (!m_downloading.contains(fingerprint, sig)) {
67 m_downloading.insert(fingerprint, sig);
71 if (!servers.count()) {
73 i18n(
"No server for downloading keys is specified in settings. Downloading aborted."),
74 i18n(
"No key server"));
80 const QStringList failedMirrors = m_triedMirrors.values(fingerprint);
81 for (
int i = 0; i < servers.count(); ++i) {
82 if (!m_triedMirrors.contains(fingerprint, servers.at(i))) {
83 mirror = servers.at(i);
88 mirror = servers.first();
91 if (mirror.isEmpty()) {
93 i18n(
"No useful key server found, key not downloaded. Add more servers to the settings or restart KGet and retry downloading."),
94 i18n(
"No key server"));
98 m_triedMirrors.insert(fingerprint, mirror);
100 m_downloading.insert(fingerprint, sig);
104 url.addPath(
"pks/lookup");
105 url.setQuery(
"op=get&options=mr&search=" + fingerprint);
108 kDebug(5001) <<
"Dowloading:" << url;
110 KIO::StoredTransferJob *job = KIO::storedGet(url, KIO::Reload, KIO::HideProgressInfo);
111 m_jobs[job] = fingerprint;
112 connect(job, SIGNAL(finished(
KJob*)),
this, SLOT(slotDownloaded(
KJob*)));
116 void KeyDownloader::slotDownloaded(
KJob *job)
119 if (!m_jobs.contains(job)) {
123 const QString fingerprint = m_jobs[job];
124 KIO::StoredTransferJob *transferJob =
static_cast<KIO::StoredTransferJob*
>(job);
126 if (transferJob->isErrorPage()) {
127 kDebug(5001) <<
"Mirror did not work, try another one.";
133 QByteArray data = transferJob->data();
134 if (data.isEmpty()) {
135 kDebug(5001) <<
"Downloaded data is empty.";
140 const int indexStart = data.indexOf(
"<pre>");
141 const int indexEnd = data.indexOf(
"</pre>", indexStart);
142 if ((indexStart == -1) || (indexEnd == -1)) {
143 kDebug(5001) <<
"Could not find a key.";
148 data = data.mid(indexStart + 6, indexEnd - indexStart - 6);
150 GpgME::initializeLibrary();
151 GpgME::Error err = GpgME::checkEngine(GpgME::OpenPGP);
153 kDebug(5001) <<
"Problem checking the engine.";
157 QScopedPointer<GpgME::Context> context(GpgME::Context::createForProtocol(GpgME::OpenPGP));
158 if (!context.data()) {
159 kDebug(5001) <<
"Could not create context.";
163 QGpgME::QByteArrayDataProvider keyBA(data);
164 GpgME::Data key(&keyBA);
165 GpgME::ImportResult importResult = context->importKeys(key);
166 err = importResult.error();
168 kDebug(5001) <<
"Error while importing key.";;
172 kDebug(5001) <<
"Key downloaded, notifying requesters.";
174 QList<Signature*> sigs = m_downloading.values(fingerprint);
178 m_downloading.remove(fingerprint);
181 kWarning(5001) << "No QGPGME support.";
185 #include "keydownloader.moc"
KeyDownloader(QObject *parent=0)
void downloadKey(QString fingerprint, Signature *sig)
Searches for a key with fignerprint.
void signatureDownloaded()
Starts verification again if a verification was tried before but aborted because of missing keys...
static QStringList signatureKeyServers()
Get SignatureKeyServers.
Class to verify signatures.