Commit a2919db7 authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Allow setting default validity period for new OpenPGP keys

Add a setting for specifying the default validity period of new OpenPGP
keys in days. Disallow changing the validity period if the setting is
marked as immutable.

GnuPG-bug-id: 5708
parent b7065471
......@@ -38,6 +38,12 @@
e.g., from the email settings of the desktop or, on Windows, from the Active Directory.</whatsthis>
<default>true</default>
</entry>
<entry key="ValidityPeriodInDays" type="Int">
<label>Default validity period</label>
<tooltip>Specifies the default validity period of new OpenPGP keys in days.</tooltip>
<whatsthis>This setting specifies how many days a new OpenPGP key is valid by default, or, in other words, after how many days the key will expire. Set this to 0 for unlimited validity. If this setting is not set or if it is set to a negative value, then new OpenPGP keys will be valid for two years by default.</whatsthis>
<default>-1</default>
</entry>
</group>
<group name="CMS">
<entry key="Enabled" name="cmsEnabled" type="Bool">
......
......@@ -397,10 +397,7 @@ public:
{
qRegisterMetaType<Subkey::PubkeyAlgo>("Subkey::PubkeyAlgo");
ui.setupUi(this);
const QDate today = QDate::currentDate();
ui.expiryDE->setMinimumDate(today);
ui.expiryDE->setDate(today.addYears(2));
ui.expiryCB->setChecked(true);
ui.expiryDE->setMinimumDate(QDate::currentDate());
ui.emailLW->setDefaultValue(i18n("new email"));
ui.dnsLW->setDefaultValue(i18n("new dns name"));
ui.uriLW->setDefaultValue(i18n("new uri"));
......@@ -414,7 +411,7 @@ public:
return;
}
protocol = proto;
loadDefaultKeyType();
loadDefaults();
}
void setAdditionalUserIDs(const QStringList &items)
......@@ -578,11 +575,8 @@ public:
void setExpiryDate(QDate date)
{
if (date.isValid()) {
ui.expiryDE->setDate(date);
} else {
ui.expiryCB->setChecked(false);
}
ui.expiryDE->setDate(date);
ui.expiryCB->setChecked(ui.expiryDE->isValid());
}
QDate expiryDate() const
{
......@@ -656,7 +650,9 @@ private Q_SLOTS:
private:
void fillKeySizeComboBoxen();
void loadDefaultKeyType();
void loadDefaultExpiration();
void loadDefaultGnuPGKeyType();
void loadDefaults();
void updateWidgetVisibility();
private:
......@@ -1833,6 +1829,30 @@ void AdvancedSettingsDialog::loadDefaultKeyType()
}
keyTypeImmutable = config.isEntryImmutable(entry);
}
void AdvancedSettingsDialog::loadDefaultExpiration()
{
if (protocol != OpenPGP) {
return;
}
const auto settings = Kleo::Settings{};
const auto defaultExpirationInDays = settings.validityPeriodInDays();
if (defaultExpirationInDays > 0) {
setExpiryDate(QDate::currentDate().addDays(defaultExpirationInDays));
} else if (defaultExpirationInDays == 0) {
setExpiryDate({}); // no expiration
} else {
setExpiryDate(QDate::currentDate().addYears(2));
}
}
void AdvancedSettingsDialog::loadDefaults()
{
loadDefaultKeyType();
loadDefaultExpiration();
updateWidgetVisibility();
}
......@@ -1911,8 +1931,15 @@ void AdvancedSettingsDialog::updateWidgetVisibility()
ui.rsaSubCB->setChecked(false);
ui.rsaKeyStrengthSubCB->setEnabled(false);
}
ui.expiryDE->setVisible(protocol == OpenPGP);
ui.expiryCB->setVisible(protocol == OpenPGP);
const auto settings = Kleo::Settings{};
if (settings.isValidityPeriodInDaysImmutable()) {
ui.expiryDE->setEnabled(false);
ui.expiryCB->setEnabled(false);
}
slotKeyMaterialSelectionChanged();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment