Prefer key fingerprints anywhere.

During delete process, keys were identified by Key::keyID().
It seems that collisions are possible; so use fingerprints instead.
This commit is contained in:
SET
2020-11-15 20:55:05 +01:00
parent 64b480912f
commit 0e9cc34ac0

View File

@@ -117,7 +117,7 @@ bool KeyringIO::CanKeyBeDeleted(const WString& fullKeyID)
{// Is a public key {// Is a public key
k = gpgw.FindKey(fullKeyID.toUTF8().c_str(), e, false); k = gpgw.FindKey(fullKeyID.toUTF8().c_str(), e, false);
// Prepare actual delete // Prepare actual delete
m_btnDelete->setAttributeValue("keyid", k.keyID()); m_btnDelete->setAttributeValue("fpr", k.primaryFingerprint());
m_btnDelete->setAttributeValue("hasSecret", "0"); m_btnDelete->setAttributeValue("hasSecret", "0");
return true; return true;
} }
@@ -131,7 +131,7 @@ bool KeyringIO::CanKeyBeDeleted(const WString& fullKeyID)
{ {
if (Tools::ConfigKeyIdMatchesKey(k, *it)) if (Tools::ConfigKeyIdMatchesKey(k, *it))
{ {
m_btnDelete->setAttributeValue("keyid", k.keyID()); m_btnDelete->setAttributeValue("fpr", k.primaryFingerprint());
m_btnDelete->setAttributeValue("hasSecret", "1"); m_btnDelete->setAttributeValue("hasSecret", "1");
return true; return true;
} }
@@ -157,13 +157,13 @@ void KeyringIO::DoDeleteKey()
Error c_e, e; Error c_e, e;
GpgMECWorker gpgcw; GpgMECWorker gpgcw;
GpgMEWorker gpgw; GpgMEWorker gpgw;
const WString fullKeyID = m_btnDelete->attributeValue("keyid"); const WString fprToDelete = m_btnDelete->attributeValue("fpr");
const WString hasSecret = m_btnDelete->attributeValue("hasSecret"); const WString hasSecret = m_btnDelete->attributeValue("hasSecret");
bool secret = true; bool secret = true;
if (hasSecret == WString("0")) if (hasSecret == WString("0"))
secret = false; secret = false;
// Get the key before deletion, to show its ID on success // Get the key before deletion, to show its ID on success
GpgME::Key k = gpgw.FindKey(fullKeyID.toUTF8().c_str(), e, secret); GpgME::Key k = gpgw.FindKey(fprToDelete.toUTF8().c_str(), e, secret);
if (e.code() != 0) if (e.code() != 0)
{ {
m_tmwMessage->SetText(e.asString()); m_tmwMessage->SetText(e.asString());