[kde-doc-english] [kmymoney/frameworks] /: Show information about expiration of recover key
Cristian Oneț
onet.cristian at gmail.com
Sun Aug 31 16:22:13 UTC 2014
Git commit 45af11d53131c93d1e573155507cc299113dba70 by Cristian Oneț, on behalf of Thomas Baumgart.
Committed on 31/08/2014 at 15:55.
Pushed by conet into branch 'frameworks'.
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:
(cherry picked from commit 0c55298bde19d33aeabe2e24387e70b588bb2e9d)
Conflicts:
libkgpgfile/kgpgfile.cpp
M +37 -0 kmymoney/kmymoney.cpp
M +21 -0 libkgpgfile/kgpgfile.cpp
M +8 -0 libkgpgfile/kgpgfile.h
http://commits.kde.org/kmymoney/45af11d53131c93d1e573155507cc299113dba70
diff --git a/kmymoney/kmymoney.cpp b/kmymoney/kmymoney.cpp
index 5211543..4267c8a 100644
--- a/kmymoney/kmymoney.cpp
+++ b/kmymoney/kmymoney.cpp
@@ -173,6 +173,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 {
@@ -2478,6 +2485,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 36cb6b6..720f2d7 100644
--- a/libkgpgfile/kgpgfile.cpp
+++ b/libkgpgfile/kgpgfile.cpp
@@ -31,6 +31,7 @@
#include <QBuffer>
#include <QList>
#include <QSaveFile>
+#include <QDateTime>
// ----------------------------------------------------------------------------
// KDE Includes
@@ -314,6 +315,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