Page MenuHome GnuPG

No OneTemporary

diff --git a/src/conf/cryptooperationsconfigwidget.cpp b/src/conf/cryptooperationsconfigwidget.cpp
index 208d4bb8c..b89d4fc76 100644
--- a/src/conf/cryptooperationsconfigwidget.cpp
+++ b/src/conf/cryptooperationsconfigwidget.cpp
@@ -1,392 +1,394 @@
/*
cryptooperationsconfigwidget.cpp
This file is part of kleopatra, the KDE key manager
SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB
SPDX-FileCopyrightText: 2016 Bundesamt für Sicherheit in der Informationstechnik
SPDX-FileContributor: Intevation GmbH
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include <config-kleopatra.h>
#include "cryptooperationsconfigwidget.h"
#include "kleopatra_debug.h"
#include "emailoperationspreferences.h"
#include "fileoperationspreferences.h"
+#include "settings.h"
#include <Libkleo/ChecksumDefinition>
#include <Libkleo/KeyFilterManager>
#include <QGpgME/Protocol>
#include <QGpgME/CryptoConfig>
#include <gpgme++/context.h>
#include <gpgme++/engineinfo.h>
#include <KConfig>
#include <KConfigGroup>
#include <KLocalizedString>
#include <KSharedConfig>
#include <KMessageBox>
#include <QCheckBox>
#include <QComboBox>
#include <QDir>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QPushButton>
#include <QProcess>
#include <QVBoxLayout>
#include <QLabel>
#include <QRegularExpression>
#include <memory>
using namespace Kleo;
using namespace Kleo::Config;
CryptoOperationsConfigWidget::CryptoOperationsConfigWidget(QWidget *p, Qt::WindowFlags f)
: QWidget(p, f),
mApplyBtn(nullptr)
{
setupGui();
}
static void resetDefaults()
{
auto config = QGpgME::cryptoConfig();
if (!config) {
qCWarning(KLEOPATRA_LOG) << "Failed to obtain config";
return;
}
const QStringList componentList = config->componentList();
for (const auto &compName: componentList) {
auto comp = config->component(compName);
if (!comp) {
qCWarning(KLEOPATRA_LOG) << "Failed to find component:" << comp;
return;
}
const QStringList groupList = comp->groupList();
for (const auto &grpName: groupList) {
auto grp = comp->group(grpName);
if (!grp) {
qCWarning(KLEOPATRA_LOG) << "Failed to find group:" << grp << "in component:" << compName;
return;
}
const QStringList entries = grp->entryList();
for (const auto &entryName: entries) {
auto entry = grp->entry(entryName);
if (!entry) {
qCWarning(KLEOPATRA_LOG) << "Failed to find entry:" << entry << "in group:"<< grp << "in component:" << compName;
return;
}
entry->resetToDefault();
}
}
}
config->sync(true);
return;
}
void CryptoOperationsConfigWidget::applyProfile(const QString &profile)
{
if (profile.isEmpty()) {
return;
}
qCDebug(KLEOPATRA_LOG) << "Applying profile " << profile;
if (profile == i18n("default")) {
if (KMessageBox::warningYesNo(
this,
i18n("This means that every configuration option of the GnuPG System will be reset to its default."),
i18n("Apply profile"),
KStandardGuiItem::apply(),
KStandardGuiItem::no()) != KMessageBox::Yes) {
return;
}
resetDefaults();
KeyFilterManager::instance()->reload();
return;
}
mApplyBtn->setEnabled(false);
QDir datadir(QString::fromLocal8Bit(GpgME::dirInfo("datadir")) + QStringLiteral("/../doc/gnupg/examples"));
const auto path = datadir.filePath(profile + QStringLiteral(".prf"));
auto gpgconf = new QProcess;
const auto ei = GpgME::engineInfo(GpgME::GpgConfEngine);
Q_ASSERT (ei.fileName());
gpgconf->setProgram(QFile::decodeName(ei.fileName()));
gpgconf->setProcessChannelMode(QProcess::MergedChannels);
gpgconf->setArguments(QStringList() << QStringLiteral("--runtime")
<< QStringLiteral("--apply-profile")
<< path);
qDebug() << "Starting" << ei.fileName() << "with args" << gpgconf->arguments();
connect(gpgconf, static_cast<void(QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished),
this, [this, gpgconf, profile] () {
mApplyBtn->setEnabled(true);
if (gpgconf->exitStatus() != QProcess::NormalExit) {
KMessageBox::error(this, QStringLiteral("<pre>%1</pre>").arg(QString::fromLocal8Bit(gpgconf->readAll())));
delete gpgconf;
return;
}
delete gpgconf;
KMessageBox::information(this,
i18nc("%1 is the name of the profile",
"The configuration profile \"%1\" was applied.", profile),
i18n("GnuPG Profile - Kleopatra"));
auto config = QGpgME::cryptoConfig();
if (config) {
config->clear();
}
KeyFilterManager::instance()->reload();
});
gpgconf->start();
}
// Get a list of available profile files and add a configuration
// group if there are any.
void CryptoOperationsConfigWidget::setupProfileGui(QBoxLayout *layout)
{
qCDebug(KLEOPATRA_LOG) << "Engine version ";
if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.1.20" || !layout) {
// Profile support is new in 2.1.20
qCDebug(KLEOPATRA_LOG) << "Engine version false";
return;
}
QDir datadir(QString::fromLocal8Bit(GpgME::dirInfo("datadir")) + QStringLiteral("/../doc/gnupg/examples"));
if (!datadir.exists()) {
qCDebug(KLEOPATRA_LOG) << "Failed to find gnupg's example profile directory" << datadir.path();
return;
}
const auto profiles = datadir.entryInfoList(QStringList() << QStringLiteral("*.prf"), QDir::Readable | QDir::Files, QDir::Name);
if (profiles.isEmpty()) {
qCDebug(KLEOPATRA_LOG) << "Failed to find any profiles in: " << datadir.path();
return;
}
auto genGrp = new QGroupBox(i18nc("@title", "General Operations"));
auto profLayout = new QHBoxLayout;
genGrp->setLayout(profLayout);
layout->addWidget(genGrp);
auto profLabel = new QLabel(i18n("Activate GnuPG Profile:"));
profLabel->setToolTip(i18n("A profile consists of various settings that can apply to multiple components of the GnuPG system."));
auto combo = new QComboBox;
profLabel->setBuddy(combo);
// Add an empty Item to avoid the impression that this GUI element
// shows the currently selected profile.
combo->addItem(QString());
// We don't translate "default" here because the other profile names are
// also not translated as they are taken directly from file.
combo->addItem(i18n("default"));
for (const auto &profile: profiles) {
combo->addItem(profile.baseName());
}
mApplyBtn = new QPushButton(i18n("Apply"));
mApplyBtn->setEnabled(false);
profLayout->addWidget(profLabel);
profLayout->addWidget(combo);
profLayout->addWidget(mApplyBtn);
profLayout->addStretch(1);
connect(mApplyBtn, &QPushButton::clicked, this, [this, combo] () {
applyProfile(combo->currentText());
});
connect(combo, qOverload<const QString &>(&QComboBox::currentTextChanged), this, [this] (const QString &text) {
mApplyBtn->setEnabled(!text.isEmpty());
});
}
void CryptoOperationsConfigWidget::setupGui()
{
auto baseLay = new QVBoxLayout(this);
baseLay->setContentsMargins(0, 0, 0, 0);
auto mailGrp = new QGroupBox(i18n("EMail Operations"));
auto mailGrpLayout = new QVBoxLayout;
mQuickSignCB = new QCheckBox(i18n("Don't confirm signing certificate if there is only one valid certificate for the identity"));
mQuickEncryptCB = new QCheckBox(i18n("Don't confirm encryption certificates if there is exactly one valid certificate for each recipient"));
mailGrpLayout->addWidget(mQuickSignCB);
mailGrpLayout->addWidget(mQuickEncryptCB);
mailGrp->setLayout(mailGrpLayout);
baseLay->addWidget(mailGrp);
auto fileGrp = new QGroupBox(i18n("File Operations"));
auto fileGrpLay = new QVBoxLayout;
mPGPFileExtCB = new QCheckBox(i18n(R"(Create OpenPGP encrypted files with ".pgp" file extensions instead of ".gpg")"));
mASCIIArmorCB = new QCheckBox(i18n("Create signed or encrypted files as text files."));
mASCIIArmorCB->setToolTip(i18nc("@info", "Set this option to encode encrypted or signed files as base64 encoded text. "
"So that they can be opened with an editor or sent in a mail body. "
"This will increase file size by one third."));
mAutoDecryptVerifyCB = new QCheckBox(i18n("Automatically start operation based on input detection for decrypt/verify."));
mTmpDirCB = new QCheckBox(i18n("Create temporary decrypted files in the folder of the encrypted file."));
mTmpDirCB->setToolTip(i18nc("@info", "Set this option to avoid using the users temporary directory."));
mSymmetricOnlyCB = new QCheckBox(i18n("Use symmetric encryption only."));
mSymmetricOnlyCB->setToolTip(i18nc("@info", "Set this option to disable public key encryption."));
fileGrpLay->addWidget(mPGPFileExtCB);
fileGrpLay->addWidget(mAutoDecryptVerifyCB);
fileGrpLay->addWidget(mASCIIArmorCB);
fileGrpLay->addWidget(mTmpDirCB);
fileGrpLay->addWidget(mSymmetricOnlyCB);
auto comboLay = new QGridLayout;
auto chkLabel = new QLabel(i18n("Checksum program to use when creating checksum files:"));
comboLay->addWidget(chkLabel, 0, 0);
mChecksumDefinitionCB = new QComboBox;
comboLay->addWidget(mChecksumDefinitionCB, 0, 1);
auto archLabel = new QLabel(i18n("Archive command to use when archiving files:"));
comboLay->addWidget(archLabel, 1, 0);
mArchiveDefinitionCB = new QComboBox;
comboLay->addWidget(mArchiveDefinitionCB, 1, 1);
fileGrpLay->addLayout(comboLay);
fileGrp->setLayout(fileGrpLay);
baseLay->addWidget(fileGrp);
setupProfileGui(baseLay);
baseLay->addStretch(1);
if (!GpgME::hasFeature(0, GpgME::BinaryAndFineGrainedIdentify)) {
/* Auto handling requires a working identify in GpgME.
* so that classify in kleoaptra can correctly detect the input.*/
mAutoDecryptVerifyCB->setVisible(false);
}
connect(mQuickSignCB, &QCheckBox::toggled, this, &CryptoOperationsConfigWidget::changed);
connect(mQuickEncryptCB, &QCheckBox::toggled, this, &CryptoOperationsConfigWidget::changed);
connect(mChecksumDefinitionCB, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &CryptoOperationsConfigWidget::changed);
connect(mArchiveDefinitionCB, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &CryptoOperationsConfigWidget::changed);
connect(mPGPFileExtCB, &QCheckBox::toggled, this, &CryptoOperationsConfigWidget::changed);
connect(mAutoDecryptVerifyCB, &QCheckBox::toggled, this, &CryptoOperationsConfigWidget::changed);
connect(mASCIIArmorCB, &QCheckBox::toggled, this, &CryptoOperationsConfigWidget::changed);
connect(mTmpDirCB, &QCheckBox::toggled, this, &CryptoOperationsConfigWidget::changed);
connect(mSymmetricOnlyCB, &QCheckBox::toggled, this, &CryptoOperationsConfigWidget::changed);
}
CryptoOperationsConfigWidget::~CryptoOperationsConfigWidget() {}
void CryptoOperationsConfigWidget::defaults()
{
EMailOperationsPreferences emailPrefs;
emailPrefs.setDefaults();
mQuickSignCB->setChecked(emailPrefs.quickSignEMail());
mQuickEncryptCB->setChecked(emailPrefs.quickEncryptEMail());
FileOperationsPreferences filePrefs;
filePrefs.setDefaults();
mPGPFileExtCB->setChecked(filePrefs.usePGPFileExt());
mAutoDecryptVerifyCB->setChecked(filePrefs.autoDecryptVerify());
if (mChecksumDefinitionCB->count()) {
mChecksumDefinitionCB->setCurrentIndex(0);
}
if (mArchiveDefinitionCB->count()) {
mArchiveDefinitionCB->setCurrentIndex(0);
}
}
-Q_DECLARE_METATYPE(std::shared_ptr<Kleo::ChecksumDefinition>)
-
void CryptoOperationsConfigWidget::load()
{
const EMailOperationsPreferences emailPrefs;
mQuickSignCB ->setChecked(emailPrefs.quickSignEMail());
mQuickEncryptCB->setChecked(emailPrefs.quickEncryptEMail());
const FileOperationsPreferences filePrefs;
mPGPFileExtCB->setChecked(filePrefs.usePGPFileExt());
mAutoDecryptVerifyCB->setChecked(filePrefs.autoDecryptVerify());
mASCIIArmorCB->setChecked(filePrefs.addASCIIArmor());
mTmpDirCB->setChecked(filePrefs.dontUseTmpDir());
mSymmetricOnlyCB->setChecked(filePrefs.symmetricEncryptionOnly());
- const std::vector< std::shared_ptr<ChecksumDefinition> > cds = ChecksumDefinition::getChecksumDefinitions();
- const std::shared_ptr<ChecksumDefinition> default_cd = ChecksumDefinition::getDefaultChecksumDefinition(cds);
+ const Settings settings;
+ const auto cds = ChecksumDefinition::getChecksumDefinitions();
+ const auto defaultChecksumDefinitionId = settings.checksumDefinitionId();
mChecksumDefinitionCB->clear();
mArchiveDefinitionCB->clear();
for (const std::shared_ptr<ChecksumDefinition> &cd : cds) {
- mChecksumDefinitionCB->addItem(cd->label(), QVariant::fromValue(cd));
- if (cd == default_cd) {
+ mChecksumDefinitionCB->addItem(cd->label(), QVariant{cd->id()});
+ if (cd->id() == defaultChecksumDefinitionId) {
mChecksumDefinitionCB->setCurrentIndex(mChecksumDefinitionCB->count() - 1);
}
}
const QString ad_default_id = filePrefs.archiveCommand();
// This is a weird hack but because we are a KCM we can't link
// against ArchiveDefinition which pulls in loads of other classes.
// So we do the parsing which archive definitions exist here ourself.
if (KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("libkleopatrarc"))) {
const QStringList groups = config->groupList().filter(QRegularExpression(QStringLiteral("^Archive Definition #")));
for (const QString &group : groups) {
const KConfigGroup cGroup(config, group);
const QString id = cGroup.readEntryUntranslated(QStringLiteral("id"));
const QString name = cGroup.readEntry("Name");
mArchiveDefinitionCB->addItem(name, QVariant(id));
if (id == ad_default_id) {
mArchiveDefinitionCB->setCurrentIndex(mArchiveDefinitionCB->count() - 1);
}
}
}
}
void CryptoOperationsConfigWidget::save()
{
EMailOperationsPreferences emailPrefs;
emailPrefs.setQuickSignEMail(mQuickSignCB ->isChecked());
emailPrefs.setQuickEncryptEMail(mQuickEncryptCB->isChecked());
emailPrefs.save();
FileOperationsPreferences filePrefs;
filePrefs.setUsePGPFileExt(mPGPFileExtCB->isChecked());
filePrefs.setAutoDecryptVerify(mAutoDecryptVerifyCB->isChecked());
filePrefs.setAddASCIIArmor(mASCIIArmorCB->isChecked());
filePrefs.setDontUseTmpDir(mTmpDirCB->isChecked());
filePrefs.setSymmetricEncryptionOnly(mSymmetricOnlyCB->isChecked());
+ Settings settings;
const int idx = mChecksumDefinitionCB->currentIndex();
if (idx >= 0) {
- const auto cd = qvariant_cast< std::shared_ptr<ChecksumDefinition> >(mChecksumDefinitionCB->itemData(idx));
- ChecksumDefinition::setDefaultChecksumDefinition(cd);
+ const auto id = mChecksumDefinitionCB->itemData(idx).toString();
+ settings.setChecksumDefinitionId(id);
}
+ settings.save();
const int aidx = mArchiveDefinitionCB->currentIndex();
if (aidx >= 0) {
const QString id = mArchiveDefinitionCB->itemData(aidx).toString();
filePrefs.setArchiveCommand(id);
}
filePrefs.save();
}
diff --git a/src/kcfg/settings.kcfg b/src/kcfg/settings.kcfg
index 4e4481c9e..fdece0ac6 100644
--- a/src/kcfg/settings.kcfg
+++ b/src/kcfg/settings.kcfg
@@ -1,112 +1,118 @@
<?xml version="1.0" encoding="UTF-8"?>
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<kcfgfile name="kleopatrarc" />
<group name="CertificateCreationWizard">
<entry key="CN_placeholder" name="cnPlaceholder" type="String">
<label>Placeholder for CN</label>
<whatsthis>This text will be used as placeholder text for the common name (CN) field of S/MIME certificates.</whatsthis>
<default></default>
</entry>
<entry key="CN_prefill" name="prefillCN" type="Bool">
<label>Prefill CN automatically</label>
<whatsthis>If true, then the common name (CN) field of S/MIME certificates will be prefilled with information gathered from the system,
e.g., from the email settings of the desktop or, on Windows, from the Active Directory.</whatsthis>
<default>true</default>
</entry>
<entry key="EMAIL_placeholder" name="emailPlaceholder" type="String">
<label>Placeholder for EMAIL</label>
<whatsthis>This text will be used as placeholder text for the email address field of OpenPGP and S/MIME certificates.</whatsthis>
<default></default>
</entry>
<entry key="EMAIL_prefill" name="prefillEmail" type="Bool">
<label>Prefill EMAIL automatically</label>
<whatsthis>If true, then the email address field of OpenPGP and S/MIME certificates will be prefilled with information gathered from the system,
e.g., from the email settings of the desktop or, on Windows, from the Active Directory.</whatsthis>
<default>true</default>
</entry>
<entry key="NAME_placeholder" name="namePlaceholder" type="String">
<label>Placeholder for NAME</label>
<whatsthis>This text will be used as placeholder text for the name field of OpenPGP certificates.</whatsthis>
<default></default>
</entry>
<entry key="NAME_prefill" name="prefillName" type="Bool">
<label>Prefill NAME automatically</label>
<whatsthis>If true, then the name field of OpenPGP certificates will be prefilled with information gathered from the system,
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>
<entry key="HideAdvanced" type="Bool">
<label>Hide advanced settings</label>
<whatsthis>If true, hides the advanced settings button in the new certificate wizard.</whatsthis>
<default>false</default>
</entry>
</group>
+ <group name="ChecksumOperations">
+ <entry key="checksum-definition-id" name="ChecksumDefinitionId" type="String">
+ <label>Checksum program to use when creating checksum files</label>
+ <default>sha256sum</default>
+ </entry>
+ </group>
<group name="CMS">
<entry key="Enabled" name="cmsEnabled" type="Bool">
<label>Enable S/MIME</label>
<tooltip>Enables support for S/MIME (CMS).</tooltip>
<whatsthis>If false, then Kleopatra's main UI will not offer any functionality related to S/MIME (CMS).</whatsthis>
<default>true</default>
</entry>
<entry key="AllowCertificateCreation" name="cmsCertificateCreationAllowed" type="Bool">
<label>Allow S/MIME certificate creation</label>
<tooltip>Allows the creation of S/MIME certificate signing requests.</tooltip>
<whatsthis>If false, then Kleopatra will not offer the creation of S/MIME certificate signing requests.</whatsthis>
<default>true</default>
</entry>
<entry key="AllowSigning" name="cmsSigningAllowed" type="Bool">
<label>Allow signing with S/MIME certificates</label>
<tooltip>Allows signing of text or files with S/MIME certificates.</tooltip>
<whatsthis>If false, then Kleopatra will not offer functionality for creating signatures with S/MIME certificates.</whatsthis>
<default>true</default>
</entry>
</group>
<group name="ConfigurationDialog">
<entry name="ShowAppearanceConfiguration" type="Bool">
<label>Show appearance configuration</label>
<default>true</default>
</entry>
<entry name="ShowCryptoOperationsConfiguration" type="Bool">
<label>Show crypto operations configuration</label>
<default>true</default>
</entry>
<entry name="ShowDirectoryServicesConfiguration" type="Bool">
<label>Show directory services configuration</label>
<default>true</default>
</entry>
<entry name="ShowGnuPGSystemConfiguration" type="Bool">
<label>Show GnuPG system configuration</label>
<default>true</default>
</entry>
<entry name="ShowSMimeValidationConfiguration" type="Bool">
<label>Show S/MIME validation configuration</label>
<default>true</default>
</entry>
</group>
<group name="Groups">
<entry name="GroupsEnabled" type="Bool">
<label>Enable Groups</label>
<tooltip>Enable usage of groups of keys.</tooltip>
<whatsthis>Enable usage of groups of keys to create lists of recipients.</whatsthis>
<default>true</default>
</entry>
</group>
<group name="Smartcard">
<entry name="AlwaysSearchCardOnKeyserver" type="Bool">
<label>Always search smartcard certificates on keyserver</label>
<tooltip>Searches for the certificates belonging the smartcard keys on the configured keyserver.</tooltip>
<whatsthis>Searches on keyservers regardless of the protocol for the smartcards key, regardless
of the keyserver protocol. Default behavior is to only do this for LDAP keyservers.</whatsthis>
<default>false</default>
</entry>
</group>
</kcfg>

File Metadata

Mime Type
text/x-diff
Expires
Tue, Apr 14, 9:23 PM (3 h, 47 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
98/48/c4f40e2d6013a4cad15ed2231889

Event Timeline