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 std::vector<std::string> compliantAlgos;
116 return Kleo::availableAlgorithms();
118 if (compliantAlgos.empty()) {
119 compliantAlgos.reserve(7);
127#if GPGMEPP_SUPPORTS_KYBER
128 if (engineIsVersion(2, 5, 2)) {
129 compliantAlgos.insert(compliantAlgos.end(),
137 return compliantAlgos;
140const std::vector<std::string> &Kleo::DeVSCompliance::preferredCompliantAlgorithms()
142 static std::vector<std::string> result;
143 if (result.empty()) {
144 const auto &preferredAlgos = Kleo::preferredAlgorithms();
145 result.reserve(preferredAlgos.size());
146 Kleo::copy_if(preferredAlgos, std::back_inserter(result), Kleo::DeVSCompliance::algorithmIsCompliant);
151void Kleo::DeVSCompliance::decorate(
QPushButton *button)
153 decorate(button, isCompliant());
156void Kleo::DeVSCompliance::decorate(
QPushButton *button,
bool compliant)
163 if (!SystemInfo::isHighContrastModeActive()) {
165 button->
setStyleSheet(QStringLiteral(
"QPushButton { background-color: %1; };").arg(bgColor));
169 if (!SystemInfo::isHighContrastModeActive()) {
171 button->
setStyleSheet(QStringLiteral(
"QPushButton { background-color: %1; };").arg(bgColor));
176QString Kleo::DeVSCompliance::name()
178 return name(isCompliant());
181static QString complianceName(
bool compliant)
183 const auto filterId = compliant ? QStringLiteral(
"de-vs-filter") : QStringLiteral(
"not-de-vs-filter");
184 if (
auto filter = KeyFilterManager::instance()->keyFilterByID(filterId)) {
187 return compliant ?
i18n(
"VS-NfD compliant") :
i18n(
"Not VS-NfD compliant");
190QString Kleo::DeVSCompliance::name(
bool compliant)
195 if (compliant && isBetaCompliance()) {
196 return i18nc(
"@info append beta-marker to compliance",
"%1 (beta)", complianceName(compliant));
198 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)