From 4f8ea18a667865bc541a715ac62e61de3e0627ed Mon Sep 17 00:00:00 2001 From: SET Date: Wed, 11 Nov 2020 21:09:43 +0100 Subject: [PATCH] Use fingerprint instead of keyid when importing and deleting keys. --- GpgMECWorker.cpp | 4 ++-- GpgMECWorker.h | 6 +++--- GpgMEWorker.cpp | 4 ++-- GpgMEWorker.h | 2 +- K7Main.cpp | 17 +++++++++-------- 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/GpgMECWorker.cpp b/GpgMECWorker.cpp index 7b86286..00761a8 100644 --- a/GpgMECWorker.cpp +++ b/GpgMECWorker.cpp @@ -17,9 +17,9 @@ GpgMECWorker::~GpgMECWorker() { gpgme_release(c_ctx); } -bool GpgMECWorker::DeleteKey(const char * fullKeyId, bool secret, GpgME::Error& e) { +bool GpgMECWorker::DeleteKey(const char * fpr, bool secret, GpgME::Error& e) { gpgme_key_t c_key; - gpgme_error_t c_err = gpgme_get_key(c_ctx, fullKeyId, &c_key, secret); + gpgme_error_t c_err = gpgme_get_key(c_ctx, fpr, &c_key, secret); if (c_key == NULL) { e = GpgME::Error::fromCode(c_err); return false; diff --git a/GpgMECWorker.h b/GpgMECWorker.h index b1f5436..a2d80f2 100644 --- a/GpgMECWorker.h +++ b/GpgMECWorker.h @@ -22,13 +22,13 @@ public: * Deleting keys must be done with the C API because * gpgmepp does not provide a way to use GPGME_DELETE_FORCE, * resulting in a confirmation dialog triggered by GPG. - * This does not fit use on a web werver. - * @param fullKeyId + * This does not fit use on a web server. + * @param fpr * @param secret delete secret key ? * @param e * @return */ - bool DeleteKey(const char * fullKeyId, bool secret, GpgME::Error& e); + bool DeleteKey(const char * fpr, bool secret, GpgME::Error& e); private: gpgme_ctx_t c_ctx; diff --git a/GpgMEWorker.cpp b/GpgMEWorker.cpp index 05d0b35..3f2efdf 100644 --- a/GpgMEWorker.cpp +++ b/GpgMEWorker.cpp @@ -80,7 +80,7 @@ const string GpgMEWorker::ImportKey(const char * filePath, Error& e) fclose(kFp); return ""; } - const string keyid = string(dKey.toKeys().at(0).keyID()); // Must be done before import + const string fpr = string(dKey.toKeys().at(0).primaryFingerprint()); // Must be done before import ImportResult rImportKey = m_ctx->importKeys(dKey); e = rImportKey.error(); if (e.code() != 0) @@ -90,7 +90,7 @@ const string GpgMEWorker::ImportKey(const char * filePath, Error& e) } fclose(kFp); - return keyid; + return fpr; } const Error GpgMEWorker::EditOwnerTrust(const char* anyFullId, GpgME::Key::OwnerTrust trustLevel) diff --git a/GpgMEWorker.h b/GpgMEWorker.h index 2e0285a..4fa594a 100644 --- a/GpgMEWorker.h +++ b/GpgMEWorker.h @@ -52,7 +52,7 @@ public: * Import a key from file. * @param filePath * @param e - * @return the keyid + * @return : the fingerprint */ const string ImportKey(const char * filePath, Error& e); /** diff --git a/K7Main.cpp b/K7Main.cpp index c758090..5f07385 100644 --- a/K7Main.cpp +++ b/K7Main.cpp @@ -425,25 +425,25 @@ void K7Main::DoImportKey() { const WString spool = m_btnImport->attributeValue("spool"); Error e; GpgMEWorker gpgw; - const WString keyid = gpgw.ImportKey(spool.toUTF8().c_str(), e); + const WString fpr = gpgw.ImportKey(spool.toUTF8().c_str(), e); m_btnImport->hide(); m_btnImport->setAttributeValue("spool", ""); if (e.code() != 0) { m_tmwMessage->SetText(e.asString()); return; } - if (keyid.empty()) { - m_tmwMessage->SetText(TR("ImportError") + keyid); + if (fpr.empty()) { + m_tmwMessage->SetText(TR("ImportError") + fpr); return; } // Show the imported key - GpgME::Key k = gpgw.FindKey(keyid.toUTF8().c_str(), e, false); // A public is present anyway + GpgME::Key k = gpgw.FindKey(fpr.toUTF8().c_str(), e, false); // A public is present anyway if (e.code() != 0) { m_tmwMessage->SetText(e.asString()); return; } - m_tmwMessage->SetText(TR("ImportSuccess") + keyid + WString(" - ") + WString(k.userID(0).name())); - m_leSearch->setText(keyid); + m_tmwMessage->SetText(TR("ImportSuccess") + fpr + WString(" - ") + WString(k.userID(0).name())); + m_leSearch->setText(fpr); Search(); } @@ -506,7 +506,8 @@ void K7Main::DoDeleteKey() { return; } // Delete the key using the C API - bool res = gpgcw.DeleteKey(fullKeyID.toUTF8().c_str(), secret, c_e); + const WString fpr(k.primaryFingerprint()); + bool res = gpgcw.DeleteKey(k.primaryFingerprint(), secret, c_e); if (c_e.code() != 0) { m_tmwMessage->SetText(c_e.asString()); } else { @@ -515,6 +516,6 @@ void K7Main::DoDeleteKey() { m_btnDelete->hide(); m_deleter->hide(); // Show that the key is no longer available - m_leSearch->setText(fullKeyID); + m_leSearch->setText(fpr); Search(); }