11#include <config-libkleo.h>
13#include "compliance.h"
16#include "cryptoconfig.h"
18#include "keyhelpers.h"
19#include "stringutils.h"
20#include "systeminfo.h"
22#include <libkleo/debug.h>
23#include <libkleo/keyfiltermanager.h>
25#include <libkleo_debug.h>
27#include <KColorScheme>
28#include <KLocalizedString>
32#include <gpgme++/key.h>
34bool Kleo::DeVSCompliance::isActive()
36 return getCryptoConfigStringValue(
"gpg",
"compliance") ==
QLatin1StringView{
"de-vs"};
39bool Kleo::DeVSCompliance::isCompliant()
50 if (engineIsVersion(2, 2, 28) && !engineIsVersion(2, 2, 34)) {
53 return getCryptoConfigIntValue(
"gpg",
"compliance_de_vs", 0) != 0;
56bool Kleo::DeVSCompliance::algorithmIsCompliant(std::string_view algo)
58 return !isActive() || Kleo::contains(compliantAlgorithms(), algo);
61bool Kleo::DeVSCompliance::allSubkeysAreCompliant(
const GpgME::Key &key)
67 const auto usableSubkeys = Kleo::count_if(key.subkeys(), [](
const auto &sub) {
68 return !sub.isExpired() && !sub.isRevoked();
70 if (usableSubkeys == 0) {
71 qCDebug(LIBKLEO_LOG) << __func__ <<
"No usable subkeys found for key" << key;
75 return Kleo::all_of(key.subkeys(), [](
const auto &sub) {
76 return sub.isDeVs() || sub.isExpired() || sub.isRevoked() || (!sub.canSign() && !sub.canEncrypt() && !sub.canCertify() && sub.canAuthenticate());
80bool Kleo::DeVSCompliance::userIDIsCompliant(
const GpgME::UserID &
id)
85 return (
id.parent().keyListMode() & GpgME::Validate)
87 &&
id.validity() >= GpgME::UserID::Full
88 && allSubkeysAreCompliant(
id.parent());
91bool Kleo::DeVSCompliance::keyIsCompliant(
const GpgME::Key &key)
96 return (key.keyListMode() & GpgME::Validate)
97 && allUserIDsHaveFullValidity(key)
98 && allSubkeysAreCompliant(key);
101const std::vector<std::string> &Kleo::DeVSCompliance::compliantAlgorithms()
103 static const std::vector<std::string> compliantAlgos = {
110 return isActive() ? compliantAlgos : Kleo::availableAlgorithms();
113const std::vector<std::string> &Kleo::DeVSCompliance::preferredCompliantAlgorithms()
115 static std::vector<std::string> result;
116 if (result.empty()) {
117 const auto &preferredAlgos = Kleo::preferredAlgorithms();
118 result.reserve(preferredAlgos.size());
119 Kleo::copy_if(preferredAlgos, std::back_inserter(result), Kleo::DeVSCompliance::algorithmIsCompliant);
124void Kleo::DeVSCompliance::decorate(
QPushButton *button)
126 decorate(button, isCompliant());
129void Kleo::DeVSCompliance::decorate(
QPushButton *button,
bool compliant)
136 if (!SystemInfo::isHighContrastModeActive()) {
138 button->
setStyleSheet(QStringLiteral(
"QPushButton { background-color: %1; };").arg(bgColor));
142 if (!SystemInfo::isHighContrastModeActive()) {
144 button->
setStyleSheet(QStringLiteral(
"QPushButton { background-color: %1; };").arg(bgColor));
149QString Kleo::DeVSCompliance::name()
151 return name(isCompliant());
154QString Kleo::DeVSCompliance::name(
bool compliant)
156 const auto filterId = compliant ? QStringLiteral(
"de-vs-filter") : QStringLiteral(
"not-de-vs-filter");
157 if (
auto filter = KeyFilterManager::instance()->keyFilterByID(filterId)) {
160 return compliant ?
i18n(
"VS-NfD compliant") :
i18n(
"Not VS-NfD compliant");
QBrush background(BackgroundRole=NormalBackground) const
QString i18n(const char *text, const TYPE &arg...)
const QColor & color() const const
QString name(NameFormat format) const const
QIcon fromTheme(const QString &name)
QFuture< void > filter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&filterFunction)