aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSaturneric <[email protected]>2023-02-07 10:26:27 +0000
committerSaturneric <[email protected]>2023-02-07 10:26:27 +0000
commitece58986669000baf696edafccb0197a54c0b7c1 (patch)
treec3b0f91e01603be6387f624ef01be9b05774f4b1
parentfix: solve an issue in version checking (diff)
downloadGpgFrontend-ece58986669000baf696edafccb0197a54c0b7c1.tar.gz
GpgFrontend-ece58986669000baf696edafccb0197a54c0b7c1.zip
fix: solve bugs in subkey generation
-rw-r--r--src/core/GpgContext.cpp22
-rw-r--r--src/core/function/gpg/GpgKeyOpera.cpp3
-rw-r--r--src/ui/UserInterfaceUtils.cpp2
-rw-r--r--src/ui/dialog/key_generate/KeygenDialog.cpp4
-rw-r--r--src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp55
-rw-r--r--src/ui/dialog/key_generate/SubkeyGenerateDialog.h2
-rw-r--r--src/ui/widgets/TextEdit.cpp2
7 files changed, 63 insertions, 27 deletions
diff --git a/src/core/GpgContext.cpp b/src/core/GpgContext.cpp
index e7b360e8..1b2669b8 100644
--- a/src/core/GpgContext.cpp
+++ b/src/core/GpgContext.cpp
@@ -257,6 +257,8 @@ gpgme_error_t GpgContext::custom_passphrase_cb(void *opaque,
const char *uid_hint,
const char *passphrase_info,
int last_was_bad, int fd) {
+ SPDLOG_INFO("custom passphrase cb called, bad times: {}", last_was_bad);
+
if (last_was_bad > 3) {
SPDLOG_WARN("failure_counts is over three times");
return gpgme_error_from_errno(GPG_ERR_CANCELED);
@@ -301,17 +303,19 @@ std::string GpgContext::need_user_input_passphrase() {
std::string final_passphrase;
bool input_done = false;
SPDLOG_DEBUG("loop start to wait from user");
- connect(CoreSignalStation::GetInstance(),
- &CoreSignalStation::SignalUserInputPassphraseDone, this,
- [&](QString passphrase) {
- SPDLOG_DEBUG("SignalUserInputPassphraseDone emitted");
- final_passphrase = passphrase.toStdString();
- input_done = true;
- });
+ auto connection =
+ connect(CoreSignalStation::GetInstance(),
+ &CoreSignalStation::SignalUserInputPassphraseDone, this,
+ [&](QString passphrase) {
+ SPDLOG_DEBUG("SignalUserInputPassphraseDone emitted");
+ final_passphrase = passphrase.toStdString();
+ input_done = true;
+ });
while (!input_done) {
- SPDLOG_DEBUG("loppe still waiting...");
- sleep(1);
+ QCoreApplication::processEvents(QEventLoop::AllEvents, 800);
}
+ disconnect(connection);
+
SPDLOG_DEBUG("lopper end");
return final_passphrase;
}
diff --git a/src/core/function/gpg/GpgKeyOpera.cpp b/src/core/function/gpg/GpgKeyOpera.cpp
index 00c0a6c8..d63afc0d 100644
--- a/src/core/function/gpg/GpgKeyOpera.cpp
+++ b/src/core/function/gpg/GpgKeyOpera.cpp
@@ -212,8 +212,7 @@ GpgFrontend::GpgError GpgFrontend::GpgKeyOpera::GenerateSubkey(
if (params->IsAllowSigning()) flags |= GPGME_CREATE_SIGN;
if (params->IsAllowAuthentication()) flags |= GPGME_CREATE_AUTH;
if (params->IsNonExpired()) flags |= GPGME_CREATE_NOEXPIRE;
-
- flags |= GPGME_CREATE_NOPASSWD;
+ if (params->IsNoPassPhrase()) flags |= GPGME_CREATE_NOPASSWD;
SPDLOG_INFO("GpgFrontend::GpgKeyOpera::GenerateSubkey args: {} {} {} {}",
key.GetId(), algo, expires, flags);
diff --git a/src/ui/UserInterfaceUtils.cpp b/src/ui/UserInterfaceUtils.cpp
index 72ebe6f6..7ab5469a 100644
--- a/src/ui/UserInterfaceUtils.cpp
+++ b/src/ui/UserInterfaceUtils.cpp
@@ -428,7 +428,7 @@ void CommonUtils::slot_popup_passphrase_input_dialog() {
dialog->setInputMode(QInputDialog::TextInput);
dialog->setTextEchoMode(QLineEdit::Password);
dialog->setLabelText("Please Input The Password");
- dialog->resize(600, 80);
+ dialog->resize(500, 80);
dialog->exec();
QString password = dialog->textValue();
diff --git a/src/ui/dialog/key_generate/KeygenDialog.cpp b/src/ui/dialog/key_generate/KeygenDialog.cpp
index 5cd6e664..91f3656f 100644
--- a/src/ui/dialog/key_generate/KeygenDialog.cpp
+++ b/src/ui/dialog/key_generate/KeygenDialog.cpp
@@ -402,7 +402,7 @@ QGroupBox* KeyGenDialog::create_basic_info_group_box() {
vbox1->addWidget(new QLabel(QString(_("KeySize (in Bit)")) + ": "), 4, 0);
vbox1->addWidget(new QLabel(QString(_("Key Type")) + ": "), 5, 0);
vbox1->addWidget(new QLabel(QString(_("Password")) + ": "), 6, 0);
- vbox1->addWidget(new QLabel(QString(_("Non Pass Phrase")) + ": "), 7, 0);
+ vbox1->addWidget(new QLabel(QString(_("Non Pass Phrase")) + ": "), 6, 3);
vbox1->addWidget(name_edit_, 0, 1, 1, 3);
vbox1->addWidget(email_edit_, 1, 1, 1, 3);
@@ -412,7 +412,7 @@ QGroupBox* KeyGenDialog::create_basic_info_group_box() {
vbox1->addWidget(key_size_spin_box_, 4, 1);
vbox1->addWidget(key_type_combo_box_, 5, 1);
vbox1->addWidget(passphrase_edit_, 6, 1);
- vbox1->addWidget(no_pass_phrase_check_box_, 7, 1);
+ vbox1->addWidget(no_pass_phrase_check_box_, 6, 2);
auto basicInfoGroupBox = new QGroupBox();
basicInfoGroupBox->setLayout(vbox1);
diff --git a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp
index 661f63c6..d6e02397 100644
--- a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp
+++ b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp
@@ -28,11 +28,12 @@
#include <cassert>
+#include "core/common/CoreCommonUtil.h"
#include "core/function/GlobalSettingStation.h"
#include "core/function/gpg/GpgKeyGetter.h"
#include "core/function/gpg/GpgKeyOpera.h"
-#include "dialog/WaitingDialog.h"
#include "ui/SignalStation.h"
+#include "ui/dialog/WaitingDialog.h"
namespace GpgFrontend::UI {
@@ -60,15 +61,20 @@ SubkeyGenerateDialog::SubkeyGenerateDialog(const KeyId& key_id, QWidget* parent)
key_usage_group_box_ = create_key_usage_group_box();
- auto* groupGrid = new QGridLayout(this);
- groupGrid->addWidget(create_basic_info_group_box(), 0, 0);
- groupGrid->addWidget(key_usage_group_box_, 1, 0);
+ auto* group_grid = new QGridLayout(this);
+ group_grid->addWidget(create_basic_info_group_box(), 0, 0);
+ group_grid->addWidget(key_usage_group_box_, 1, 0);
- auto* nameList = new QWidget(this);
- nameList->setLayout(groupGrid);
+ auto* tipps_label = new QLabel(
+ QString(_("Tipps: if the key pair has a passphrase, the subkey's "
+ "passphrase must be equal to it.")));
+ group_grid->addWidget(tipps_label);
+
+ auto* name_list = new QWidget(this);
+ name_list->setLayout(group_grid);
auto* vbox2 = new QVBoxLayout();
- vbox2->addWidget(nameList);
+ vbox2->addWidget(name_list);
vbox2->addWidget(error_label_);
vbox2->addWidget(button_box_);
@@ -121,6 +127,8 @@ QGroupBox* SubkeyGenerateDialog::create_basic_info_group_box() {
error_label_ = new QLabel();
key_size_spin_box_ = new QSpinBox(this);
key_type_combo_box_ = new QComboBox(this);
+ no_pass_phrase_check_box_ = new QCheckBox(this);
+ passphrase_edit_ = new QLineEdit(this);
for (auto& algo : GenKeyInfo::GetSupportedSubkeyAlgo()) {
key_type_combo_box_->addItem(QString::fromStdString(algo.first));
@@ -142,15 +150,19 @@ QGroupBox* SubkeyGenerateDialog::create_basic_info_group_box() {
auto* vbox1 = new QGridLayout;
- vbox1->addWidget(new QLabel(QString(_("Expiration Date")) + ": "), 2, 0);
- vbox1->addWidget(new QLabel(QString(_("Never Expire")) + ": "), 2, 3);
- vbox1->addWidget(new QLabel(QString(_("KeySize (in Bit)")) + ": "), 1, 0);
vbox1->addWidget(new QLabel(QString(_("Key Type")) + ": "), 0, 0);
+ vbox1->addWidget(new QLabel(QString(_("KeySize (in Bit)")) + ": "), 1, 0);
+ vbox1->addWidget(new QLabel(QString(_("Expiration Date")) + ": "), 2, 0);
+ vbox1->addWidget(new QLabel(QString(_("Never Expire"))), 2, 3);
+ vbox1->addWidget(new QLabel(QString(_("Password")) + ": "), 3, 0);
+ vbox1->addWidget(new QLabel(QString(_("Non Pass Phrase"))), 3, 3);
+ vbox1->addWidget(key_type_combo_box_, 0, 1);
+ vbox1->addWidget(key_size_spin_box_, 1, 1);
vbox1->addWidget(date_edit_, 2, 1);
vbox1->addWidget(expire_check_box_, 2, 2);
- vbox1->addWidget(key_size_spin_box_, 1, 1);
- vbox1->addWidget(key_type_combo_box_, 0, 1);
+ vbox1->addWidget(passphrase_edit_, 3, 1);
+ vbox1->addWidget(no_pass_phrase_check_box_, 3, 2);
auto basicInfoGroupBox = new QGroupBox();
basicInfoGroupBox->setLayout(vbox1);
@@ -179,6 +191,12 @@ void SubkeyGenerateDialog::set_signal_slot() {
connect(key_type_combo_box_, qOverload<int>(&QComboBox::currentIndexChanged),
this, &SubkeyGenerateDialog::slot_activated_key_type);
+
+ connect(no_pass_phrase_check_box_, &QCheckBox::stateChanged, this,
+ [this](int state) -> void {
+ gen_key_info_->SetNonPassPhrase(state != 0);
+ passphrase_edit_->setDisabled(state != 0);
+ });
}
void SubkeyGenerateDialog::slot_expire_box_changed() {
@@ -249,6 +267,10 @@ void SubkeyGenerateDialog::slot_key_gen_accept() {
err_stream << " " << _("Expiration time no more than 2 years.") << " ";
}
+ if (passphrase_edit_->isEnabled() && passphrase_edit_->text().size() == 0) {
+ err_stream << " " << _("Password is empty.") << std::endl;
+ }
+
auto err_string = err_stream.str();
if (err_string.empty()) {
@@ -261,6 +283,11 @@ void SubkeyGenerateDialog::slot_key_gen_accept() {
boost::posix_time::from_time_t(date_edit_->dateTime().toTime_t()));
}
+ if (!gen_key_info_->IsNoPassPhrase()) {
+ CoreCommonUtil::GetInstance()->SetTempCacheValue(
+ "__key_passphrase", this->passphrase_edit_->text().toStdString());
+ }
+
GpgError error;
auto thread = QThread::create([&]() {
SPDLOG_INFO("thread started");
@@ -276,6 +303,10 @@ void SubkeyGenerateDialog::slot_key_gen_accept() {
}
waiting_dialog->close();
+ if (!gen_key_info_->IsNoPassPhrase()) {
+ CoreCommonUtil::GetInstance()->ResetTempCacheValue("__key_passphrase");
+ }
+
if (check_gpg_error_2_err_code(error) == GPG_ERR_NO_ERROR) {
auto* msg_box = new QMessageBox((QWidget*)this->parent());
msg_box->setAttribute(Qt::WA_DeleteOnClose);
diff --git a/src/ui/dialog/key_generate/SubkeyGenerateDialog.h b/src/ui/dialog/key_generate/SubkeyGenerateDialog.h
index 1e6608b2..731bb951 100644
--- a/src/ui/dialog/key_generate/SubkeyGenerateDialog.h
+++ b/src/ui/dialog/key_generate/SubkeyGenerateDialog.h
@@ -69,6 +69,8 @@ class SubkeyGenerateDialog : public GeneralDialog {
QComboBox* key_type_combo_box_{}; ///< Combobox for Key tpe
QDateTimeEdit* date_edit_{}; ///< Date edit for expiration date
QCheckBox* expire_check_box_{}; ///< Checkbox, if key should expire
+ QCheckBox* no_pass_phrase_check_box_{}; ///< Checkbox, if key should expire
+ QLineEdit* passphrase_edit_{};
std::vector<QCheckBox*> key_usage_check_boxes_; ///< ENCR, SIGN, CERT, AUTH
QDateTime max_date_time_; ///<
diff --git a/src/ui/widgets/TextEdit.cpp b/src/ui/widgets/TextEdit.cpp
index 5d10ece9..344f422e 100644
--- a/src/ui/widgets/TextEdit.cpp
+++ b/src/ui/widgets/TextEdit.cpp
@@ -632,7 +632,7 @@ void TextEdit::slot_save_status_to_cache_for_revovery() {
auto raw_text = document->toRawText().toStdString();
SPDLOG_DEBUG("unsaved page index: {}, tab title: {} tab content: {}", i,
- tab_title, raw_text);
+ tab_title, raw_text.size());
unsaved_pages.push_back({i, tab_title, raw_text});
}
}