From 43e1eff2215314cb33890f7e3f85515623013094 Mon Sep 17 00:00:00 2001 From: SET Date: Wed, 18 Nov 2020 20:48:15 +0100 Subject: [PATCH] Add function to revoke a user identity. Done with Context::revUid, not with UserID::revoke. Does not remove the identity. N.B. : if the uid is revoked a second time, Error::code is 0. --- GpgMEWorker.cpp | 27 +++++++++++++++++++++++++++ GpgMEWorker.h | 13 +++++++++++++ 2 files changed, 40 insertions(+) diff --git a/GpgMEWorker.cpp b/GpgMEWorker.cpp index bb4bda1..afe35b3 100644 --- a/GpgMEWorker.cpp +++ b/GpgMEWorker.cpp @@ -201,6 +201,33 @@ const Error GpgMEWorker::AddUserID(const char* keyFpr, const string& passphrase, return e; } +const Error GpgMEWorker::RevokeUserID(const char* keyFpr, + const string& passphrase, + const string& name, const string& email, + const string& comment) +{ + 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; + + m_ctx->setPinentryMode(Context::PinentryMode::PinentryLoopback); + if (m_ppp == NULL) + m_ppp = new LoopbackPassphraseProvider(); + m_ppp->SetPassphrase(passphrase); + m_ctx->setPassphraseProvider(m_ppp); + + const string uid = MakeUidString(name, email, comment); + e = m_ctx->revUid(k, uid.c_str()); + k.update(); + m_ctx->clearSigningKeys(); + + return e; +} + /* * Using a temporary context for key creation. It is altered after secret key * creation, and subkey creation fails thereafter. This is observational. diff --git a/GpgMEWorker.h b/GpgMEWorker.h index f99a5c1..d2fb62d 100644 --- a/GpgMEWorker.h +++ b/GpgMEWorker.h @@ -100,6 +100,19 @@ public: const Error AddUserID(const char * keyFpr, const string& passphrase, const string& name, const string& email, const string& comment); + /** + * Revoke a user identity. Does not remove the identity. + * \n N.B. : if the uid is revoked a second time, Error::code is 0. + * @param keyFpr + * @param passphrase + * @param name + * @param email + * @param comment + * @return + */ + const Error RevokeUserID(const char * keyFpr, const string& passphrase, + const string& name, const string& email, + const string& comment); /** * Creates a pair of secret and public keys with the default engine * algorithms. Default expiry time is 2 * 365 days.