Use new Context::setExpire to set expiration dates.
If no subkey is found (wrong fpr) or not provided, the expiry time of the key is set instead. setExpire() allows to expire all subkeys at once. Not implemented here. Requires GPGME >= 1.15.0.
This commit is contained in:
@@ -173,7 +173,7 @@ const Error GpgMEWorker::RevokeKeyCertifications(const char* fprSigningKey,
|
||||
return e;
|
||||
}
|
||||
|
||||
const Error GpgMEWorker::SetSubkeyExpiryTime(const char* keyFpr,
|
||||
const Error GpgMEWorker::SetKeyExpiryTime(const char* keyFpr,
|
||||
const char* subkeyFpr,
|
||||
const string& passphrase,
|
||||
ulong expires)
|
||||
@@ -204,38 +204,12 @@ const Error GpgMEWorker::SetSubkeyExpiryTime(const char* keyFpr,
|
||||
m_ppp->SetPassphrase(passphrase);
|
||||
m_ctx->setPassphraseProvider(m_ppp);
|
||||
|
||||
// setExpire() allows to expire all subkeys at once. Not implemented here.
|
||||
e = m_ctx->setExpire(k, expires, subkey);
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
const Error GpgMEWorker::SetExpiryTime(const char * keyFpr,
|
||||
const string& passphrase,
|
||||
const string& timeString)
|
||||
{
|
||||
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);
|
||||
|
||||
SetExpiryTimeEditInteractor * interactor
|
||||
= new SetExpiryTimeEditInteractor(timeString);
|
||||
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;
|
||||
}
|
||||
|
||||
const Error GpgMEWorker::AddUserID(const char* keyFpr, const string& passphrase,
|
||||
const string& name, const string& email,
|
||||
const string& comment)
|
||||
|
||||
@@ -91,27 +91,19 @@ public:
|
||||
vector<GpgME::UserID>& userIDsToRevoke,
|
||||
const string& passphrase);
|
||||
/**
|
||||
* Sets the expiry time of a single subkey. Requires GPGME >= 1.15.0.
|
||||
* \n If no subkey is found (wrong fpr), the expiry time of key is set
|
||||
* instead.
|
||||
* Sets the expiry time of a single (sub)key. Requires GPGME >= 1.15.0.
|
||||
* \n If no subkey is found (wrong fpr) or not provided, the expiry time of
|
||||
* key is set instead.
|
||||
* @param keyFpr
|
||||
* @param subkeyFpr
|
||||
* @param passphrase
|
||||
* @param expires : seconds from now. Use 0 for no expiry.
|
||||
* @return
|
||||
*/
|
||||
const Error SetSubkeyExpiryTime(const char * keyFpr,
|
||||
const Error SetKeyExpiryTime(const char * keyFpr,
|
||||
const char * subkeyFpr,
|
||||
const string& passphrase,
|
||||
ulong expires = 63072000);
|
||||
/**
|
||||
* Set new expiry time of a secret key.
|
||||
* @param timeString
|
||||
* @return
|
||||
*/
|
||||
const Error SetExpiryTime(const char * keyFpr,
|
||||
const string& passphrase,
|
||||
const string& timeString = "0");
|
||||
/**
|
||||
* Adds a user identity to a key.
|
||||
* \n The email parameter must have a valid email address format here, else
|
||||
@@ -259,20 +251,6 @@ public:
|
||||
|
||||
};
|
||||
|
||||
class SetExpiryTimeEditInteractor : public GpgSetExpiryTimeEditInteractor
|
||||
{
|
||||
public:
|
||||
|
||||
SetExpiryTimeEditInteractor(const std::string& timeString = "0")
|
||||
: GpgSetExpiryTimeEditInteractor(timeString)
|
||||
{
|
||||
};
|
||||
|
||||
virtual ~SetExpiryTimeEditInteractor()
|
||||
{
|
||||
};
|
||||
};
|
||||
|
||||
class AddUserIDEditInteractor : public GpgAddUserIDEditInteractor
|
||||
{
|
||||
public:
|
||||
|
||||
17
KeyEdit.cpp
17
KeyEdit.cpp
@@ -204,31 +204,24 @@ void KeyEdit::OnExpiryClicked(WTreeTableNode* subkeyNode, const WString& keyFpr,
|
||||
m_popupExpiryTime = new PopupExpiryTime(lblExpiry, m_owner->m_tmwMessage);
|
||||
m_popupExpiryTime->Create(keyFpr);
|
||||
m_expiryEditedKeyFpr = keyFpr;
|
||||
m_popupExpiryTime->GetApplyButton()->clicked().connect(this, &KeyEdit::SetExpiryTime);
|
||||
m_popupExpiryTime->GetApplyButton()->clicked().connect(this, &KeyEdit::SetKeyExpiryTime);
|
||||
}
|
||||
m_popupExpiryTime->SetSubkeyFpr(subkeyFpr);
|
||||
m_popupExpiryTime->show();
|
||||
}
|
||||
|
||||
void KeyEdit::SetExpiryTime()
|
||||
void KeyEdit::SetKeyExpiryTime()
|
||||
{
|
||||
GpgMEWorker gpgWorker;
|
||||
GpgME::Error e;
|
||||
const WString keyFpr = m_popupExpiryTime->GetKeyFpr();
|
||||
const WString subkeyFpr = m_popupExpiryTime->GetSubkeyFpr();
|
||||
WString subkeyFpr = m_popupExpiryTime->GetSubkeyFpr();
|
||||
if (keyFpr == subkeyFpr)
|
||||
{
|
||||
e = gpgWorker.SetExpiryTime(keyFpr.toUTF8().c_str(),
|
||||
m_popupExpiryTime->GetPassphrase(),
|
||||
m_popupExpiryTime->GetExpiryTime());
|
||||
}
|
||||
else
|
||||
{
|
||||
e = gpgWorker.SetSubkeyExpiryTime(keyFpr.toUTF8().c_str(),
|
||||
subkeyFpr = WString::Empty;
|
||||
e = gpgWorker.SetKeyExpiryTime(keyFpr.toUTF8().c_str(),
|
||||
subkeyFpr.toUTF8().c_str(),
|
||||
m_popupExpiryTime->GetPassphrase(),
|
||||
m_popupExpiryTime->GetExpiry());
|
||||
}
|
||||
if (e.code() != 0)
|
||||
{
|
||||
m_owner->m_tmwMessage->SetText(TR("SetExpirationTimeFailure"));
|
||||
|
||||
Reference in New Issue
Block a user