Allow changing subkey expiry time.

Needs GPGME 1.15.0.
Using the same UI for changing expiry time of the primary secret key.
This commit is contained in:
SET
2020-11-21 20:53:01 +01:00
parent bb174075df
commit e9a55a1f69
7 changed files with 100 additions and 12 deletions

View File

@@ -145,6 +145,42 @@ const Error GpgMEWorker::CertifyKey(const char* fprSigningKey,
return e;
}
const Error GpgMEWorker::SetSubkeyExpiryTime(const char* keyFpr,
const char* subkeyFpr,
const string& passphrase,
ulong expires)
{
Error e;
Key k = FindKey(keyFpr, e, true);
if (e.code() != 0)
return e;
e = m_ctx->addSigningKey(k); // +++
if (e.code() != 0)
return e;
vector<GpgME::Subkey> subkey;
for (uint i = 0; i < k.subkeys().size(); i++)
{
GpgME::Subkey sk = k.subkey(i);
if (string(sk.fingerprint()) == string(subkeyFpr))
{
subkey.push_back(sk);
break;
}
}
// There should always be at least one subkey (the key itself).
m_ctx->setPinentryMode(Context::PinentryMode::PinentryLoopback);
if (m_ppp == NULL)
m_ppp = new LoopbackPassphraseProvider();
m_ppp->SetPassphrase(passphrase);
m_ctx->setPassphraseProvider(m_ppp);
e = m_ctx->setExpire(k, expires, subkey);
return e;
}
const Error GpgMEWorker::SetExpiryTime(const char * keyFpr,
const string& passphrase,
const string& timeString)
@@ -168,7 +204,7 @@ const Error GpgMEWorker::SetExpiryTime(const char * keyFpr,
GpgME::Data d;
e = m_ctx->edit(k, std::unique_ptr<SetExpiryTimeEditInteractor> (interactor), d);
m_ctx->clearSigningKeys();
// NB : with a wrong passphrase, e.code() is 0 !
return e;
}