aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSaturneric <[email protected]>2022-11-26 17:52:27 +0000
committerSaturneric <[email protected]>2022-11-26 17:52:27 +0000
commitefd722000d7ea6648b11b5627b1c833bdf64b0af (patch)
tree4e540b27671783e722519cf5a84ef767386e86e2
parentfeat: change submodules url (diff)
downloadGpgFrontend-efd722000d7ea6648b11b5627b1c833bdf64b0af.tar.gz
GpgFrontend-efd722000d7ea6648b11b5627b1c833bdf64b0af.zip
feat: support generate ecc key
1. support elliptische kurve nist
-rw-r--r--src/core/GpgGenKeyInfo.cpp94
-rw-r--r--src/core/GpgGenKeyInfo.h12
-rw-r--r--src/core/function/gpg/GpgKeyOpera.cpp4
-rw-r--r--src/core/thread/TaskRunner.cpp9
-rw-r--r--src/main.cpp2
-rw-r--r--src/ui/dialog/key_generate/KeygenDialog.cpp7
-rw-r--r--src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp25
-rw-r--r--src/ui/dialog/keypair_details/KeyPairDetailTab.cpp9
-rw-r--r--src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp15
-rw-r--r--src/ui/dialog/keypair_details/KeyPairUIDTab.cpp7
-rw-r--r--src/ui/widgets/KeyList.cpp7
11 files changed, 132 insertions, 59 deletions
diff --git a/src/core/GpgGenKeyInfo.cpp b/src/core/GpgGenKeyInfo.cpp
index dca5eff7..84c72f10 100644
--- a/src/core/GpgGenKeyInfo.cpp
+++ b/src/core/GpgGenKeyInfo.cpp
@@ -28,38 +28,49 @@
#include "core/GpgGenKeyInfo.h"
+#include <algorithm>
#include <boost/date_time/gregorian/greg_date.hpp>
#include <boost/date_time/gregorian/greg_duration.hpp>
#include <boost/date_time/gregorian/gregorian_types.hpp>
+#include <cassert>
#include <string>
#include <vector>
-void GpgFrontend::GenKeyInfo::SetAlgo(const std::string &m_algo) {
- LOG(INFO) << "set algo" << m_algo;
+void GpgFrontend::GenKeyInfo::SetAlgo(
+ const GpgFrontend::GenKeyInfo::KeyGenAlgo &m_algo) {
+ LOG(INFO) << "set algo name" << m_algo.first;
// Check algo if supported
- std::string algo_args = std::string(m_algo);
+ std::string algo_args = m_algo.second;
boost::algorithm::to_upper(algo_args);
if (standalone_) {
if (!subkey_) {
auto support_algo = GetSupportedKeyAlgoStandalone();
- auto it = std::find(support_algo.begin(), support_algo.end(), algo_args);
+ auto it = std::find_if(
+ support_algo.begin(), support_algo.end(),
+ [=](const KeyGenAlgo &o) { return o.second == algo_args; });
// Algo Not Supported
if (it == support_algo.end()) return;
} else {
auto support_algo = GetSupportedSubkeyAlgoStandalone();
- auto it = std::find(support_algo.begin(), support_algo.end(), algo_args);
+ auto it = std::find_if(
+ support_algo.begin(), support_algo.end(),
+ [=](const KeyGenAlgo &o) { return o.second == algo_args; });
// Algo Not Supported
if (it == support_algo.end()) return;
}
} else {
if (!subkey_) {
auto support_algo = GetSupportedKeyAlgo();
- auto it = std::find(support_algo.begin(), support_algo.end(), algo_args);
+ auto it = std::find_if(
+ support_algo.begin(), support_algo.end(),
+ [=](const KeyGenAlgo &o) { return o.second == algo_args; });
// Algo Not Supported
if (it == support_algo.end()) return;
} else {
auto support_algo = GetSupportedSubkeyAlgo();
- auto it = std::find(support_algo.begin(), support_algo.end(), algo_args);
+ auto it = std::find_if(
+ support_algo.begin(), support_algo.end(),
+ [=](const KeyGenAlgo &o) { return o.second == algo_args; });
// Algo Not Supported
if (it == support_algo.end()) return;
}
@@ -116,21 +127,35 @@ void GpgFrontend::GenKeyInfo::SetAlgo(const std::string &m_algo) {
suggest_max_key_size_ = -1;
suggest_size_addition_step_ = -1;
SetKeyLength(-1);
- } else if (algo_args == "elg") {
- /**
- * GnuPG supports the Elgamal asymmetric encryption algorithm in key lengths
- * ranging from 1024 to 4096 bits.
- */
+ } else if (algo_args == "cv25519") {
SetAllowAuthentication(false);
allow_change_authentication_ = false;
SetAllowSigning(false);
allow_change_signing_ = false;
+ SetAllowCertification(false);
+ allow_change_certification_ = false;
+
suggest_min_key_size_ = 1024;
suggest_max_key_size_ = 4096;
suggest_size_addition_step_ = 1024;
SetKeyLength(2048);
+ } else if (algo_args == "nistp256" || algo_args == "nistp384" ||
+ algo_args == "nistp521") {
+ SetAllowAuthentication(false);
+ allow_change_authentication_ = false;
+
+ SetAllowSigning(false);
+ allow_change_signing_ = false;
+
+ SetAllowCertification(false);
+ allow_change_certification_ = false;
+
+ suggest_min_key_size_ = -1;
+ suggest_max_key_size_ = -1;
+ suggest_size_addition_step_ = -1;
+ SetKeyLength(-1);
}
this->algo_ = algo_args;
}
@@ -194,34 +219,49 @@ void GpgFrontend::GenKeyInfo::SetAllowCertification(
GpgFrontend::GenKeyInfo::GenKeyInfo(bool m_is_sub_key, bool m_standalone)
: standalone_(m_standalone), subkey_(m_is_sub_key) {
- SetAlgo("rsa");
+ assert(GetSupportedKeyAlgo().size() > 0);
+ SetAlgo(GetSupportedKeyAlgo()[0]);
}
-const std::vector<std::string> &GpgFrontend::GenKeyInfo::GetSupportedKeyAlgo() {
- static const std::vector<std::string> support_key_algo = {"RSA", "DSA",
- "ELG"
- "ED25519",
- "CV25519"};
+const std::vector<GpgFrontend::GenKeyInfo::KeyGenAlgo>
+ &GpgFrontend::GenKeyInfo::GetSupportedKeyAlgo() {
+ static const std::vector<GpgFrontend::GenKeyInfo::KeyGenAlgo>
+ support_key_algo = {
+ {"RSA", "RSA"},
+ {"DSA", "DSA"},
+ {"ECDSA", "ED25519"},
+ };
return support_key_algo;
}
-const std::vector<std::string>
+const std::vector<GpgFrontend::GenKeyInfo::KeyGenAlgo>
&GpgFrontend::GenKeyInfo::GetSupportedSubkeyAlgo() {
- static const std::vector<std::string> support_subkey_algo = {
- "RSA", "DSA", "ELG", "ED25519"};
+ static const std::vector<GpgFrontend::GenKeyInfo::KeyGenAlgo>
+ support_subkey_algo = {{"RSA", "RSA"},
+ {"DSA", "DSA"},
+ {"ECDSA", "ED25519"},
+ {"ECDH NIST P-256", "NISTP256"},
+ {"ECDH NIST P-384", "NISTP384"},
+ {"ECDH NIST P-521", "NISTP521"}};
return support_subkey_algo;
}
-const std::vector<std::string>
+const std::vector<GpgFrontend::GenKeyInfo::KeyGenAlgo>
&GpgFrontend::GenKeyInfo::GetSupportedKeyAlgoStandalone() {
- static const std::vector<std::string> support_subkey_algo_standalone = {
- "RSA", "DSA"};
+ static const std::vector<GpgFrontend::GenKeyInfo::KeyGenAlgo>
+ support_subkey_algo_standalone = {
+ {"RSA", "RSA"},
+ {"DSA", "DSA"},
+ };
return support_subkey_algo_standalone;
}
-const std::vector<std::string>
+const std::vector<GpgFrontend::GenKeyInfo::KeyGenAlgo>
&GpgFrontend::GenKeyInfo::GetSupportedSubkeyAlgoStandalone() {
- static const std::vector<std::string> support_subkey_algo_standalone = {
- "RSA", "DSA", "ELG-E"};
+ static const std::vector<GpgFrontend::GenKeyInfo::KeyGenAlgo>
+ support_subkey_algo_standalone = {
+ {"RSA", "RSA"},
+ {"DSA", "DSA"},
+ };
return support_subkey_algo_standalone;
}
diff --git a/src/core/GpgGenKeyInfo.h b/src/core/GpgGenKeyInfo.h
index 73dd9680..d47b803e 100644
--- a/src/core/GpgGenKeyInfo.h
+++ b/src/core/GpgGenKeyInfo.h
@@ -62,34 +62,36 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo {
std::string passphrase_; ///<
+ using KeyGenAlgo = std::pair<std::string, std::string>;
+
public:
/**
* @brief Get the Supported Key Algo object
*
* @return const std::vector<std::string>&
*/
- static const std::vector<std::string> &GetSupportedKeyAlgo();
+ static const std::vector<KeyGenAlgo> &GetSupportedKeyAlgo();
/**
* @brief Get the Supported Subkey Algo object
*
* @return const std::vector<std::string>&
*/
- static const std::vector<std::string> &GetSupportedSubkeyAlgo();
+ static const std::vector<KeyGenAlgo> &GetSupportedSubkeyAlgo();
/**
* @brief Get the Supported Key Algo Standalone object
*
* @return const std::vector<std::string>&
*/
- static const std::vector<std::string> &GetSupportedKeyAlgoStandalone();
+ static const std::vector<KeyGenAlgo> &GetSupportedKeyAlgoStandalone();
/**
* @brief Get the Supported Subkey Algo Standalone object
*
* @return const std::vector<std::string>&
*/
- static const std::vector<std::string> &GetSupportedSubkeyAlgoStandalone();
+ static const std::vector<KeyGenAlgo> &GetSupportedSubkeyAlgoStandalone();
/**
* @brief
@@ -171,7 +173,7 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo {
*
* @param m_algo
*/
- void SetAlgo(const std::string &m_algo);
+ void SetAlgo(const GpgFrontend::GenKeyInfo::KeyGenAlgo &m_algo);
/**
* @brief Get the Key Size Str object
diff --git a/src/core/function/gpg/GpgKeyOpera.cpp b/src/core/function/gpg/GpgKeyOpera.cpp
index 03d8c8d9..0839c132 100644
--- a/src/core/function/gpg/GpgKeyOpera.cpp
+++ b/src/core/function/gpg/GpgKeyOpera.cpp
@@ -245,6 +245,10 @@ GpgFrontend::GpgError GpgFrontend::GpgKeyOpera::GenerateSubkey(
const GpgKey& key, const std::unique_ptr<GenKeyInfo>& params) {
if (!params->IsSubKey()) return GPG_ERR_CANCELED;
+ LOG(INFO) << "generate subkey"
+ << "algo" << params->GetAlgo() << "key size"
+ << params->GetKeySizeStr();
+
auto algo_utf8 = (params->GetAlgo() + params->GetKeySizeStr());
const char* algo = algo_utf8.c_str();
unsigned long expires = 0;
diff --git a/src/core/thread/TaskRunner.cpp b/src/core/thread/TaskRunner.cpp
index 7116ca71..f70b2d4c 100644
--- a/src/core/thread/TaskRunner.cpp
+++ b/src/core/thread/TaskRunner.cpp
@@ -36,19 +36,18 @@ GpgFrontend::Thread::TaskRunner::TaskRunner() = default;
GpgFrontend::Thread::TaskRunner::~TaskRunner() = default;
void GpgFrontend::Thread::TaskRunner::PostTask(Task* task) {
- LOG(TRACE) << "Post Task" << task->GetUUID();
+ std::string uuid = task->GetUUID();
+ LOG(TRACE) << "Post Task" << uuid;
if (task == nullptr) return;
task->setParent(nullptr);
task->moveToThread(this);
- connect(task, &Task::SignalTaskPostFinishedDone, this, [=]() {
- auto it = pending_tasks_.find(task->GetUUID());
+ connect(task, &Task::SignalTaskPostFinishedDone, this, [&, uuid]() {
+ auto it = pending_tasks_.find(uuid);
if (it == pending_tasks_.end()) {
- LOG(ERROR) << "Task" << task->GetUUID() << "not found in pending tasks";
return;
} else {
- LOG(TRACE) << "Task" << task->GetUUID() << "found in pending tasks";
it->second->deleteLater();
pending_tasks_.erase(it);
}
diff --git a/src/main.cpp b/src/main.cpp
index 4cb3849f..14563880 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -80,10 +80,12 @@ extern void init_logging_system();
* @return
*/
int main(int argc, char* argv[]) {
+#ifdef RELEASE
// re
signal(SIGSEGV, handle_signal);
signal(SIGFPE, handle_signal);
signal(SIGILL, handle_signal);
+#endif
// clean something before exit
atexit(before_exit);
diff --git a/src/ui/dialog/key_generate/KeygenDialog.cpp b/src/ui/dialog/key_generate/KeygenDialog.cpp
index 42160ec9..b7ba6369 100644
--- a/src/ui/dialog/key_generate/KeygenDialog.cpp
+++ b/src/ui/dialog/key_generate/KeygenDialog.cpp
@@ -254,8 +254,9 @@ void KeyGenDialog::slot_authentication_box_changed(int state) {
void KeyGenDialog::slot_activated_key_type(int index) {
qDebug() << "key type index changed " << index;
- gen_key_info_->SetAlgo(
- this->key_type_combo_box_->itemText(index).toStdString());
+ // check
+ assert(gen_key_info_->GetSupportedKeyAlgo().size() > index);
+ gen_key_info_->SetAlgo(gen_key_info_->GetSupportedKeyAlgo()[index]);
refresh_widgets_state();
}
@@ -357,7 +358,7 @@ QGroupBox* KeyGenDialog::create_basic_info_group_box() {
key_type_combo_box_ = new QComboBox(this);
for (auto& algo : GenKeyInfo::GetSupportedKeyAlgo()) {
- key_type_combo_box_->addItem(QString::fromStdString(algo));
+ key_type_combo_box_->addItem(QString::fromStdString(algo.first));
}
if (!GenKeyInfo::GetSupportedKeyAlgo().empty()) {
key_type_combo_box_->setCurrentIndex(0);
diff --git a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp
index 806c0e50..afa768f0 100644
--- a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp
+++ b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp
@@ -26,6 +26,8 @@
#include "SubkeyGenerateDialog.h"
+#include <cassert>
+
#include "core/function/GlobalSettingStation.h"
#include "core/function/gpg/GpgKeyGetter.h"
#include "core/function/gpg/GpgKeyOpera.h"
@@ -120,10 +122,10 @@ QGroupBox* SubkeyGenerateDialog::create_basic_info_group_box() {
key_size_spin_box_ = new QSpinBox(this);
key_type_combo_box_ = new QComboBox(this);
- for (auto& algo : GenKeyInfo::GetSupportedKeyAlgo()) {
- key_type_combo_box_->addItem(QString::fromStdString(algo));
+ for (auto& algo : GenKeyInfo::GetSupportedSubkeyAlgo()) {
+ key_type_combo_box_->addItem(QString::fromStdString(algo.first));
}
- if (!GenKeyInfo::GetSupportedKeyAlgo().empty()) {
+ if (!GenKeyInfo::GetSupportedSubkeyAlgo().empty()) {
key_type_combo_box_->setCurrentIndex(0);
}
@@ -188,7 +190,7 @@ void SubkeyGenerateDialog::slot_expire_box_changed() {
}
void SubkeyGenerateDialog::refresh_widgets_state() {
- qDebug() << "refresh_widgets_state called";
+ LOG(INFO) << "refresh_widgets_state called";
if (gen_key_info_->IsAllowEncryption())
key_usage_check_boxes_[0]->setCheckState(Qt::CheckState::Checked);
@@ -266,13 +268,13 @@ void SubkeyGenerateDialog::slot_key_gen_accept() {
});
thread->start();
- auto* dialog = new WaitingDialog(_("Generating"), this);
- dialog->show();
+ auto* waiting_dialog = new WaitingDialog(_("Generating"), this);
+ waiting_dialog->show();
while (thread->isRunning()) {
QCoreApplication::processEvents();
}
- dialog->close();
+ waiting_dialog->close();
if (check_gpg_error_2_err_code(error) == GPG_ERR_NO_ERROR) {
auto* msg_box = new QMessageBox((QWidget*)this->parent());
@@ -285,8 +287,9 @@ void SubkeyGenerateDialog::slot_key_gen_accept() {
emit SignalSubKeyGenerated();
this->close();
- } else
+ } else {
QMessageBox::critical(this, _("Failure"), _("Failed to generate key."));
+ }
} else {
/**
@@ -336,8 +339,10 @@ void SubkeyGenerateDialog::slot_authentication_box_changed(int state) {
void SubkeyGenerateDialog::slot_activated_key_type(int index) {
qDebug() << "key type index changed " << index;
- gen_key_info_->SetAlgo(
- this->key_type_combo_box_->itemText(index).toStdString());
+
+ // check
+ assert(gen_key_info_->GetSupportedSubkeyAlgo().size() > index);
+ gen_key_info_->SetAlgo(gen_key_info_->GetSupportedSubkeyAlgo()[index]);
refresh_widgets_state();
}
diff --git a/src/ui/dialog/keypair_details/KeyPairDetailTab.cpp b/src/ui/dialog/keypair_details/KeyPairDetailTab.cpp
index 4a6e4b52..b4d2d688 100644
--- a/src/ui/dialog/keypair_details/KeyPairDetailTab.cpp
+++ b/src/ui/dialog/keypair_details/KeyPairDetailTab.cpp
@@ -28,6 +28,7 @@
#include "core/function/gpg/GpgKeyGetter.h"
#include "core/function/gpg/GpgKeyImportExporter.h"
+#include "core/model/GpgKey.h"
#include "dialog/WaitingDialog.h"
#include "ui/SignalStation.h"
@@ -268,8 +269,12 @@ void KeyPairDetailTab::slot_refresh_key_info() {
}
void KeyPairDetailTab::slot_refresh_key() {
- LOG(INFO) << _("Called");
- this->key_ = GpgKeyGetter::GetInstance().GetKey(key_.GetId());
+ LOG(INFO) << _("called");
+
+ // refresh the key
+ GpgKey refreshed_key = GpgKeyGetter::GetInstance().GetKey(key_.GetId());
+ std::swap(this->key_, refreshed_key);
+
this->slot_refresh_key_info();
}
diff --git a/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp b/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp
index fe1d0798..be67e5ca 100644
--- a/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp
+++ b/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp
@@ -165,7 +165,7 @@ void KeyPairSubkeyTab::create_subkey_list() {
}
void KeyPairSubkeyTab::slot_refresh_subkey_list() {
- LOG(INFO) << "Called";
+ LOG(INFO) << "called";
int row = 0;
subkey_list_->setSelectionMode(QAbstractItemView::SingleSelection);
@@ -177,6 +177,10 @@ void KeyPairSubkeyTab::slot_refresh_subkey_list() {
this->buffered_subkeys_.push_back(std::move(sub_key));
}
+ LOG(INFO) << "buffered_subkeys_"
+ << "refreshed"
+ << "size" << this->buffered_subkeys_.size();
+
subkey_list_->setRowCount(buffered_subkeys_.size());
for (const auto& subkeys : buffered_subkeys_) {
@@ -212,12 +216,20 @@ void KeyPairSubkeyTab::slot_refresh_subkey_list() {
}
}
+ LOG(INFO) << "subkey_list_ item" << row << "refreshed";
+
row++;
}
+ LOG(INFO) << "subkey_list_"
+ << "refreshed";
+
if (subkey_list_->rowCount() > 0) {
subkey_list_->selectRow(0);
}
+
+ LOG(INFO) << "slot_refresh_subkey_list"
+ << "ended";
}
void KeyPairSubkeyTab::slot_add_subkey() {
@@ -332,6 +344,7 @@ const GpgSubKey& KeyPairSubkeyTab::get_selected_subkey() {
return buffered_subkeys_[row];
}
void KeyPairSubkeyTab::slot_refresh_key_info() {
+ LOG(INFO) << "called";
key_ = GpgKeyGetter::GetInstance().GetKey(key_.GetId());
}
diff --git a/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp b/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp
index b923dbec..caa4e3be 100644
--- a/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp
+++ b/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp
@@ -574,7 +574,12 @@ void KeyPairUIDTab::slot_del_sign() {
}
}
void KeyPairUIDTab::slot_refresh_key() {
- this->m_key_ = GpgKeyGetter::GetInstance().GetKey(this->m_key_.GetId());
+ LOG(INFO) << "called";
+
+ // refresh the key
+ GpgKey refreshed_key = GpgKeyGetter::GetInstance().GetKey(m_key_.GetId());
+ std::swap(this->m_key_, refreshed_key);
+
this->slot_refresh_uid_list();
this->slot_refresh_tofu_info();
this->slot_refresh_sig_list();
diff --git a/src/ui/widgets/KeyList.cpp b/src/ui/widgets/KeyList.cpp
index 44559b8e..9150d580 100644
--- a/src/ui/widgets/KeyList.cpp
+++ b/src/ui/widgets/KeyList.cpp
@@ -158,7 +158,7 @@ void KeyList::AddListGroupTab(
}
void KeyList::SlotRefresh() {
- LOG(INFO) << _("Called") << "address" << this;
+ LOG(INFO) << _("called") << "address" << this;
ui_->refreshKeyListButton->setDisabled(true);
ui_->syncButton->setDisabled(true);
@@ -379,9 +379,7 @@ void KeyList::dragEnterEvent(QDragEnterEvent* event) {
*
*/
[[maybe_unused]] void KeyList::MarkKeys(QStringList* keyIds) {
- foreach (QString id, *keyIds) {
- qDebug() << "marked: " << id;
- }
+ foreach (QString id, *keyIds) { qDebug() << "marked: " << id; }
}
void KeyList::import_keys(const QByteArray& inBuffer) {
@@ -520,7 +518,6 @@ void KeyTable::SetChecked(KeyIdArgsListPtr key_ids) {
}
void KeyTable::Refresh(KeyLinkListPtr m_keys) {
-
auto& checked_key_list = GetChecked();
// while filling the table, sort enabled causes errors