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;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Error GpgMEWorker::SetSubkeyExpiryTime(const char* keyFpr,
|
const Error GpgMEWorker::SetKeyExpiryTime(const char* keyFpr,
|
||||||
const char* subkeyFpr,
|
const char* subkeyFpr,
|
||||||
const string& passphrase,
|
const string& passphrase,
|
||||||
ulong expires)
|
ulong expires)
|
||||||
@@ -204,38 +204,12 @@ const Error GpgMEWorker::SetSubkeyExpiryTime(const char* keyFpr,
|
|||||||
m_ppp->SetPassphrase(passphrase);
|
m_ppp->SetPassphrase(passphrase);
|
||||||
m_ctx->setPassphraseProvider(m_ppp);
|
m_ctx->setPassphraseProvider(m_ppp);
|
||||||
|
|
||||||
|
// setExpire() allows to expire all subkeys at once. Not implemented here.
|
||||||
e = m_ctx->setExpire(k, expires, subkey);
|
e = m_ctx->setExpire(k, expires, subkey);
|
||||||
|
|
||||||
return e;
|
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 Error GpgMEWorker::AddUserID(const char* keyFpr, const string& passphrase,
|
||||||
const string& name, const string& email,
|
const string& name, const string& email,
|
||||||
const string& comment)
|
const string& comment)
|
||||||
|
|||||||
@@ -91,27 +91,19 @@ public:
|
|||||||
vector<GpgME::UserID>& userIDsToRevoke,
|
vector<GpgME::UserID>& userIDsToRevoke,
|
||||||
const string& passphrase);
|
const string& passphrase);
|
||||||
/**
|
/**
|
||||||
* Sets the expiry time of a single subkey. Requires GPGME >= 1.15.0.
|
* Sets the expiry time of a single (sub)key. Requires GPGME >= 1.15.0.
|
||||||
* \n If no subkey is found (wrong fpr), the expiry time of key is set
|
* \n If no subkey is found (wrong fpr) or not provided, the expiry time of
|
||||||
* instead.
|
* key is set instead.
|
||||||
* @param keyFpr
|
* @param keyFpr
|
||||||
* @param subkeyFpr
|
* @param subkeyFpr
|
||||||
* @param passphrase
|
* @param passphrase
|
||||||
* @param expires : seconds from now. Use 0 for no expiry.
|
* @param expires : seconds from now. Use 0 for no expiry.
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
const Error SetSubkeyExpiryTime(const char * keyFpr,
|
const Error SetKeyExpiryTime(const char * keyFpr,
|
||||||
const char * subkeyFpr,
|
const char * subkeyFpr,
|
||||||
const string& passphrase,
|
const string& passphrase,
|
||||||
ulong expires = 63072000);
|
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.
|
* Adds a user identity to a key.
|
||||||
* \n The email parameter must have a valid email address format here, else
|
* \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
|
class AddUserIDEditInteractor : public GpgAddUserIDEditInteractor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
23
KeyEdit.cpp
23
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 = new PopupExpiryTime(lblExpiry, m_owner->m_tmwMessage);
|
||||||
m_popupExpiryTime->Create(keyFpr);
|
m_popupExpiryTime->Create(keyFpr);
|
||||||
m_expiryEditedKeyFpr = 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->SetSubkeyFpr(subkeyFpr);
|
||||||
m_popupExpiryTime->show();
|
m_popupExpiryTime->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyEdit::SetExpiryTime()
|
void KeyEdit::SetKeyExpiryTime()
|
||||||
{
|
{
|
||||||
GpgMEWorker gpgWorker;
|
GpgMEWorker gpgWorker;
|
||||||
GpgME::Error e;
|
GpgME::Error e;
|
||||||
const WString keyFpr = m_popupExpiryTime->GetKeyFpr();
|
const WString keyFpr = m_popupExpiryTime->GetKeyFpr();
|
||||||
const WString subkeyFpr = m_popupExpiryTime->GetSubkeyFpr();
|
WString subkeyFpr = m_popupExpiryTime->GetSubkeyFpr();
|
||||||
if (keyFpr == subkeyFpr)
|
if (keyFpr == subkeyFpr)
|
||||||
{
|
subkeyFpr = WString::Empty;
|
||||||
e = gpgWorker.SetExpiryTime(keyFpr.toUTF8().c_str(),
|
e = gpgWorker.SetKeyExpiryTime(keyFpr.toUTF8().c_str(),
|
||||||
m_popupExpiryTime->GetPassphrase(),
|
subkeyFpr.toUTF8().c_str(),
|
||||||
m_popupExpiryTime->GetExpiryTime());
|
m_popupExpiryTime->GetPassphrase(),
|
||||||
}
|
m_popupExpiryTime->GetExpiry());
|
||||||
else
|
|
||||||
{
|
|
||||||
e = gpgWorker.SetSubkeyExpiryTime(keyFpr.toUTF8().c_str(),
|
|
||||||
subkeyFpr.toUTF8().c_str(),
|
|
||||||
m_popupExpiryTime->GetPassphrase(),
|
|
||||||
m_popupExpiryTime->GetExpiry());
|
|
||||||
}
|
|
||||||
if (e.code() != 0)
|
if (e.code() != 0)
|
||||||
{
|
{
|
||||||
m_owner->m_tmwMessage->SetText(TR("SetExpirationTimeFailure"));
|
m_owner->m_tmwMessage->SetText(TR("SetExpirationTimeFailure"));
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ private:
|
|||||||
*/
|
*/
|
||||||
void FillOwnerTrustCombo(WComboBox * cmb, bool keyHasSecret);
|
void FillOwnerTrustCombo(WComboBox * cmb, bool keyHasSecret);
|
||||||
void EditUidValidity();
|
void EditUidValidity();
|
||||||
void SetExpiryTime();
|
void SetKeyExpiryTime();
|
||||||
void AddOrRevokeUid();
|
void AddOrRevokeUid();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user