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>
36bool Kleo::DeVSCompliance::isActive()
38 return getCryptoConfigStringValue(
"gpg",
"compliance") ==
QLatin1StringView{
"de-vs"};
41bool Kleo::DeVSCompliance::isCompliant()
52 if (engineIsVersion(2, 2, 28) && !engineIsVersion(2, 2, 34)) {
55 return getCryptoConfigIntValue(
"gpg",
"compliance_de_vs", 0) != 0;
58bool Kleo::DeVSCompliance::isBetaCompliance()
64 return getCryptoConfigIntValue(
"gpg",
"compliance_de_vs", 0) > 2000;
67bool Kleo::DeVSCompliance::algorithmIsCompliant(std::string_view algo)
69 return !isActive() || Kleo::contains(compliantAlgorithms(), algo);
72bool Kleo::DeVSCompliance::allSubkeysAreCompliant(
const GpgME::Key &key)
78 const auto usableSubkeys = Kleo::count_if(key.subkeys(), [](
const auto &sub) {
79 return !sub.isExpired() && !sub.isRevoked();
81 if (usableSubkeys == 0) {
82 qCDebug(LIBKLEO_LOG) << __func__ <<
"No usable subkeys found for key" << key;
86 return Kleo::all_of(key.subkeys(), [](
const auto &sub) {
87 return sub.isDeVs() || sub.isExpired() || sub.isRevoked() || (!sub.canSign() && !sub.canEncrypt() && !sub.canCertify() && sub.canAuthenticate());
91bool Kleo::DeVSCompliance::userIDIsCompliant(
const GpgME::UserID &
id)
96 return (
id.parent().keyListMode() & GpgME::Validate)
98 &&
id.validity() >= GpgME::UserID::Full
99 && allSubkeysAreCompliant(
id.parent());
102bool Kleo::DeVSCompliance::keyIsCompliant(
const GpgME::Key &key)
107 return (key.keyListMode() & GpgME::Validate)
108 && allUserIDsHaveFullValidity(key)
109 && allSubkeysAreCompliant(key);
112const std::vector<std::string> &Kleo::DeVSCompliance::compliantAlgorithms()
114 static const std::vector<std::string> compliantAlgos = {
121 return isActive() ? compliantAlgos : Kleo::availableAlgorithms();
124const std::vector<std::string> &Kleo::DeVSCompliance::preferredCompliantAlgorithms()
126 static std::vector<std::string> result;
127 if (result.empty()) {
128 const auto &preferredAlgos = Kleo::preferredAlgorithms();
129 result.reserve(preferredAlgos.size());
130 Kleo::copy_if(preferredAlgos, std::back_inserter(result), Kleo::DeVSCompliance::algorithmIsCompliant);
135void Kleo::DeVSCompliance::decorate(
QPushButton *button)
137 decorate(button, isCompliant());
140void Kleo::DeVSCompliance::decorate(
QPushButton *button,
bool compliant)
147 if (!SystemInfo::isHighContrastModeActive()) {
149 button->
setStyleSheet(QStringLiteral(
"QPushButton { background-color: %1; };").arg(bgColor));
153 if (!SystemInfo::isHighContrastModeActive()) {
155 button->
setStyleSheet(QStringLiteral(
"QPushButton { background-color: %1; };").arg(bgColor));
160QString Kleo::DeVSCompliance::name()
162 return name(isCompliant());
165static QString complianceName(
bool compliant)
167 const auto filterId = compliant ? QStringLiteral(
"de-vs-filter") : QStringLiteral(
"not-de-vs-filter");
168 if (
auto filter = KeyFilterManager::instance()->keyFilterByID(filterId)) {
171 return compliant ?
i18n(
"VS-NfD compliant") :
i18n(
"Not VS-NfD compliant");
174QString Kleo::DeVSCompliance::name(
bool compliant)
179 if (compliant && isBetaCompliance()) {
180 return i18nc(
"@info append beta-marker to compliance",
"%1 (beta)", complianceName(compliant));
182 return complianceName(compliant);
QBrush background(BackgroundRole=NormalBackground) const
QString i18nc(const char *context, const char *text, const TYPE &arg...)
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)