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

Use the compatibility helper for getting config entries

This makes the code robust against logical regrouping of config entries,
e.g. dirmngr's max-replies config entry.

GnuPG-bug-id: 5217
parent 27011862
......@@ -15,7 +15,7 @@ option(DISABLE_KWATCHGNUPG "Don't build the kwatchgnupg tool [default=OFF]" OFF)
# Standalone build. Find / include everything necessary.
set(KF5_MIN_VERSION "5.79.0")
set(KMIME_VERSION "5.16.40")
set(LIBKLEO_VERSION "5.16.52")
set(LIBKLEO_VERSION "5.16.53")
set(QT_REQUIRED_VERSION "5.14.0")
set(GPGME_REQUIRED_VERSION "1.13.1")
......
......@@ -15,6 +15,7 @@
#include "detailscommand.h"
#include <Libkleo/Compat>
#include <Libkleo/GnuPG>
#include <dialogs/lookupcertificatesdialog.h>
......@@ -376,9 +377,9 @@ static bool haveX509DirectoryServerConfigured()
if (!config) {
return false;
}
const QGpgME::CryptoConfigEntry *entry = config->entry(QStringLiteral("dirmngr"), QStringLiteral("LDAP"), QStringLiteral("LDAP Server"));
const QGpgME::CryptoConfigEntry *entry = getCryptoConfigEntry(config, "dirmngr", "LDAP Server");
bool entriesExist = entry && !entry->urlValueList().empty();
entry = config->entry(QStringLiteral("gpgsm"), QStringLiteral("Configuration"), QStringLiteral("keyserver"));
entry = getCryptoConfigEntry(config, "gpgsm", "keyserver");
entriesExist |= entry && !entry->urlValueList().empty();
return entriesExist;
}
......
......@@ -10,6 +10,10 @@
#include <config-kleopatra.h>
#include "dirservconfigpage.h"
#include "compat.h"
#include <Libkleo/Compat>
#include <Libkleo/DirectoryServicesWidget>
#include <Libkleo/CryptoConfigModule>
......@@ -105,39 +109,27 @@ private:
#endif
static const char s_x509services_componentName[] = "dirmngr";
static const char s_x509services_groupName[] = "LDAP";
static const char s_x509services_entryName[] = "LDAP Server";
static const char s_x509services_componentName[] = "gpgsm";
static const char s_x509services_entryName[] = "keyserver";
static const char s_x509services_new_componentName[] = "gpgsm";
static const char s_x509services_new_groupName[] = "Configuration";
static const char s_x509services_new_entryName[] = "keyserver";
static const char s_x509services_legacy_componentName[] = "dirmngr";
static const char s_x509services_legacy_entryName[] = "LDAP Server";
static const char s_pgpservice_componentName[] = "dirmngr";
static const char s_pgpservice_groupName[] = "Keyserver";
static const char s_pgpservice_entryName[] = "keyserver";
// legacy config entry used until GnuPG 2.2
static const char s_pgpservice_legacy_componentName[] = "gpg";
static const char s_pgpservice_legacy_groupName[] = "Keyserver";
static const char s_pgpservice_legacy_entryName[] = "keyserver";
static const char s_timeout_componentName[] = "dirmngr";
static const char s_timeout_groupName[] = "LDAP";
static const char s_timeout_entryName[] = "ldaptimeout";
static const char s_maxitems_componentName[] = "dirmngr";
static const char s_maxitems_groupName[] = "Configuration";
static const char s_maxitems_entryName[] = "max-replies";
// legacy config entry used until GnuPG 2.2
static const char s_maxitems_legacy_componentName[] = "dirmngr";
static const char s_maxitems_legacy_groupName[] = "LDAP";
static const char s_maxitems_legacy_entryName[] = "max-replies";
#ifdef NOT_USEFUL_CURRENTLY
static const char s_addnewservers_componentName[] = "dirmngr";
static const char s_addnewservers_groupName[] = "LDAP";
static const char s_addnewservers_entryName[] = "add-servers";
#endif
......@@ -201,24 +193,22 @@ static QList<QUrl> string2urls(const QString &str)
void DirectoryServicesConfigurationPage::load()
{
mWidget->clear();
// gpgsm/Configuration/keyserver is not provided by older gpgconf versions;
if ((mX509ServicesEntry = configEntry(s_x509services_new_componentName, s_x509services_new_groupName, s_x509services_new_entryName,
// gpgsm's keyserver option is not provided by very old gpgconf versions
if ((mX509ServicesEntry = configEntry(s_x509services_componentName, s_x509services_entryName,
CryptoConfigEntry::ArgType_LDAPURL, ListValue, DoNotShowError))) {
mWidget->addX509Services(mX509ServicesEntry->urlValueList());
} else if ((mX509ServicesEntry = configEntry(s_x509services_componentName, s_x509services_groupName, s_x509services_entryName,
CryptoConfigEntry::ArgType_LDAPURL, ListValue, DoShowError))) {
} else if ((mX509ServicesEntry = configEntry(s_x509services_legacy_componentName, s_x509services_legacy_entryName,
CryptoConfigEntry::ArgType_LDAPURL, ListValue, DoShowError))) {
mWidget->addX509Services(mX509ServicesEntry->urlValueList());
}
mWidget->setX509ReadOnly(mX509ServicesEntry && mX509ServicesEntry->isReadOnly());
{
auto *const newEntry = configEntry(s_pgpservice_componentName, s_pgpservice_groupName, s_pgpservice_entryName,
auto *const newEntry = configEntry(s_pgpservice_componentName, s_pgpservice_entryName,
CryptoConfigEntry::ArgType_String, SingleValue, DoNotShowError);
auto *const legacyEntry = configEntry(s_pgpservice_legacy_componentName, s_pgpservice_legacy_groupName, s_pgpservice_legacy_entryName,
auto *const legacyEntry = configEntry(s_pgpservice_legacy_componentName, s_pgpservice_legacy_entryName,
CryptoConfigEntry::ArgType_String, SingleValue, DoNotShowError);
mOpenPGPServiceEntry = newEntry ? newEntry : legacyEntry;
......@@ -226,13 +216,13 @@ void DirectoryServicesConfigurationPage::load()
if (newEntry && legacyEntry && !newEntry->isSet() && legacyEntry->isSet()) {
// use value of legacy entry if value of new entry is unset
qCDebug(KLEOPATRA_LOG) << "Using value of legacy entry for config entry"
<< s_pgpservice_componentName << "/" << s_pgpservice_groupName << "/" << s_pgpservice_entryName;
<< s_pgpservice_componentName << "/" << s_pgpservice_entryName;
stringValue = legacyEntry->stringValue();
} else if (mOpenPGPServiceEntry) {
stringValue = mOpenPGPServiceEntry->stringValue();
} else {
qCWarning(KLEOPATRA_LOG) << "Unknown or wrong typed config entry"
<< s_pgpservice_componentName << "/" << s_pgpservice_groupName << "/" << s_pgpservice_entryName;
<< s_pgpservice_componentName << "/" << s_pgpservice_entryName;
}
mWidget->addOpenPGPServices(string2urls(parseKeyserver(stringValue).url));
mWidget->setOpenPGPReadOnly(mOpenPGPServiceEntry && mOpenPGPServiceEntry->isReadOnly());
......@@ -257,10 +247,10 @@ void DirectoryServicesConfigurationPage::load()
// read LDAP timeout
// first try to read the config entry as int (GnuPG 2.3)
mTimeoutConfigEntry = configEntry(s_timeout_componentName, s_timeout_groupName, s_timeout_entryName, CryptoConfigEntry::ArgType_Int, SingleValue, DoNotShowError);
mTimeoutConfigEntry = configEntry(s_timeout_componentName, s_timeout_entryName, CryptoConfigEntry::ArgType_Int, SingleValue, DoNotShowError);
if (!mTimeoutConfigEntry) {
// if this fails, then try to read the config entry as unsigned int (GnuPG <= 2.2)
mTimeoutConfigEntry = configEntry(s_timeout_componentName, s_timeout_groupName, s_timeout_entryName, CryptoConfigEntry::ArgType_UInt, SingleValue, DoShowError);
mTimeoutConfigEntry = configEntry(s_timeout_componentName, s_timeout_entryName, CryptoConfigEntry::ArgType_UInt, SingleValue, DoShowError);
}
if (mTimeoutConfigEntry) {
const int ldapTimeout = mTimeoutConfigEntry->argType() == CryptoConfigEntry::ArgType_Int ?
......@@ -271,16 +261,12 @@ void DirectoryServicesConfigurationPage::load()
mTimeout->setTime(time);
}
{
auto *const newEntry = configEntry(s_maxitems_componentName, s_maxitems_groupName, s_maxitems_entryName,
CryptoConfigEntry::ArgType_Int, SingleValue, DoNotShowError);
auto *const legacyEntry = configEntry(s_maxitems_legacy_componentName, s_maxitems_legacy_groupName, s_maxitems_legacy_entryName,
CryptoConfigEntry::ArgType_UInt, SingleValue, DoNotShowError);
mMaxItemsConfigEntry = newEntry ? newEntry : legacyEntry;
if (!mMaxItemsConfigEntry) {
qCWarning(KLEOPATRA_LOG) << "Unknown or wrong typed config entry"
<< s_maxitems_componentName << "/" << s_maxitems_groupName << "/" << s_maxitems_entryName;
}
// read max-replies config entry
// first try to read the config entry as int (GnuPG 2.3)
mMaxItemsConfigEntry = configEntry(s_maxitems_componentName, s_maxitems_entryName, CryptoConfigEntry::ArgType_Int, SingleValue, DoNotShowError);
if (!mMaxItemsConfigEntry) {
// if this fails, then try to read the config entry as unsigned int (GnuPG <= 2.2)
mMaxItemsConfigEntry = configEntry(s_maxitems_componentName, s_maxitems_entryName, CryptoConfigEntry::ArgType_UInt, SingleValue, DoShowError);
}
if (mMaxItemsConfigEntry) {
const int value = mMaxItemsConfigEntry->argType() == CryptoConfigEntry::ArgType_Int ?
......@@ -392,26 +378,23 @@ extern "C"
// Find config entry for ldap servers. Implements runtime checks on the configuration option.
CryptoConfigEntry *DirectoryServicesConfigurationPage::configEntry(const char *componentName,
const char *groupName,
const char *entryName,
CryptoConfigEntry::ArgType argType,
EntryMultiplicity multiplicity,
ShowError showError)
{
CryptoConfigEntry *entry = mConfig->entry(QLatin1String(componentName), QLatin1String(groupName), QLatin1String(entryName));
CryptoConfigEntry *const entry = Kleo::getCryptoConfigEntry(mConfig, componentName, entryName);
if (!entry) {
if (showError == DoShowError) {
KMessageBox::error(this, i18n("Backend error: gpgconf does not seem to know the entry for %1/%2/%3", QLatin1String(componentName), QLatin1String(groupName), QLatin1String(entryName)));
KMessageBox::error(this, i18n("Backend error: gpgconf does not seem to know the entry for %1/%2", QLatin1String(componentName), QLatin1String(entryName)));
}
return nullptr;
}
if (entry->argType() != argType || entry->isList() != bool(multiplicity)) {
if (showError == DoShowError) {
KMessageBox::error(this, i18n("Backend error: gpgconf has wrong type for %1/%2/%3: %4 %5", QLatin1String(componentName), QLatin1String(groupName), QLatin1String(entryName), entry->argType(), entry->isList()));
KMessageBox::error(this, i18n("Backend error: gpgconf has wrong type for %1/%2: %3 %4", QLatin1String(componentName), QLatin1String(entryName), entry->argType(), entry->isList()));
}
return nullptr;
}
return entry;
}
......@@ -49,7 +49,6 @@ private:
};
QGpgME::CryptoConfigEntry *configEntry(const char *componentName,
const char *groupName,
const char *entryName,
QGpgME::CryptoConfigEntry::ArgType argType,
EntryMultiplicity multiplicity,
......
......@@ -15,6 +15,8 @@
#include "smimevalidationpreferences.h"
#include <Libkleo/Compat>
#include <QGpgME/CryptoConfig>
#include <QGpgME/Protocol>
......@@ -133,31 +135,29 @@ struct SMIMECryptoConfigEntries {
SMIMECryptoConfigEntries(CryptoConfig *config)
: mConfig(config),
// Checkboxes
mCheckUsingOCSPConfigEntry(configEntry("gpgsm", "Security", "enable-ocsp", CryptoConfigEntry::ArgType_None, false)),
mEnableOCSPsendingConfigEntry(configEntry("dirmngr", "OCSP", "allow-ocsp", CryptoConfigEntry::ArgType_None, false)),
mDoNotCheckCertPolicyConfigEntry(configEntry("gpgsm", "Security", "disable-policy-checks", CryptoConfigEntry::ArgType_None, false)),
mNeverConsultConfigEntry(configEntry("gpgsm", "Security", "disable-crl-checks", CryptoConfigEntry::ArgType_None, false)),
mAllowMarkTrustedConfigEntry(configEntry("gpg-agent", "Security", "allow-mark-trusted", CryptoConfigEntry::ArgType_None, false)),
mFetchMissingConfigEntry(configEntry("gpgsm", "Security", "auto-issuer-key-retrieve", CryptoConfigEntry::ArgType_None, false)),
mNoAllowMarkTrustedConfigEntry(configEntry("gpg-agent", "Security", "no-allow-mark-trusted", CryptoConfigEntry::ArgType_None, false)),
mCheckUsingOCSPConfigEntry(configEntry("gpgsm", "enable-ocsp", CryptoConfigEntry::ArgType_None, false)),
mEnableOCSPsendingConfigEntry(configEntry("dirmngr", "allow-ocsp", CryptoConfigEntry::ArgType_None, false)),
mDoNotCheckCertPolicyConfigEntry(configEntry("gpgsm", "disable-policy-checks", CryptoConfigEntry::ArgType_None, false)),
mNeverConsultConfigEntry(configEntry("gpgsm", "disable-crl-checks", CryptoConfigEntry::ArgType_None, false)),
mAllowMarkTrustedConfigEntry(configEntry("gpg-agent", "allow-mark-trusted", CryptoConfigEntry::ArgType_None, false)),
mFetchMissingConfigEntry(configEntry("gpgsm", "auto-issuer-key-retrieve", CryptoConfigEntry::ArgType_None, false)),
mNoAllowMarkTrustedConfigEntry(configEntry("gpg-agent", "no-allow-mark-trusted", CryptoConfigEntry::ArgType_None, false)),
// dirmngr-0.9.0 options
mIgnoreServiceURLEntry(configEntry("dirmngr", "OCSP", "ignore-ocsp-service-url", CryptoConfigEntry::ArgType_None, false)),
mIgnoreHTTPDPEntry(configEntry("dirmngr", "HTTP", "ignore-http-dp", CryptoConfigEntry::ArgType_None, false)),
mDisableHTTPEntry(configEntry("dirmngr", "HTTP", "disable-http", CryptoConfigEntry::ArgType_None, false)),
mHonorHTTPProxy(configEntry("dirmngr", "HTTP", "honor-http-proxy", CryptoConfigEntry::ArgType_None, false)),
mIgnoreLDAPDPEntry(configEntry("dirmngr", "LDAP", "ignore-ldap-dp", CryptoConfigEntry::ArgType_None, false)),
mDisableLDAPEntry(configEntry("dirmngr", "LDAP", "disable-ldap", CryptoConfigEntry::ArgType_None, false)),
mIgnoreServiceURLEntry(configEntry("dirmngr", "ignore-ocsp-service-url", CryptoConfigEntry::ArgType_None, false)),
mIgnoreHTTPDPEntry(configEntry("dirmngr", "ignore-http-dp", CryptoConfigEntry::ArgType_None, false)),
mDisableHTTPEntry(configEntry("dirmngr", "disable-http", CryptoConfigEntry::ArgType_None, false)),
mHonorHTTPProxy(configEntry("dirmngr", "honor-http-proxy", CryptoConfigEntry::ArgType_None, false)),
mIgnoreLDAPDPEntry(configEntry("dirmngr", "ignore-ldap-dp", CryptoConfigEntry::ArgType_None, false)),
mDisableLDAPEntry(configEntry("dirmngr", "disable-ldap", CryptoConfigEntry::ArgType_None, false)),
// Other widgets
mOCSPResponderURLConfigEntry(configEntry("dirmngr", "OCSP", "ocsp-responder", CryptoConfigEntry::ArgType_String, false)),
mOCSPResponderSignature(configEntry("dirmngr", "OCSP", "ocsp-signer", CryptoConfigEntry::ArgType_String, false)),
mCustomHTTPProxy(configEntry("dirmngr", "HTTP", "http-proxy", CryptoConfigEntry::ArgType_String, false)),
mCustomLDAPProxy(configEntry("dirmngr", "LDAP", "ldap-proxy", CryptoConfigEntry::ArgType_String, false))
mOCSPResponderURLConfigEntry(configEntry("dirmngr", "ocsp-responder", CryptoConfigEntry::ArgType_String, false)),
mOCSPResponderSignature(configEntry("dirmngr", "ocsp-signer", CryptoConfigEntry::ArgType_String, false)),
mCustomHTTPProxy(configEntry("dirmngr", "http-proxy", CryptoConfigEntry::ArgType_String, false)),
mCustomLDAPProxy(configEntry("dirmngr", "ldap-proxy", CryptoConfigEntry::ArgType_String, false))
{
}
CryptoConfigEntry *configEntry(const char *componentName,
const char *groupName,
const char *entryName,
int argType,
bool isList);
......@@ -365,18 +365,17 @@ void SMimeValidationConfigurationWidget::save() const
}
CryptoConfigEntry *SMIMECryptoConfigEntries::configEntry(const char *componentName,
const char *groupName,
const char *entryName,
int /*CryptoConfigEntry::ArgType*/ argType,
bool isList)
{
CryptoConfigEntry *const entry = mConfig->entry(QLatin1String(componentName), QLatin1String(groupName), QLatin1String(entryName));
CryptoConfigEntry *const entry = getCryptoConfigEntry(mConfig, componentName, entryName);
if (!entry) {
qCWarning(KLEOPATRA_LOG) << QStringLiteral("Backend error: gpgconf doesn't seem to know the entry for %1/%2/%3").arg(QLatin1String(componentName), QLatin1String(groupName), QLatin1String(entryName));
qCWarning(KLEOPATRA_LOG) << QStringLiteral("Backend error: gpgconf doesn't seem to know the entry for %1/%2").arg(QLatin1String(componentName), QLatin1String(entryName));
return nullptr;
}
if (entry->argType() != argType || entry->isList() != isList) {
qCWarning(KLEOPATRA_LOG) << QStringLiteral("Backend error: gpgconf has wrong type for %1/%2/%3: %4 %5").arg(QLatin1String(componentName), QLatin1String(groupName), QLatin1String(entryName)).arg(entry->argType()).arg(entry->isList());
qCWarning(KLEOPATRA_LOG) << QStringLiteral("Backend error: gpgconf has wrong type for %1/%2: %3 %4").arg(QLatin1String(componentName), QLatin1String(entryName)).arg(entry->argType()).arg(entry->isList());
return nullptr;
}
return entry;
......
......@@ -8,6 +8,7 @@
*/
#include "updatenotification.h"
#include <Libkleo/Compat>
#include <Libkleo/GnuPG>
#include "kleopatra_debug.h"
......@@ -44,9 +45,7 @@ namespace
static void gpgconf_set_update_check(bool value)
{
auto conf = QGpgME::cryptoConfig();
auto entry = conf->entry(QStringLiteral("dirmngr"),
QStringLiteral("Enforcement"),
QStringLiteral("allow-version-check"));
auto entry = getCryptoConfigEntry(conf, "dirmngr", "allow-version-check");
if (!entry) {
qCDebug(KLEOPATRA_LOG) << "allow-version-check entry not found";
return;
......
......@@ -32,6 +32,7 @@
#include "utils/keyparameters.h"
#include "utils/userinfo.h"
#include <Libkleo/Compat>
#include <Libkleo/GnuPG>
#include <Libkleo/Stl_Util>
#include <Libkleo/Dn>
......@@ -757,9 +758,7 @@ public:
qCWarning(KLEOPATRA_LOG) << "Failed to obtain cryptoConfig.";
return;
}
const auto entry = conf->entry(QStringLiteral("gpg-agent"),
QStringLiteral("Passphrase policy"),
QStringLiteral("enforce-passphrase-constraints"));
const auto entry = getCryptoConfigEntry(conf, "gpg-agent", "enforce-passphrase-constraints");
if (entry && entry->boolValue()) {
qCDebug(KLEOPATRA_LOG) << "Disabling passphrace cb because of agent config.";
ui.withPassCB->setEnabled(false);
......
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