Page Menu
Home
GnuPG
Search
Configure Global Search
Log In
Files
F34206689
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Size
26 KB
Subscribers
None
View Options
diff --git a/src/dialogs/addsubkeydialog.cpp b/src/dialogs/addsubkeydialog.cpp
index 66913e5ae..8935b6fe0 100644
--- a/src/dialogs/addsubkeydialog.cpp
+++ b/src/dialogs/addsubkeydialog.cpp
@@ -1,632 +1,525 @@
/* -*- mode: c++; c-basic-offset:4 -*-
dialogs/expirydialog.cpp
This file is part of Kleopatra, the KDE keymanager
SPDX-FileCopyrightText: 2008 Klarälvdalens Datakonsult AB
SPDX-FileCopyrightText: 2021 g10 Code GmbH
SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "addsubkeydialog.h"
#include <config-kleopatra.h>
#include "expirydialog.h"
#include "newcertificatewizard/keyalgo_p.h"
#include "utils/expiration.h"
#include "utils/gui-helper.h"
#include "utils/qt-cxx20-compat.h"
#include "utils/scrollarea.h"
#include <gpgme++/key.h>
#include <QGpgME/CryptoConfig>
#include <QGpgME/Protocol>
#include <Libkleo/Compat>
#include <Libkleo/Compliance>
#include <Libkleo/Formatting>
#include <Libkleo/GnuPG>
#include <KConfigGroup>
#include <KDateComboBox>
#include <KLocalizedString>
#include <KMessageBox>
#include <KSharedConfig>
#include <KStandardGuiItem>
#include <QCheckBox>
#include <QDate>
#include <QDialogButtonBox>
#include <QFormLayout>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QRadioButton>
#include <QVBoxLayout>
static const char RSA_KEYSIZES_ENTRY[] = "RSAKeySizes";
static const char RSA_KEYSIZE_LABELS_ENTRY[] = "RSAKeySizeLabels";
static const char PGP_KEY_TYPE_ENTRY[] = "PGPKeyType";
// This should come from gpgme in the future
// For now we only support the basic 2.1 curves and check
// for GnuPG 2.1. The whole subkey / usage generation needs
// new api and a reworked dialog. (ah 10.3.16)
static const QStringList curveNames{
{QStringLiteral("brainpoolP256r1")},
{QStringLiteral("brainpoolP384r1")},
{QStringLiteral("brainpoolP512r1")},
{QStringLiteral("NIST P-256")},
{QStringLiteral("NIST P-384")},
{QStringLiteral("NIST P-521")},
};
using namespace Kleo;
using namespace Kleo::Dialogs;
using namespace Kleo::NewCertificateUi;
using namespace GpgME;
class AddSubkeyDialog::Private
{
friend class ::Kleo::Dialogs::AddSubkeyDialog;
AddSubkeyDialog *const q;
public:
Private(AddSubkeyDialog *qq)
: q{qq}
, ui{qq}
{
}
private:
void slotOnDateChanged();
private:
void setInitialFocus();
private:
bool initialFocusWasSet = false;
struct UI {
- QRadioButton *rsaRB = nullptr;
- QComboBox *rsaKeyStrengthCB = nullptr;
- QRadioButton *eccRB = nullptr;
- QComboBox *eccKeyCurvesCB = nullptr;
+ QComboBox *algoCombo = nullptr;
+ QComboBox *strengthCombo = nullptr;
+
QRadioButton *signingCB = nullptr;
QRadioButton *encryptionCB = nullptr;
QRadioButton *authenticationCB = nullptr;
+
QCheckBox *expiryCB = nullptr;
KDateComboBox *expiryDE = nullptr;
+
QLabel *primaryKeyExpiration = nullptr;
QDialogButtonBox *buttonBox = nullptr;
UI(QDialog *parent)
{
parent->setWindowTitle(i18nc("@title:window", "Advanced Settings"));
auto mainLayout = new QVBoxLayout{parent};
- auto technicalTab = new ScrollArea{parent};
+ auto scrollArea = new ScrollArea{parent};
{
- technicalTab->setFocusPolicy(Qt::NoFocus);
- technicalTab->setFrameStyle(QFrame::NoFrame);
- technicalTab->setBackgroundRole(parent->backgroundRole());
- technicalTab->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- technicalTab->setSizeAdjustPolicy(QScrollArea::AdjustToContents);
- auto tabLayout = qobject_cast<QVBoxLayout *>(technicalTab->widget()->layout());
+ scrollArea->setFocusPolicy(Qt::NoFocus);
+ scrollArea->setFrameStyle(QFrame::NoFrame);
+ scrollArea->setBackgroundRole(parent->backgroundRole());
+ scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ scrollArea->setSizeAdjustPolicy(QScrollArea::AdjustToContents);
+ auto scrollLayout = qobject_cast<QVBoxLayout *>(scrollArea->widget()->layout());
{
- auto groupBox = new QGroupBox{i18nc("@title:group", "Key Material"), technicalTab};
- // auto groupBoxGrid = new QGridLayout{groupBox};
+ auto groupBox = new QGroupBox{i18nc("@title:group", "Key Material"), scrollArea};
auto formLayout = new QFormLayout(groupBox);
- // int row = 0;
- auto algoCombo = new QComboBox(groupBox);
- algoCombo->addItem(QStringLiteral("RSA"));
- algoCombo->addItem(QStringLiteral("ECC"));
+ algoCombo = new QComboBox(groupBox);
+ algoCombo->addItem(QStringLiteral("RSA"), QLatin1String("rsa"));
+ algoCombo->addItem(QStringLiteral("ECC"), QLatin1String("ecc"));
formLayout->addRow(i18n("Algorithm:"), algoCombo);
- // row++;
-
- // rsaRB = new QRadioButton{i18nc("@option:radio", "RSA"), groupBox};
- // rsaRB->setChecked(false);
- // groupBoxGrid->addWidget(rsaRB, row, 0, 1, 2);
- //
- // rsaKeyStrengthCB = new QComboBox{groupBox};
- // rsaKeyStrengthCB->setEnabled(false);
- // groupBoxGrid->addWidget(rsaKeyStrengthCB, row, 2, 1, 1);
- // connect(rsaRB, &QAbstractButton::toggled, rsaKeyStrengthCB, &QWidget::setEnabled);
- //
- // row++;
- // eccRB = new QRadioButton{i18nc("@option:radio", "ECC"), groupBox};
- // groupBoxGrid->addWidget(eccRB, row, 0, 1, 2);
- //
- // eccKeyCurvesCB = new QComboBox{groupBox};
- // eccKeyCurvesCB->setEnabled(false);
- // groupBoxGrid->addWidget(eccKeyCurvesCB, row, 2, 1, 1);
- // connect(eccRB, &QAbstractButton::toggled, eccKeyCurvesCB, &QWidget::setEnabled);
- //
- // groupBoxGrid->setColumnStretch(3, 1);
-
- tabLayout->addWidget(groupBox);
+
+ strengthCombo = new QComboBox(groupBox);
+ formLayout->addRow(i18n("Variant:"), strengthCombo);
+
+ scrollLayout->addWidget(groupBox);
}
{
- auto groupBox = new QGroupBox{i18nc("@title:group", "Certificate Usage"), technicalTab};
+ auto groupBox = new QGroupBox{i18nc("@title:group", "Certificate Usage"), scrollArea};
auto usageLayout = new QVBoxLayout;
signingCB = new QRadioButton{i18nc("@option:check", "Signing"), groupBox};
signingCB->setChecked(true);
usageLayout->addWidget(signingCB);
encryptionCB = new QRadioButton{i18nc("@option:check", "Encryption"), groupBox};
encryptionCB->setChecked(true);
usageLayout->addWidget(encryptionCB);
authenticationCB = new QRadioButton{i18nc("@option:check", "Authentication"), groupBox};
usageLayout->addWidget(authenticationCB);
{
auto hbox = new QHBoxLayout;
expiryCB = new QCheckBox{i18nc("@option:check", "Valid until:"), groupBox};
expiryCB->setChecked(true);
hbox->addWidget(expiryCB);
expiryDE = new KDateComboBox(groupBox);
hbox->addWidget(expiryDE, 1);
connect(expiryCB, &QCheckBox::toggled, expiryDE, &KDateComboBox::setEnabled);
usageLayout->addLayout(hbox);
}
primaryKeyExpiration = new QLabel(groupBox);
primaryKeyExpiration->setVisible(false);
usageLayout->addWidget(primaryKeyExpiration);
groupBox->setLayout(usageLayout);
- tabLayout->addWidget(groupBox);
+ scrollLayout->addWidget(groupBox);
}
- tabLayout->addStretch(1);
+ scrollLayout->addStretch(1);
}
- mainLayout->addWidget(technicalTab);
+ mainLayout->addWidget(scrollArea);
buttonBox = new QDialogButtonBox{parent};
buttonBox->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
mainLayout->addWidget(buttonBox);
}
} ui;
};
-void AddSubkeyDialog::Private::setInitialFocus()
-{
- if (initialFocusWasSet) {
- return;
- }
- // give focus to the checked radio button
- // TODO (void)focusFirstCheckedButton({ui.neverRB, ui.onRB});
- initialFocusWasSet = true;
-}
-
AddSubkeyDialog::AddSubkeyDialog(const GpgME::Key &parent, QWidget *p)
: QDialog{p}
, d{new Private{this}}
, mECCSupported{engineIsVersion(2, 1, 0)}
, mEdDSASupported{engineIsVersion(2, 1, 15)}
{
setWindowTitle(i18nc("@title:window", "Add Subkey"));
- fillKeySizeComboBoxes();
d->ui.expiryCB->setEnabled(unlimitedValidityIsAllowed());
if (!parent.subkey(0).neverExpires()) {
d->ui.expiryDE->setMaximumDate(Kleo::Formatting::expirationDate(parent));
d->ui.primaryKeyExpiration->setText(i18n("Expiration of primary key: %1", Kleo::Formatting::expirationDateString(parent)));
d->ui.primaryKeyExpiration->setVisible(true);
}
d->ui.expiryDE->setMinimumDate(QDate::currentDate());
loadDefaults();
- connect(d->ui.encryptionCB, &QCheckBox::toggled, this, &AddSubkeyDialog::updateWidgetVisibility);
- connect(d->ui.signingCB, &QCheckBox::toggled, this, &AddSubkeyDialog::updateWidgetVisibility);
- connect(d->ui.authenticationCB, &QCheckBox::toggled, this, &AddSubkeyDialog::updateWidgetVisibility);
+ if (!mECCSupported) {
+ d->ui.algoCombo->removeItem(1);
+ }
+
+ connect(d->ui.algoCombo, &QComboBox::currentIndexChanged, this, &AddSubkeyDialog::updateState);
+ connect(d->ui.encryptionCB, &QCheckBox::toggled, this, &AddSubkeyDialog::updateState);
+ connect(d->ui.signingCB, &QCheckBox::toggled, this, &AddSubkeyDialog::updateState);
+ connect(d->ui.authenticationCB, &QCheckBox::toggled, this, &AddSubkeyDialog::updateState);
connect(d->ui.buttonBox, &QDialogButtonBox::accepted, this, &AddSubkeyDialog::accept);
connect(d->ui.buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
}
static void fill_combobox(QComboBox &cb, const QList<int> &sizes, const QStringList &labels)
{
cb.clear();
for (int i = 0, end = sizes.size(); i != end; ++i) {
const int size = std::abs(sizes[i]);
/* As we respect the defaults configurable in GnuPG, and we also have configurable
* defaults in Kleopatra its difficult to print out "default" here. To avoid confusion
* about that its better not to show any default indication. */
cb.addItem(i < labels.size() && !labels[i].trimmed().isEmpty()
? i18ncp("%2: some admin-supplied text, %1: key size in bits", "%2 (1 bit)", "%2 (%1 bits)", size, labels[i].trimmed())
: i18ncp("%1: key size in bits", "1 bit", "%1 bits", size),
size);
if (sizes[i] < 0) {
cb.setCurrentIndex(cb.count() - 1);
}
}
}
void AddSubkeyDialog::fillKeySizeComboBoxes()
{
- const KConfigGroup config(KSharedConfig::openConfig(), "CertificateCreationWizard");
+ const auto ¤t = d->ui.strengthCombo->currentData();
+ d->ui.strengthCombo->clear();
+ if (d->ui.algoCombo->currentData().toString() == QStringLiteral("rsa")) {
+ const KConfigGroup config(KSharedConfig::openConfig(), "CertificateCreationWizard");
+
+ QList<int> rsaKeySizes = config.readEntry(RSA_KEYSIZES_ENTRY, QList<int>() << 2048 << -3072 << 4096);
+ if (DeVSCompliance::isActive()) {
+ rsaKeySizes = config.readEntry(RSA_KEYSIZES_ENTRY, QList<int>() << -3072 << 4096);
+ }
- QList<int> rsaKeySizes = config.readEntry(RSA_KEYSIZES_ENTRY, QList<int>() << 2048 << -3072 << 4096);
- if (DeVSCompliance::isActive()) {
- rsaKeySizes = config.readEntry(RSA_KEYSIZES_ENTRY, QList<int>() << -3072 << 4096);
+ const QStringList rsaKeySizeLabels = config.readEntry(RSA_KEYSIZE_LABELS_ENTRY, QStringList());
+ fill_combobox(*d->ui.strengthCombo, rsaKeySizes, rsaKeySizeLabels);
+ } else {
+ for (const auto &curve : curveNames) {
+ d->ui.strengthCombo->insertItem(d->ui.strengthCombo->count(), curve, curve);
+ }
+ if (mEdDSASupported) {
+ d->ui.strengthCombo->insertItem(0, d->ui.encryptionCB->isChecked() ? QLatin1String("cv25519") : QLatin1String("ed25519"));
+ }
+ if (DeVSCompliance::isActive()) {
+ int i;
+ while ((i = d->ui.strengthCombo->findText(QStringLiteral("NIST"), Qt::MatchStartsWith)) != -1
+ || (i = d->ui.strengthCombo->findText(QStringLiteral("25519"), Qt::MatchEndsWith)) != -1) {
+ d->ui.strengthCombo->removeItem(i);
+ }
+ }
}
-
- const QStringList rsaKeySizeLabels = config.readEntry(RSA_KEYSIZE_LABELS_ENTRY, QStringList());
- fill_combobox(*d->ui.rsaKeyStrengthCB, rsaKeySizes, rsaKeySizeLabels);
-
- if (mEdDSASupported) {
- // If supported we recommend cv25519
- d->ui.eccKeyCurvesCB->addItem(QStringLiteral("ed25519"));
+ if (const auto index = d->ui.strengthCombo->findData(current); index != -1) {
+ d->ui.strengthCombo->setCurrentIndex(index);
}
- d->ui.eccKeyCurvesCB->addItems(curveNames);
}
AddSubkeyDialog::~AddSubkeyDialog() = default;
void AddSubkeyDialog::accept()
{
QDialog::accept();
}
-void AddSubkeyDialog::showEvent(QShowEvent *event)
-{
- d->setInitialFocus();
- QDialog::showEvent(event);
-}
-
bool AddSubkeyDialog::unlimitedValidityIsAllowed() const
{
return !Kleo::maximumExpirationDate().isValid();
}
void AddSubkeyDialog::setKeyType(GpgME::Subkey::PubkeyAlgo algo)
{
- QRadioButton *const rb = is_rsa(algo) ? d->ui.rsaRB : is_ecdsa(algo) || is_eddsa(algo) ? d->ui.eccRB : nullptr;
- if (rb) {
- rb->setChecked(true);
- }
-}
-
-static void set_curve(QComboBox *cb, const QString &curve)
-{
- if (!cb) {
- return;
- }
- const int idx = cb->findText(curve, Qt::MatchFixedString);
- if (idx >= 0) {
- cb->setCurrentIndex(idx);
- }
+ d->ui.algoCombo->setCurrentIndex(is_rsa(algo) ? 0 : 1);
}
GpgME::Subkey::PubkeyAlgo AddSubkeyDialog::keyType() const
{
- if (d->ui.rsaRB->isChecked()) {
- return GpgME::Subkey::AlgoRSA;
- }
- return GpgME::Subkey::AlgoUnknown;
-}
-
-static void set_keysize(QComboBox *cb, unsigned int strength)
-{
- if (!cb) {
- return;
- }
- const int idx = cb->findData(static_cast<int>(strength));
- if (idx >= 0) {
- cb->setCurrentIndex(idx);
- }
+ return d->ui.algoCombo->currentIndex() == 0 ? GpgME::Subkey::AlgoRSA : GpgME::Subkey::AlgoECC;
}
// Extract the algo information from default_pubkey_algo format
//
// and put it into the return values size, algo and curve.
//
// Values look like:
// RSA-2048
// rsa2048/cert,sign+rsa2048/enc
// brainpoolP256r1+brainpoolP256r1
static void parseAlgoString(const QString &algoString, int *size, Subkey::PubkeyAlgo *algo, QString &curve)
{
const auto split = algoString.split(QLatin1Char('/'));
bool isEncrypt = split.size() == 2 && split[1].contains(QLatin1String("enc"));
// Normalize
const auto lowered = split[0].toLower().remove(QLatin1Char('-'));
if (!algo || !size) {
return;
}
*algo = Subkey::AlgoUnknown;
if (lowered.startsWith(QLatin1String("rsa"))) {
*algo = Subkey::AlgoRSA;
}
if (*algo != Subkey::AlgoUnknown) {
bool ok;
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
*size = lowered.rightRef(lowered.size() - 3).toInt(&ok);
#else
*size = QStringView(lowered).right(lowered.size() - 3).toInt(&ok);
#endif
if (!ok) {
// qCWarning(KLEOPATRA_LOG) << "Could not extract size from: " << lowered;
*size = 3072;
}
return;
}
// Now the ECC Algorithms
if (lowered.startsWith(QLatin1String("ed25519"))) {
// Special handling for this as technically
// this is a cv25519 curve used for EDDSA
if (isEncrypt) {
curve = QLatin1String("cv25519");
*algo = Subkey::AlgoECDH;
} else {
curve = split[0];
*algo = Subkey::AlgoEDDSA;
}
return;
}
if (lowered.startsWith(QLatin1String("cv25519")) //
|| lowered.startsWith(QLatin1String("nist")) //
|| lowered.startsWith(QLatin1String("brainpool")) //
|| lowered.startsWith(QLatin1String("secp"))) {
curve = split[0];
*algo = isEncrypt ? Subkey::AlgoECDH : Subkey::AlgoECDSA;
return;
}
// qCWarning(KLEOPATRA_LOG) << "Failed to parse default_pubkey_algo:" << algoString;
}
-// Try to load the default key type from GnuPG
void AddSubkeyDialog::loadDefaultGnuPGKeyType()
{
const auto conf = QGpgME::cryptoConfig();
if (!conf) {
- // qCWarning(KLEOPATRA_LOG) << "Failed to obtain cryptoConfig.";
return;
}
const auto entry = getCryptoConfigEntry(conf, "gpg", "default_pubkey_algo");
if (!entry) {
- // qCDebug(KLEOPATRA_LOG) << "GnuPG does not have default key type. Fallback to RSA";
setKeyType(GpgME::Subkey::AlgoRSA);
return;
}
- // qCDebug(KLEOPATRA_LOG) << "Have default key type: " << entry->stringValue();
-
// Format is <primarytype>[/usage]+<subkeytype>[/usage]
const auto split = entry->stringValue().split(QLatin1Char('+'));
int size = 0;
GpgME::Subkey::PubkeyAlgo algo = GpgME::Subkey::AlgoUnknown;
QString curve;
parseAlgoString(split[0], &size, &algo, curve);
if (algo == GpgME::Subkey::AlgoUnknown) {
setKeyType(GpgME::Subkey::AlgoRSA);
return;
}
setKeyType(algo);
-
if (is_rsa(algo)) {
- setKeyStrength(size);
+ setKeyVariant(size);
} else {
- set_curve(d->ui.eccKeyCurvesCB, curve);
- }
-
- {
- auto algoString = (split.size() == 2) ? split[1] : split[0];
- // If it has no usage we assume encrypt subkey
- if (!algoString.contains(QLatin1Char('/'))) {
- algoString += QStringLiteral("/enc");
- }
-
- parseAlgoString(algoString, &size, &algo, curve);
-
- if (algo == GpgME::Subkey::AlgoUnknown) {
- setKeyType(GpgME::Subkey::AlgoRSA);
- return;
- }
-
- setKeyType(algo);
-
- if (is_rsa(algo)) {
- if (keyType() == GpgME::Subkey::AlgoRSA) {
- set_keysize(d->ui.rsaKeyStrengthCB, size);
- }
- } else {
- set_curve(d->ui.eccKeyCurvesCB, curve);
- }
+ setKeyVariant(curve);
}
}
-void AddSubkeyDialog::setKeyStrength(unsigned int strength)
+void AddSubkeyDialog::setKeyVariant(const QVariant &variant)
{
- set_keysize(d->ui.rsaKeyStrengthCB, strength);
+ auto index = d->ui.strengthCombo->findData(variant);
+ if (index != -1) {
+ d->ui.strengthCombo->setCurrentIndex(index);
+ }
}
void AddSubkeyDialog::loadDefaults()
{
- loadDefaultKeyType();
loadDefaultExpiration();
-
- updateWidgetVisibility();
+ updateState();
+ loadDefaultKeyType();
+ updateState(); // intentional
+ loadDefaultKeyType();
}
-void AddSubkeyDialog::updateWidgetVisibility()
+void AddSubkeyDialog::updateState()
{
- d->ui.eccKeyCurvesCB->setVisible(mECCSupported);
- d->ui.eccRB->setVisible(mECCSupported);
-
- const bool deVsHack = DeVSCompliance::isActive();
-
- if (deVsHack) {
- // GnuPG Provides no API to query which keys are compliant for
- // a mode. If we request a different one it will error out so
- // we have to remove the options.
- //
- // Does anyone want to use NIST anyway?
- int i;
- while ((i = d->ui.eccKeyCurvesCB->findText(QStringLiteral("NIST"), Qt::MatchStartsWith)) != -1
- || (i = d->ui.eccKeyCurvesCB->findText(QStringLiteral("25519"), Qt::MatchEndsWith)) != -1) {
- d->ui.eccKeyCurvesCB->removeItem(i);
- }
- }
-
- auto encrypt = d->ui.encryptionCB->isChecked();
-
// TODO relevant?
if (keyTypeImmutable) {
- d->ui.rsaRB->setEnabled(false);
- d->ui.eccRB->setEnabled(false);
+ d->ui.algoCombo->setEnabled(false);
// force usage if key type is forced
d->ui.signingCB->setEnabled(false);
d->ui.encryptionCB->setEnabled(false);
d->ui.authenticationCB->setEnabled(false);
} else {
- d->ui.rsaRB->setEnabled(true);
- d->ui.eccRB->setEnabled(true);
+ d->ui.algoCombo->setEnabled(true);
}
- if (encrypt) {
- const int idx = d->ui.eccKeyCurvesCB->findText(QLatin1String("ed25519"), Qt::MatchFixedString);
- if (idx >= 0) {
- d->ui.eccKeyCurvesCB->setItemText(idx, QLatin1String("cv25519"));
- }
- } else {
- const int idx = d->ui.eccKeyCurvesCB->findText(QLatin1String("cv25519"), Qt::MatchFixedString);
- if (idx >= 0) {
- d->ui.eccKeyCurvesCB->setItemText(idx, QLatin1String("ed25519"));
- }
- }
+ fillKeySizeComboBoxes();
}
void AddSubkeyDialog::loadDefaultKeyType()
{
const KConfigGroup config(KSharedConfig::openConfig(), "CertificateCreationWizard");
const QString entry = QLatin1String(PGP_KEY_TYPE_ENTRY);
const QString keyType = config.readEntry(entry).trimmed().toUpper();
+ // TODO: this whole thing looks almost useless; is there a point in not always using loadDefaultGnuPGKeyType?
if (keyType.isEmpty() && engineIsVersion(2, 1, 17)) {
loadDefaultGnuPGKeyType();
} else {
if (!keyType.isEmpty() && keyType != QLatin1String("RSA")) {
// qCWarning(KLEOPATRA_LOG) << "invalid value \"" << qPrintable(keyType) << "\" for entry \"[CertificateCreationWizard]" << qPrintable(entry) <<
// "\"";
}
setKeyType(Subkey::AlgoRSA);
}
keyTypeImmutable = config.isEntryImmutable(entry);
}
void AddSubkeyDialog::loadDefaultExpiration()
{
- if (unlimitedValidityIsAllowed()) {
- setExpiryDate(defaultExpirationDate(ExpirationOnUnlimitedValidity::NoExpiration));
- } else {
- setExpiryDate(defaultExpirationDate(ExpirationOnUnlimitedValidity::InternalDefaultExpiration));
- }
+ setExpiryDate(defaultExpirationDate(unlimitedValidityIsAllowed() ? ExpirationOnUnlimitedValidity::NoExpiration
+ : ExpirationOnUnlimitedValidity::InternalDefaultExpiration));
}
QDate AddSubkeyDialog::forceDateIntoAllowedRange(QDate date) const
{
const auto minDate = d->ui.expiryDE->minimumDate();
if (minDate.isValid() && date < minDate) {
date = minDate;
}
const auto maxDate = d->ui.expiryDE->maximumDate();
if (maxDate.isValid() && date > maxDate) {
date = maxDate;
}
return date;
}
void AddSubkeyDialog::setExpiryDate(QDate date)
{
if (date.isValid()) {
d->ui.expiryDE->setDate(forceDateIntoAllowedRange(date));
} else {
// check if unlimited validity is allowed
if (unlimitedValidityIsAllowed()) {
d->ui.expiryDE->setDate(date);
}
}
if (d->ui.expiryCB->isEnabled()) {
d->ui.expiryCB->setChecked(d->ui.expiryDE->isValid());
}
}
QString AddSubkeyDialog::usage() const
{
if (d->ui.signingCB->isChecked()) {
return QLatin1String("sign");
}
if (d->ui.encryptionCB->isChecked()) {
return QLatin1String("encr");
}
return QLatin1String("auth");
}
QString AddSubkeyDialog::algo() const
{
- if (d->ui.rsaRB->isChecked()) {
+ if (d->ui.algoCombo->currentData().toString() == QLatin1String("rsa")) {
return QLatin1String("rsa") + size();
}
return curve();
}
static QString get_keysize(const QComboBox *cb)
{
if (!cb) {
return {};
}
const int idx = cb->currentIndex();
if (idx < 0) {
return {};
}
return cb->itemData(idx).toString();
}
QString AddSubkeyDialog::size() const
{
- if (d->ui.rsaRB->isChecked()) {
- return get_keysize(d->ui.rsaKeyStrengthCB);
- }
+ get_keysize(d->ui.strengthCombo);
return {};
}
QString AddSubkeyDialog::curve() const
{
- return d->ui.eccKeyCurvesCB->currentText() + u'/' + usage();
+ return d->ui.strengthCombo->currentText() + u'/' + usage();
}
QDate AddSubkeyDialog::expires() const
{
return d->ui.expiryDE->date();
}
#include "moc_addsubkeydialog.cpp"
diff --git a/src/dialogs/addsubkeydialog.h b/src/dialogs/addsubkeydialog.h
index 91c6ad6c6..2bf4ab137 100644
--- a/src/dialogs/addsubkeydialog.h
+++ b/src/dialogs/addsubkeydialog.h
@@ -1,63 +1,60 @@
/*
SPDX-FileCopyrightText: 2023 g10 Code GmbH
SPDX-FileContributor: Tobias Fella <tobias.fella@gnupg.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include <QDialog>
#include <memory.h>
#include <gpgme++/key.h>
class QDate;
-class QShowEvent;
namespace Kleo
{
namespace Dialogs
{
class AddSubkeyDialog : public QDialog
{
Q_OBJECT
public:
explicit AddSubkeyDialog(const GpgME::Key &parent, QWidget *p = nullptr);
~AddSubkeyDialog() override;
void accept() override;
QString usage() const;
QString algo() const;
QDate expires() const;
-protected:
- void showEvent(QShowEvent *event) override;
-
private:
class Private;
std::unique_ptr<Private> d;
void fillKeySizeComboBoxes();
bool mECCSupported;
bool mEdDSASupported;
bool unlimitedValidityIsAllowed() const;
void loadDefaultGnuPGKeyType();
void setKeyType(GpgME::Subkey::PubkeyAlgo algo);
void setKeyStrength(unsigned int strength);
GpgME::Subkey::PubkeyAlgo keyType() const;
void loadDefaults();
void loadDefaultKeyType();
void loadDefaultExpiration();
bool keyTypeImmutable = false;
void setExpiryDate(QDate date);
QDate forceDateIntoAllowedRange(QDate date) const;
- void updateWidgetVisibility();
+ void updateState();
+ void setKeyVariant(const QVariant &variant);
QString curve() const;
QString size() const;
};
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Dec 18, 8:57 AM (11 h, 33 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
40/51/b771eb5dfde76d5c8f831f933a59
Attached To
rKLEOPATRA Kleopatra
Event Timeline
Log In to Comment