Commit 0db0273b authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Support arbitrary algorithms in GenCardKeyDialog

Prepare GenCardKeyDialog for usage with other algorithms than just
RSA with different key sizes.

GnuPG-bug-id: 4794
parent f93f44ba
Pipeline #31652 passed with stage
in 38 minutes and 10 seconds
......@@ -64,11 +64,11 @@ public:
// In the future GnuPG may support more algos but for now
// (2.1.18) we are stuck with RSA for on card generation.
auto rsaLabel = new QLabel(i18n("RSA Keysize:"));
mKeySizeCombo = new QComboBox;
auto algorithmLabel = new QLabel(i18n("Algorithm:"));
mAlgorithmCombo = new QComboBox;
grid->addWidget(rsaLabel, row, 0);
grid->addWidget(mKeySizeCombo, row++, 1);
grid->addWidget(algorithmLabel, row, 0);
grid->addWidget(mAlgorithmCombo, row++, 1);
mBackupCheckBox = new QCheckBox(i18n("Backup encryption key"));
mBackupCheckBox->setToolTip(i18n("Backup the encryption key in a file.") + QStringLiteral("<br/>") +
......@@ -87,19 +87,18 @@ public:
{
params.name = mNameEdit->text();
params.email = mEmailEdit->text();
params.keysize = mKeySizeCombo->currentText().toInt();
params.algo = GpgME::Subkey::AlgoRSA;
params.algorithm = mAlgorithmCombo->currentData().toByteArray().toStdString();
params.backup = mBackupCheckBox->isChecked();
q->accept();
}
void setSupportedSizes(const std::vector<int> &sizes)
void setSupportedAlgorithms(const std::vector<std::pair<std::string, QString>> &algorithms, const std::string &defaultAlgo)
{
mKeySizeCombo->clear();
for (auto size: sizes) {
mKeySizeCombo->addItem(QString::number(size));
mAlgorithmCombo->clear();
for (auto algorithm: algorithms) {
mAlgorithmCombo->addItem(algorithm.second, QByteArray::fromStdString(algorithm.first));
}
mKeySizeCombo->setCurrentIndex(mKeySizeCombo->findText(QStringLiteral("2048")));
mAlgorithmCombo->setCurrentIndex(mAlgorithmCombo->findData(QByteArray::fromStdString(defaultAlgo)));
}
void checkAcceptable()
......@@ -126,7 +125,7 @@ public:
QLineEdit *mNameEdit;
QLineEdit *mEmailEdit;
QLabel *mInvalidEmailLabel;
QComboBox *mKeySizeCombo;
QComboBox *mAlgorithmCombo;
QCheckBox *mBackupCheckBox;
};
......@@ -135,9 +134,9 @@ GenCardKeyDialog::GenCardKeyDialog(QWidget *parent) : QDialog(parent),
{
}
void GenCardKeyDialog::setSupportedSizes(const std::vector<int> &sizes)
void GenCardKeyDialog::setSupportedAlgorithms(const std::vector<std::pair<std::string, QString>> &algorithms, const std::string &defaultAlgo)
{
d->setSupportedSizes(sizes);
d->setSupportedAlgorithms(algorithms, defaultAlgo);
}
GenCardKeyDialog::KeyParams GenCardKeyDialog::getKeyParams() const
......
......@@ -28,15 +28,14 @@ public:
QString name;
QString email;
QString comment;
int keysize;
GpgME::Subkey::PubkeyAlgo algo;
std::string algorithm;
bool backup;
};
explicit GenCardKeyDialog(QWidget *parent = nullptr);
KeyParams getKeyParams() const;
void setSupportedSizes(const std::vector<int> &sizes);
void setSupportedAlgorithms(const std::vector<std::pair<std::string, QString>> &algorithms, const std::string &defaultAlgo);
private:
class Private;
......
......@@ -70,7 +70,8 @@ class GenKeyThread: public QThread
protected:
void run() override {
GpgME::GpgGenCardKeyInteractor *ei = new GpgME::GpgGenCardKeyInteractor(mSerial);
ei->setKeySize(mParams.keysize);
ei->setAlgo(GpgME::GpgGenCardKeyInteractor::RSA);
ei->setKeySize(QByteArray::fromStdString(mParams.algorithm).toInt());
ei->setNameUtf8(mParams.name.toStdString());
ei->setEmailUtf8(mParams.email.toStdString());
ei->setDoBackup(mParams.backup);
......@@ -311,15 +312,16 @@ void PGPCardWidget::genkeyRequested()
}
GenCardKeyDialog *dlg = new GenCardKeyDialog(this);
std::vector <int> sizes;
sizes.push_back(1024);
sizes.push_back(2048);
sizes.push_back(3072);
std::vector<std::pair<std::string, QString>> algos = {
{ "1024", QStringLiteral("RSA 1024") },
{ "2048", QStringLiteral("RSA 2048") },
{ "3072", QStringLiteral("RSA 3072") }
};
// There is probably a better way to check for capabilities
if (mIs21) {
sizes.push_back(4096);
algos.push_back({"4096", QStringLiteral("RSA 4096")});
}
dlg->setSupportedSizes(sizes);
dlg->setSupportedAlgorithms(algos, "2048");
connect(dlg, &QDialog::accepted, this, [this, dlg] () {
doGenKey(dlg);
dlg->deleteLater();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment