[kde-doc-english] [kmymoney] /: Show information about expiration of recover key
Thomas Baumgart
thb at net-bembel.de
Sun Aug 31 15:59:18 UTC 2014
Git commit 0c55298bde19d33aeabe2e24387e70b588bb2e9d by Thomas Baumgart.
Committed on 31/08/2014 at 15:55.
Pushed by tbaumgart into branch 'master'.
Show information about expiration of recover key
30 days prior to the expiration of the KMyMoney recover key
an information dialog will popup during application start or
after settings have been changed if the recover key is in use.
GUI:
M +37 -0 kmymoney/kmymoney.cpp
M +21 -0 libkgpgfile/kgpgfile.cpp
M +8 -0 libkgpgfile/kgpgfile.h
http://commits.kde.org/kmymoney/0c55298bde19d33aeabe2e24387e70b588bb2e9d
diff --git a/kmymoney/kmymoney.cpp b/kmymoney/kmymoney.cpp
index 3dc2599..9b60171 100644
--- a/kmymoney/kmymoney.cpp
+++ b/kmymoney/kmymoney.cpp
@@ -170,6 +170,13 @@
#define RECOVER_KEY_ID "59B0F826D2B08440"
+
+// define the default period to warn about an expiring recoverkey to 30 days
+// but allows to override this setting during build time
+#ifndef RECOVER_KEY_EXPIRATION_WARNING
+#define RECOVER_KEY_EXPIRATION_WARNING 30
+#endif
+
#define ID_STATUS_MSG 1
enum backupStateE {
@@ -2455,6 +2462,36 @@ void KMyMoneyApp::slotUpdateConfiguration(void)
}
d->setCustomColors();
+
+ // check if the recovery key is still valid or expires soon
+
+ if (KMyMoneySettings::writeDataEncrypted() && KMyMoneySettings::encryptRecover()) {
+ if (KGPGFile::GPGAvailable()) {
+ KGPGFile file;
+ QDateTime expirationDate = file.keyExpires(QLatin1String(RECOVER_KEY_ID));
+ if (expirationDate.isValid() && QDateTime::currentDateTime().daysTo(expirationDate) <= RECOVER_KEY_EXPIRATION_WARNING) {
+ bool skipMessage = false;
+
+ //get global config object for our app.
+ KSharedConfigPtr kconfig = KGlobal::config();
+ KConfigGroup grp;
+ QDate lastWarned;
+ if (kconfig) {
+ grp = d->m_config->group("General Options");
+ lastWarned = grp.readEntry("LastRecoverKeyExpirationWarning", QDate());
+ if (QDate::currentDate() == lastWarned) {
+ skipMessage = true;
+ }
+ }
+ if (!skipMessage) {
+ if (kconfig) {
+ grp.writeEntry("LastRecoverKeyExpirationWarning", QDate::currentDate());
+ }
+ KMessageBox::information(this, i18n("You have configured KMyMoney to use GPG to protect your data and to encrypt your data also with the KMyMoney recover key. This key is about to expire in %1 days. Please update the key from a keyserver using your GPG frontend (e.g. KGPG).").arg(QDateTime::currentDateTime().daysTo(expirationDate)), i18n("Recover key expires soon"));
+ }
+ }
+ }
+ }
}
/** No descriptions */
diff --git a/libkgpgfile/kgpgfile.cpp b/libkgpgfile/kgpgfile.cpp
index 1289dc9..5371c8e 100644
--- a/libkgpgfile/kgpgfile.cpp
+++ b/libkgpgfile/kgpgfile.cpp
@@ -32,6 +32,7 @@
#include <QByteArray>
#include <QBuffer>
#include <QList>
+#include <QDateTime>
// ----------------------------------------------------------------------------
// KDE Includes
@@ -317,6 +318,26 @@ void KGPGFile::secretKeyList(QStringList& list)
file.keyList(list, true);
}
+QDateTime KGPGFile::keyExpires(const QString& name)
+{
+ QDateTime expirationDate;
+
+ // skip a possible leading 0x in the id
+ QString cmp = name;
+ if (cmp.startsWith(QLatin1String("0x")))
+ cmp = cmp.mid(2);
+
+ QStringList keylist;
+ keyList(keylist, false, cmp);
+
+ // in case we have no or more than one matching key
+ // or the key does not have subkeys, we return an invalid date
+ if (d->m_keys.size() == 1 && d->m_keys[0].subkeys().size() > 0 && !d->m_keys[0].subkeys()[0].neverExpires()) {
+ expirationDate.setTime_t(d->m_keys[0].subkeys()[0].expirationTime());
+ }
+ return expirationDate;
+}
+
void KGPGFile::keyList(QStringList& list, bool secretKeys, const QString& pattern)
{
d->m_keys.clear();
diff --git a/libkgpgfile/kgpgfile.h b/libkgpgfile/kgpgfile.h
index 8d172fb..d5fa08e 100644
--- a/libkgpgfile/kgpgfile.h
+++ b/libkgpgfile/kgpgfile.h
@@ -29,6 +29,7 @@
#include <vector>
+class QDateTime;
// ----------------------------------------------------------------------------
// KDE Includes
@@ -109,6 +110,13 @@ public:
QString errorToString() const;
/**
+ * This method returns the information about the expiration date of a key.
+ * An invalid QDateTime object is returned if @a name matches more than one
+ * key or the key does not have an expiration date.
+ */
+ QDateTime keyExpires(const QString& name);
+
+ /**
* Checks whether GPG is available or not
*
* @retval true GPG can be started and returns a version number
More information about the kde-doc-english
mailing list