Use fingerprint instead of keyid when importing and deleting keys.

This commit is contained in:
SET
2020-11-11 21:09:43 +01:00
parent 9cce0febdb
commit 4f8ea18a66
5 changed files with 17 additions and 16 deletions

View File

@@ -17,9 +17,9 @@ GpgMECWorker::~GpgMECWorker() {
gpgme_release(c_ctx); 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_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) { if (c_key == NULL) {
e = GpgME::Error::fromCode(c_err); e = GpgME::Error::fromCode(c_err);
return false; return false;

View File

@@ -22,13 +22,13 @@ public:
* Deleting keys must be done with the C API because * Deleting keys must be done with the C API because
* gpgmepp does not provide a way to use GPGME_DELETE_FORCE, * gpgmepp does not provide a way to use GPGME_DELETE_FORCE,
* resulting in a confirmation dialog triggered by GPG. * resulting in a confirmation dialog triggered by GPG.
* This does not fit use on a web werver. * This does not fit use on a web server.
* @param fullKeyId * @param fpr
* @param secret delete secret key ? * @param secret delete secret key ?
* @param e * @param e
* @return * @return
*/ */
bool DeleteKey(const char * fullKeyId, bool secret, GpgME::Error& e); bool DeleteKey(const char * fpr, bool secret, GpgME::Error& e);
private: private:
gpgme_ctx_t c_ctx; gpgme_ctx_t c_ctx;

View File

@@ -80,7 +80,7 @@ const string GpgMEWorker::ImportKey(const char * filePath, Error& e)
fclose(kFp); fclose(kFp);
return ""; 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); ImportResult rImportKey = m_ctx->importKeys(dKey);
e = rImportKey.error(); e = rImportKey.error();
if (e.code() != 0) if (e.code() != 0)
@@ -90,7 +90,7 @@ const string GpgMEWorker::ImportKey(const char * filePath, Error& e)
} }
fclose(kFp); fclose(kFp);
return keyid; return fpr;
} }
const Error GpgMEWorker::EditOwnerTrust(const char* anyFullId, GpgME::Key::OwnerTrust trustLevel) const Error GpgMEWorker::EditOwnerTrust(const char* anyFullId, GpgME::Key::OwnerTrust trustLevel)

View File

@@ -52,7 +52,7 @@ public:
* Import a key from file. * Import a key from file.
* @param filePath * @param filePath
* @param e * @param e
* @return the keyid * @return : the fingerprint
*/ */
const string ImportKey(const char * filePath, Error& e); const string ImportKey(const char * filePath, Error& e);
/** /**

View File

@@ -425,25 +425,25 @@ void K7Main::DoImportKey() {
const WString spool = m_btnImport->attributeValue("spool"); const WString spool = m_btnImport->attributeValue("spool");
Error e; Error e;
GpgMEWorker gpgw; 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->hide();
m_btnImport->setAttributeValue("spool", ""); m_btnImport->setAttributeValue("spool", "");
if (e.code() != 0) { if (e.code() != 0) {
m_tmwMessage->SetText(e.asString()); m_tmwMessage->SetText(e.asString());
return; return;
} }
if (keyid.empty()) { if (fpr.empty()) {
m_tmwMessage->SetText(TR("ImportError") + keyid); m_tmwMessage->SetText(TR("ImportError") + fpr);
return; return;
} }
// Show the imported key // 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) { if (e.code() != 0) {
m_tmwMessage->SetText(e.asString()); m_tmwMessage->SetText(e.asString());
return; return;
} }
m_tmwMessage->SetText(TR("ImportSuccess") + keyid + WString(" - ") + WString(k.userID(0).name())); m_tmwMessage->SetText(TR("ImportSuccess") + fpr + WString(" - ") + WString(k.userID(0).name()));
m_leSearch->setText(keyid); m_leSearch->setText(fpr);
Search(); Search();
} }
@@ -506,7 +506,8 @@ void K7Main::DoDeleteKey() {
return; return;
} }
// Delete the key using the C API // 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) { if (c_e.code() != 0) {
m_tmwMessage->SetText(c_e.asString()); m_tmwMessage->SetText(c_e.asString());
} else { } else {
@@ -515,6 +516,6 @@ void K7Main::DoDeleteKey() {
m_btnDelete->hide(); m_btnDelete->hide();
m_deleter->hide(); m_deleter->hide();
// Show that the key is no longer available // Show that the key is no longer available
m_leSearch->setText(fullKeyID); m_leSearch->setText(fpr);
Search(); Search();
} }