diff options
71 files changed, 825 insertions, 424 deletions
diff --git a/src/GpgFrontendContext.h b/src/GpgFrontendContext.h index 507ee051..af29af73 100644 --- a/src/GpgFrontendContext.h +++ b/src/GpgFrontendContext.h @@ -38,8 +38,8 @@ namespace GpgFrontend { struct GpgFrontendContext; -using GFCxtWPtr = std::weak_ptr<GpgFrontendContext>; -using GFCxtSPtr = std::shared_ptr<GpgFrontendContext>; +using GFCxtWPtr = QWeakPointer<GpgFrontendContext>; +using GFCxtSPtr = QSharedPointer<GpgFrontendContext>; struct GpgFrontendContext { int argc; diff --git a/src/core/function/gpg/GpgAbstractKeyGetter.cpp b/src/core/function/gpg/GpgAbstractKeyGetter.cpp index 193fec0e..581d027e 100644 --- a/src/core/function/gpg/GpgAbstractKeyGetter.cpp +++ b/src/core/function/gpg/GpgAbstractKeyGetter.cpp @@ -54,7 +54,7 @@ auto GpgAbstractKeyGetter::Fetch() -> GpgAbstractKeyPtrList { auto GpgAbstractKeyGetter::GetGpgKeyTableModel() -> QSharedPointer<GpgKeyTableModel> { - return SecureCreateQSharedObject<GpgKeyTableModel>( + return SecureCreateSharedObject<GpgKeyTableModel>( SingletonFunctionObject::GetChannel(), Fetch(), nullptr); } diff --git a/src/core/function/gpg/GpgAutomatonHandler.cpp b/src/core/function/gpg/GpgAutomatonHandler.cpp index 33c94436..6cf06ab6 100644 --- a/src/core/function/gpg/GpgAutomatonHandler.cpp +++ b/src/core/function/gpg/GpgAutomatonHandler.cpp @@ -28,6 +28,8 @@ #include "GpgAutomatonHandler.h" +#include <utility> + #include "core/model/GpgData.h" #include "core/model/GpgKey.h" #include "core/utils/GpgUtils.h" @@ -37,9 +39,8 @@ namespace GpgFrontend { GpgAutomatonHandler::GpgAutomatonHandler(int channel) : SingletonFunctionObject<GpgAutomatonHandler>(channel) {} -auto GpgAutomatonHandler::interator_cb_func(void* handle, const char* status, - const char* args, - int fd) -> gpgme_error_t { +auto InteratorCbFunc(void* handle, const char* status, const char* args, + int fd) -> gpgme_error_t { auto* handle_struct = static_cast<AutomatonHandelStruct*>(handle); QString status_s = status; QString args_s = args; @@ -47,8 +48,26 @@ auto GpgAutomatonHandler::interator_cb_func(void* handle, const char* status, if (status_s == "KEY_CONSIDERED") { auto tokens = QString(args).split(' '); + if (handle_struct->KeyFpr().isEmpty()) return 0; + if (tokens.empty() || tokens[0] != handle_struct->KeyFpr()) { - LOG_W() << "handle struct key fpr " << handle_struct->KeyFpr() + LOG_W() << "handle struct key fpr: " << handle_struct->KeyFpr() + << "mismatch token: " << tokens[0] << ", exit..."; + + return -1; + } + + return 0; + } + + if (status_s == "CARDCTRL") { + auto tokens = QString(args).split(' '); + + if (handle_struct->SerialNumber().isEmpty()) return 0; + + if (tokens.empty() || tokens[0] != handle_struct->SerialNumber()) { + LOG_W() << "handle struct serial number: " + << handle_struct->SerialNumber() << "mismatch token: " << tokens[0] << ", exit..."; return -1; @@ -65,20 +84,22 @@ auto GpgAutomatonHandler::interator_cb_func(void* handle, const char* status, LOG_D() << "current state" << handle_struct->CurrentStatus() << "gpg status: " << status_s << ", args: " << args_s; + handle_struct->SetPromptStatus(status_s, args_s); + AutomatonState next_state = handle_struct->NextState(status_s, args_s); - if (next_state == AS_ERROR) { + if (next_state == GpgAutomatonHandler::kAS_ERROR) { FLOG_D("handle struct next state caught error, abort..."); return -1; } LOG_D() << "next state" << next_state; - if (next_state == AS_SAVE) { + if (next_state == GpgAutomatonHandler::kAS_SAVE) { handle_struct->SetSuccess(true); } // set state and preform action handle_struct->SetStatus(next_state); - Command cmd = handle_struct->Action(); + GpgAutomatonHandler::Command cmd = handle_struct->Action(); LOG_D() << "next action, cmd:" << cmd; @@ -86,7 +107,7 @@ auto GpgAutomatonHandler::interator_cb_func(void* handle, const char* status, auto btye_array = cmd.toUtf8(); gpgme_io_write(fd, btye_array, btye_array.size()); gpgme_io_write(fd, "\n", 1); - } else if (status_s == "GET_LINE") { + } else if (status_s.startsWith("GET_")) { // avoid trapping in this state return GPG_ERR_FALSE; } @@ -94,30 +115,40 @@ auto GpgAutomatonHandler::interator_cb_func(void* handle, const char* status, return 0; } -auto GpgAutomatonHandler::DoInteract( - const GpgKeyPtr& key, AutomatonNextStateHandler next_state_handler, - AutomatonActionHandler action_handler, int flags) -> bool { - gpgme_key_t p_key = - flags == GPGME_INTERACT_CARD ? nullptr : static_cast<gpgme_key_t>(*key); +auto DoInteractImpl(GpgContext& ctx_, const GpgKeyPtr& key, bool card_edit, + const QString& id, + AutomatonNextStateHandler next_state_handler, + AutomatonActionHandler action_handler, int flags) -> bool { + gpgme_key_t p_key = key == nullptr ? nullptr : static_cast<gpgme_key_t>(*key); - AutomatonHandelStruct handel_struct( - flags == GPGME_INTERACT_CARD ? "" : key->Fingerprint()); + AutomatonHandelStruct handel_struct(card_edit, id); handel_struct.SetHandler(std::move(next_state_handler), std::move(action_handler)); GpgData data_out; - auto err = gpgme_op_interact(ctx_.DefaultContext(), p_key, flags, - GpgAutomatonHandler::interator_cb_func, - static_cast<void*>(&handel_struct), data_out); + auto err = + gpgme_op_interact(ctx_.DefaultContext(), p_key, flags, InteratorCbFunc, + static_cast<void*>(&handel_struct), data_out); return CheckGpgError(err) == GPG_ERR_NO_ERROR && handel_struct.Success(); } +auto GpgAutomatonHandler::DoInteract( + const GpgKeyPtr& key, AutomatonNextStateHandler next_state_handler, + AutomatonActionHandler action_handler, int flags) -> bool { + assert(key != nullptr); + if (key == nullptr) return false; + return DoInteractImpl(ctx_, key, false, key->ID(), + std::move(next_state_handler), + std::move(action_handler), flags); +} + auto GpgAutomatonHandler::DoCardInteract( - AutomatonNextStateHandler next_state_handler, + const QString& serial_number, AutomatonNextStateHandler next_state_handler, AutomatonActionHandler action_handler) -> bool { - return DoInteract({}, std::move(next_state_handler), - std::move(action_handler), GPGME_INTERACT_CARD); + return DoInteractImpl(ctx_, nullptr, true, serial_number, + std::move(next_state_handler), + std::move(action_handler), GPGME_INTERACT_CARD); } auto GpgAutomatonHandler::AutomatonHandelStruct::NextState( @@ -133,7 +164,7 @@ void GpgAutomatonHandler::AutomatonHandelStruct::SetHandler( action_handler_ = std::move(action_handler); } -auto GpgAutomatonHandler::AutomatonHandelStruct::CurrentStatus() +auto GpgAutomatonHandler::AutomatonHandelStruct::CurrentStatus() const -> AutomatonState { return current_state_; } @@ -154,11 +185,27 @@ void GpgAutomatonHandler::AutomatonHandelStruct::SetSuccess(bool success) { auto GpgAutomatonHandler::AutomatonHandelStruct::Success() const -> bool { return success_; } -auto GpgAutomatonHandler::AutomatonHandelStruct::KeyFpr() -> QString { - return key_fpr_; +auto GpgAutomatonHandler::AutomatonHandelStruct::KeyFpr() const -> QString { + return card_edit_ ? "" : id_; } GpgAutomatonHandler::AutomatonHandelStruct::AutomatonHandelStruct( - QString key_fpr) - : key_fpr_(std::move(key_fpr)) {} + bool card_edit, QString id) + : card_edit_(card_edit), id_(std::move(id)) {} + +auto GpgAutomatonHandler::AutomatonHandelStruct::PromptStatus() const + -> std::tuple<QString, QString> { + return {prompt_status_, prompt_args_}; +} + +void GpgAutomatonHandler::AutomatonHandelStruct::SetPromptStatus(QString status, + QString args) { + prompt_status_ = std::move(status); + prompt_args_ = std::move(args); +} + +auto GpgAutomatonHandler::AutomatonHandelStruct::SerialNumber() const + -> QString { + return card_edit_ ? id_ : ""; +} } // namespace GpgFrontend
\ No newline at end of file diff --git a/src/core/function/gpg/GpgAutomatonHandler.h b/src/core/function/gpg/GpgAutomatonHandler.h index cdf96060..d142bbcc 100644 --- a/src/core/function/gpg/GpgAutomatonHandler.h +++ b/src/core/function/gpg/GpgAutomatonHandler.h @@ -28,6 +28,8 @@ #pragma once +#include <utility> + #include "core/GpgFrontendCore.h" #include "core/function/basic/GpgFunctionObject.h" #include "core/function/gpg/GpgContext.h" @@ -40,16 +42,18 @@ class GpgAutomatonHandler public: using Command = QString; using AutomatonState = enum { - AS_START, - AS_SELECT, - AS_COMMAND, - AS_VALUE, - AS_REASON_CODE, - AS_REASON_TEXT, - AS_REALLY_ULTIMATE, - AS_SAVE, - AS_ERROR, - AS_QUIT, + kAS_START, + kAS_SELECT, + kAS_COMMAND, + kAS_VALUE, + kAS_ADMIN, + kAS_REASON_CODE, + kAS_REASON_TEXT, + kAS_REALLY_ULTIMATE, + kAS_SAVE, + kAS_INFO, + kAS_ERROR, + kAS_QUIT, }; struct AutomatonHandelStruct; @@ -60,23 +64,32 @@ class GpgAutomatonHandler std::function<AutomatonState(AutomatonState, QString, QString)>; struct AutomatonHandelStruct { - explicit AutomatonHandelStruct(QString key_fpr); - void SetStatus(AutomatonState next_state); - auto CurrentStatus() -> AutomatonState; - void SetHandler(AutomatonNextStateHandler next_state_handler, - AutomatonActionHandler action_handler); + explicit AutomatonHandelStruct(bool card_edit, QString id); + auto NextState(QString gpg_status, QString args) -> AutomatonState; auto Action() -> Command; + + void SetStatus(AutomatonState next_state); void SetSuccess(bool success); + void SetPromptStatus(QString status, QString args); + void SetHandler(AutomatonNextStateHandler next_state_handler, + AutomatonActionHandler action_handler); + + [[nodiscard]] auto CurrentStatus() const -> AutomatonState; [[nodiscard]] auto Success() const -> bool; - auto KeyFpr() -> QString; + [[nodiscard]] auto KeyFpr() const -> QString; + [[nodiscard]] auto SerialNumber() const -> QString; + [[nodiscard]] auto PromptStatus() const -> std::tuple<QString, QString>; private: - AutomatonState current_state_ = AS_START; + AutomatonState current_state_ = kAS_START; AutomatonNextStateHandler next_state_handler_; AutomatonActionHandler action_handler_; bool success_ = false; - QString key_fpr_; + bool card_edit_; + QString id_; + QString prompt_status_; + QString prompt_args_; }; /** @@ -109,24 +122,13 @@ class GpgAutomatonHandler * @return true * @return false */ - auto DoCardInteract(AutomatonNextStateHandler next_state_handler, + auto DoCardInteract(const QString& serial_number, + AutomatonNextStateHandler next_state_handler, AutomatonActionHandler action_handler) -> bool; private: GpgContext& ctx_ = GpgContext::GetInstance(SingletonFunctionObject::GetChannel()); ///< - - /** - * @brief - * - * @param handle - * @param status - * @param args - * @param fd - * @return gpgme_error_t - */ - static auto interator_cb_func(void* handle, const char* status, - const char* args, int fd) -> gpgme_error_t; }; using AutomatonNextStateHandler = diff --git a/src/core/function/gpg/GpgKeyImportExporter.cpp b/src/core/function/gpg/GpgKeyImportExporter.cpp index f42c84ce..eda36273 100644 --- a/src/core/function/gpg/GpgKeyImportExporter.cpp +++ b/src/core/function/gpg/GpgKeyImportExporter.cpp @@ -45,7 +45,7 @@ GpgKeyImportExporter::GpgKeyImportExporter(int channel) * @return Import information */ auto GpgKeyImportExporter::ImportKey(const GFBuffer& in_buffer) - -> std::shared_ptr<GpgImportInformation> { + -> QSharedPointer<GpgImportInformation> { if (in_buffer.Empty()) return {}; GpgData data_in(in_buffer); @@ -55,7 +55,8 @@ auto GpgKeyImportExporter::ImportKey(const GFBuffer& in_buffer) gpgme_import_result_t result; result = gpgme_op_import_result(ctx_.BinaryContext()); gpgme_import_status_t status = result->imports; - auto import_info = SecureCreateSharedObject<GpgImportInformation>(result); + + auto import_info = QSharedPointer<GpgImportInformation>::create(result); while (status != nullptr) { GpgImportInformation::GpgImportedKey key; key.import_status = static_cast<int>(status->status); diff --git a/src/core/function/gpg/GpgKeyImportExporter.h b/src/core/function/gpg/GpgKeyImportExporter.h index 4f938cb7..dcadec36 100644 --- a/src/core/function/gpg/GpgKeyImportExporter.h +++ b/src/core/function/gpg/GpgKeyImportExporter.h @@ -58,7 +58,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyImportExporter * @param inBuffer * @return GpgImportInformation */ - auto ImportKey(const GFBuffer&) -> std::shared_ptr<GpgImportInformation>; + auto ImportKey(const GFBuffer&) -> QSharedPointer<GpgImportInformation>; /** * @brief diff --git a/src/core/function/gpg/GpgKeyManager.cpp b/src/core/function/gpg/GpgKeyManager.cpp index 9f43d03d..1fa050bb 100644 --- a/src/core/function/gpg/GpgKeyManager.cpp +++ b/src/core/function/gpg/GpgKeyManager.cpp @@ -106,62 +106,62 @@ auto GpgKeyManager::SetOwnerTrustLevel(const GpgKeyPtr& key, auto tokens = args.split(' '); switch (state) { - case GpgAutomatonHandler::AS_START: + case GpgAutomatonHandler::kAS_START: if (status == "GET_LINE" && args == "keyedit.prompt") { - return GpgAutomatonHandler::AS_COMMAND; + return GpgAutomatonHandler::kAS_COMMAND; } - return GpgAutomatonHandler::AS_ERROR; - case GpgAutomatonHandler::AS_COMMAND: + return GpgAutomatonHandler::kAS_ERROR; + case GpgAutomatonHandler::kAS_COMMAND: if (status == "GET_LINE" && args == "edit_ownertrust.value") { - return GpgAutomatonHandler::AS_VALUE; + return GpgAutomatonHandler::kAS_VALUE; } - return GpgAutomatonHandler::AS_ERROR; - case GpgAutomatonHandler::AS_VALUE: + return GpgAutomatonHandler::kAS_ERROR; + case GpgAutomatonHandler::kAS_VALUE: if (status == "GET_LINE" && args == "keyedit.prompt") { - return GpgAutomatonHandler::AS_QUIT; + return GpgAutomatonHandler::kAS_QUIT; } else if (status == "GET_BOOL" && args == "edit_ownertrust.set_ultimate.okay") { - return GpgAutomatonHandler::AS_REALLY_ULTIMATE; + return GpgAutomatonHandler::kAS_REALLY_ULTIMATE; } - return GpgAutomatonHandler::AS_ERROR; - case GpgAutomatonHandler::AS_REALLY_ULTIMATE: + return GpgAutomatonHandler::kAS_ERROR; + case GpgAutomatonHandler::kAS_REALLY_ULTIMATE: if (status == "GET_LINE" && args == "keyedit.prompt") { - return GpgAutomatonHandler::AS_QUIT; + return GpgAutomatonHandler::kAS_QUIT; } - return GpgAutomatonHandler::AS_ERROR; - case GpgAutomatonHandler::AS_QUIT: + return GpgAutomatonHandler::kAS_ERROR; + case GpgAutomatonHandler::kAS_QUIT: if (status == "GET_BOOL" && args == "keyedit.save.okay") { - return GpgAutomatonHandler::AS_SAVE; + return GpgAutomatonHandler::kAS_SAVE; } - return GpgAutomatonHandler::AS_ERROR; - case GpgAutomatonHandler::AS_ERROR: + return GpgAutomatonHandler::kAS_ERROR; + case GpgAutomatonHandler::kAS_ERROR: if (status == "GET_LINE" && args == "keyedit.prompt") { - return GpgAutomatonHandler::AS_QUIT; + return GpgAutomatonHandler::kAS_QUIT; } - return GpgAutomatonHandler::AS_ERROR; + return GpgAutomatonHandler::kAS_ERROR; default: - return GpgAutomatonHandler::AS_ERROR; + return GpgAutomatonHandler::kAS_ERROR; }; }; AutomatonActionHandler action_handler = [trust_level](AutomatonHandelStruct& handler, AutomatonState state) { switch (state) { - case GpgAutomatonHandler::AS_COMMAND: + case GpgAutomatonHandler::kAS_COMMAND: return QString("trust"); - case GpgAutomatonHandler::AS_VALUE: + case GpgAutomatonHandler::kAS_VALUE: handler.SetSuccess(true); return QString::number(trust_level); - case GpgAutomatonHandler::AS_REALLY_ULTIMATE: + case GpgAutomatonHandler::kAS_REALLY_ULTIMATE: handler.SetSuccess(true); return QString("Y"); - case GpgAutomatonHandler::AS_QUIT: + case GpgAutomatonHandler::kAS_QUIT: return QString("quit"); - case GpgAutomatonHandler::AS_SAVE: + case GpgAutomatonHandler::kAS_SAVE: handler.SetSuccess(true); return QString("Y"); - case GpgAutomatonHandler::AS_START: - case GpgAutomatonHandler::AS_ERROR: + case GpgAutomatonHandler::kAS_START: + case GpgAutomatonHandler::kAS_ERROR: return QString(""); default: return QString(""); @@ -186,74 +186,67 @@ auto GpgKeyManager::DeleteSubkey(const GpgKeyPtr& key, auto tokens = args.split(' '); switch (state) { - case GpgAutomatonHandler::AS_START: + case GpgAutomatonHandler::kAS_START: if (status == "GET_LINE" && args == "keyedit.prompt") { - return GpgAutomatonHandler::AS_SELECT; + return GpgAutomatonHandler::kAS_SELECT; } - return GpgAutomatonHandler::AS_ERROR; - case GpgAutomatonHandler::AS_SELECT: + return GpgAutomatonHandler::kAS_ERROR; + case GpgAutomatonHandler::kAS_SELECT: if (status == "GET_LINE" && args == "keyedit.prompt") { - return GpgAutomatonHandler::AS_COMMAND; + return GpgAutomatonHandler::kAS_COMMAND; } - return GpgAutomatonHandler::AS_ERROR; - case GpgAutomatonHandler::AS_COMMAND: + return GpgAutomatonHandler::kAS_ERROR; + case GpgAutomatonHandler::kAS_COMMAND: if (status == "GET_LINE" && args == "keyedit.prompt") { - return GpgAutomatonHandler::AS_QUIT; + return GpgAutomatonHandler::kAS_QUIT; } else if (status == "GET_BOOL" && args == "keyedit.remove.subkey.okay") { - return GpgAutomatonHandler::AS_REALLY_ULTIMATE; + return GpgAutomatonHandler::kAS_REALLY_ULTIMATE; } - return GpgAutomatonHandler::AS_ERROR; - case GpgAutomatonHandler::AS_REALLY_ULTIMATE: + return GpgAutomatonHandler::kAS_ERROR; + case GpgAutomatonHandler::kAS_REALLY_ULTIMATE: if (status == "GET_LINE" && args == "keyedit.prompt") { - return GpgAutomatonHandler::AS_QUIT; + return GpgAutomatonHandler::kAS_QUIT; } - return GpgAutomatonHandler::AS_ERROR; - case GpgAutomatonHandler::AS_QUIT: + return GpgAutomatonHandler::kAS_ERROR; + case GpgAutomatonHandler::kAS_QUIT: if (status == "GET_BOOL" && args == "keyedit.save.okay") { - return GpgAutomatonHandler::AS_SAVE; + return GpgAutomatonHandler::kAS_SAVE; } - return GpgAutomatonHandler::AS_ERROR; - case GpgAutomatonHandler::AS_ERROR: + return GpgAutomatonHandler::kAS_ERROR; + case GpgAutomatonHandler::kAS_ERROR: if (status == "GET_LINE" && args == "keyedit.prompt") { - return GpgAutomatonHandler::AS_QUIT; + return GpgAutomatonHandler::kAS_QUIT; } - return GpgAutomatonHandler::AS_ERROR; + return GpgAutomatonHandler::kAS_ERROR; default: - return GpgAutomatonHandler::AS_ERROR; + return GpgAutomatonHandler::kAS_ERROR; }; }; AutomatonActionHandler action_handler = [subkey_index](AutomatonHandelStruct& handler, AutomatonState state) { switch (state) { - case GpgAutomatonHandler::AS_SELECT: + case GpgAutomatonHandler::kAS_SELECT: return QString("key %1").arg(subkey_index); - case GpgAutomatonHandler::AS_COMMAND: + case GpgAutomatonHandler::kAS_COMMAND: return QString("delkey"); - case GpgAutomatonHandler::AS_REALLY_ULTIMATE: + case GpgAutomatonHandler::kAS_REALLY_ULTIMATE: handler.SetSuccess(true); return QString("Y"); - case GpgAutomatonHandler::AS_QUIT: + case GpgAutomatonHandler::kAS_QUIT: return QString("quit"); - case GpgAutomatonHandler::AS_SAVE: + case GpgAutomatonHandler::kAS_SAVE: handler.SetSuccess(true); return QString("Y"); - case GpgAutomatonHandler::AS_START: - case GpgAutomatonHandler::AS_ERROR: - return QString(""); + case GpgAutomatonHandler::kAS_START: + case GpgAutomatonHandler::kAS_ERROR: default: return QString(""); } return QString(""); }; - auto key_fpr = key->Fingerprint(); - AutomatonHandelStruct handel_struct(key_fpr); - handel_struct.SetHandler(next_state_handler, action_handler); - - GpgData data_out; - return GpgAutomatonHandler::GetInstance(GetChannel()) .DoInteract(key, next_state_handler, action_handler); } @@ -281,63 +274,63 @@ auto GpgKeyManager::RevokeSubkey(const GpgKeyPtr& key, int subkey_index, auto tokens = args.split(' '); switch (state) { - case GpgAutomatonHandler::AS_START: + case GpgAutomatonHandler::kAS_START: if (status == "GET_LINE" && args == "keyedit.prompt") { - return GpgAutomatonHandler::AS_SELECT; + return GpgAutomatonHandler::kAS_SELECT; } - return GpgAutomatonHandler::AS_ERROR; - case GpgAutomatonHandler::AS_SELECT: + return GpgAutomatonHandler::kAS_ERROR; + case GpgAutomatonHandler::kAS_SELECT: if (status == "GET_LINE" && args == "keyedit.prompt") { - return GpgAutomatonHandler::AS_COMMAND; + return GpgAutomatonHandler::kAS_COMMAND; } - return GpgAutomatonHandler::AS_ERROR; - case GpgAutomatonHandler::AS_COMMAND: + return GpgAutomatonHandler::kAS_ERROR; + case GpgAutomatonHandler::kAS_COMMAND: if (status == "GET_LINE" && args == "keyedit.prompt") { - return GpgAutomatonHandler::AS_QUIT; + return GpgAutomatonHandler::kAS_QUIT; } else if (status == "GET_BOOL" && args == "keyedit.revoke.subkey.okay") { - return GpgAutomatonHandler::AS_REALLY_ULTIMATE; + return GpgAutomatonHandler::kAS_REALLY_ULTIMATE; } - return GpgAutomatonHandler::AS_ERROR; - case GpgAutomatonHandler::AS_REASON_CODE: + return GpgAutomatonHandler::kAS_ERROR; + case GpgAutomatonHandler::kAS_REASON_CODE: if (status == "GET_LINE" && args == "keyedit.prompt") { - return GpgAutomatonHandler::AS_QUIT; + return GpgAutomatonHandler::kAS_QUIT; } else if (status == "GET_LINE" && args == "ask_revocation_reason.text") { - return GpgAutomatonHandler::AS_REASON_TEXT; + return GpgAutomatonHandler::kAS_REASON_TEXT; } - return GpgAutomatonHandler::AS_ERROR; - case GpgAutomatonHandler::AS_REASON_TEXT: + return GpgAutomatonHandler::kAS_ERROR; + case GpgAutomatonHandler::kAS_REASON_TEXT: if (status == "GET_LINE" && args == "keyedit.prompt") { - return GpgAutomatonHandler::AS_QUIT; + return GpgAutomatonHandler::kAS_QUIT; } else if (status == "GET_LINE" && args == "ask_revocation_reason.text") { - return GpgAutomatonHandler::AS_REASON_TEXT; + return GpgAutomatonHandler::kAS_REASON_TEXT; } else if (status == "GET_BOOL" && args == "ask_revocation_reason.okay") { - return GpgAutomatonHandler::AS_REALLY_ULTIMATE; + return GpgAutomatonHandler::kAS_REALLY_ULTIMATE; } - return GpgAutomatonHandler::AS_ERROR; - case GpgAutomatonHandler::AS_REALLY_ULTIMATE: + return GpgAutomatonHandler::kAS_ERROR; + case GpgAutomatonHandler::kAS_REALLY_ULTIMATE: if (status == "GET_LINE" && args == "keyedit.prompt") { - return GpgAutomatonHandler::AS_QUIT; + return GpgAutomatonHandler::kAS_QUIT; } else if (status == "GET_LINE" && args == "ask_revocation_reason.code") { - return GpgAutomatonHandler::AS_REASON_CODE; + return GpgAutomatonHandler::kAS_REASON_CODE; } - return GpgAutomatonHandler::AS_ERROR; - case GpgAutomatonHandler::AS_QUIT: + return GpgAutomatonHandler::kAS_ERROR; + case GpgAutomatonHandler::kAS_QUIT: if (status == "GET_BOOL" && args == "keyedit.save.okay") { - return GpgAutomatonHandler::AS_SAVE; + return GpgAutomatonHandler::kAS_SAVE; } - return GpgAutomatonHandler::AS_ERROR; - case GpgAutomatonHandler::AS_ERROR: + return GpgAutomatonHandler::kAS_ERROR; + case GpgAutomatonHandler::kAS_ERROR: if (status == "GET_LINE" && args == "keyedit.prompt") { - return GpgAutomatonHandler::AS_QUIT; + return GpgAutomatonHandler::kAS_QUIT; } - return GpgAutomatonHandler::AS_ERROR; + return GpgAutomatonHandler::kAS_ERROR; default: - return GpgAutomatonHandler::AS_ERROR; + return GpgAutomatonHandler::kAS_ERROR; }; }; @@ -345,38 +338,31 @@ auto GpgKeyManager::RevokeSubkey(const GpgKeyPtr& key, int subkey_index, [subkey_index, reason_code, reason_text_lines]( AutomatonHandelStruct& handler, AutomatonState state) { switch (state) { - case GpgAutomatonHandler::AS_SELECT: + case GpgAutomatonHandler::kAS_SELECT: return QString("key %1").arg(subkey_index); - case GpgAutomatonHandler::AS_COMMAND: + case GpgAutomatonHandler::kAS_COMMAND: return QString("revkey"); - case GpgAutomatonHandler::AS_REASON_CODE: + case GpgAutomatonHandler::kAS_REASON_CODE: return QString::number(reason_code); - case GpgAutomatonHandler::AS_REASON_TEXT: + case GpgAutomatonHandler::kAS_REASON_TEXT: return reason_text_lines->isEmpty() ? QString("") : QString(reason_text_lines->takeFirst().toUtf8()); - case GpgAutomatonHandler::AS_REALLY_ULTIMATE: + case GpgAutomatonHandler::kAS_REALLY_ULTIMATE: return QString("Y"); - case GpgAutomatonHandler::AS_QUIT: + case GpgAutomatonHandler::kAS_QUIT: return QString("quit"); - case GpgAutomatonHandler::AS_SAVE: + case GpgAutomatonHandler::kAS_SAVE: handler.SetSuccess(true); return QString("Y"); - case GpgAutomatonHandler::AS_START: - case GpgAutomatonHandler::AS_ERROR: - return QString(""); + case GpgAutomatonHandler::kAS_START: + case GpgAutomatonHandler::kAS_ERROR: default: return QString(""); } return QString(""); }; - auto key_fpr = key->Fingerprint(); - AutomatonHandelStruct handel_struct(key_fpr); - handel_struct.SetHandler(next_state_handler, action_handler); - - GpgData data_out; - return GpgAutomatonHandler::GetInstance(GetChannel()) .DoInteract(key, next_state_handler, action_handler); } diff --git a/src/core/function/gpg/GpgSmartCardManager.cpp b/src/core/function/gpg/GpgSmartCardManager.cpp index 4c55b63d..9937ef7a 100644 --- a/src/core/function/gpg/GpgSmartCardManager.cpp +++ b/src/core/function/gpg/GpgSmartCardManager.cpp @@ -41,39 +41,36 @@ auto GpgSmartCardManager::Fetch(const QString& serial_number) -> bool { auto tokens = args.split(' '); switch (state) { - case GpgAutomatonHandler::AS_START: - if (status == "CARDCTRL" && args.contains(serial_number)) { - return GpgAutomatonHandler::AS_START; - } else if (status == "GET_LINE" && args == "cardedit.prompt") { - return GpgAutomatonHandler::AS_COMMAND; + case GpgAutomatonHandler::kAS_START: + if (status == "GET_LINE" && args == "cardedit.prompt") { + return GpgAutomatonHandler::kAS_COMMAND; } - return GpgAutomatonHandler::AS_ERROR; - case GpgAutomatonHandler::AS_COMMAND: + return GpgAutomatonHandler::kAS_ERROR; + case GpgAutomatonHandler::kAS_COMMAND: if (status == "GET_LINE" && args == "cardedit.prompt") { - return GpgAutomatonHandler::AS_QUIT; + return GpgAutomatonHandler::kAS_QUIT; } - return GpgAutomatonHandler::AS_ERROR; - case GpgAutomatonHandler::AS_QUIT: - case GpgAutomatonHandler::AS_ERROR: + return GpgAutomatonHandler::kAS_ERROR; + case GpgAutomatonHandler::kAS_QUIT: + case GpgAutomatonHandler::kAS_ERROR: if (status == "GET_LINE" && args == "keyedit.prompt") { - return GpgAutomatonHandler::AS_QUIT; + return GpgAutomatonHandler::kAS_QUIT; } - return GpgAutomatonHandler::AS_ERROR; + return GpgAutomatonHandler::kAS_ERROR; default: - return GpgAutomatonHandler::AS_ERROR; + return GpgAutomatonHandler::kAS_ERROR; }; }; AutomatonActionHandler action_handler = [](AutomatonHandelStruct& handler, AutomatonState state) { switch (state) { - case GpgAutomatonHandler::AS_COMMAND: + case GpgAutomatonHandler::kAS_COMMAND: return QString("fetch"); - case GpgAutomatonHandler::AS_QUIT: + case GpgAutomatonHandler::kAS_QUIT: return QString("quit"); - case GpgAutomatonHandler::AS_START: - case GpgAutomatonHandler::AS_ERROR: - return QString(""); + case GpgAutomatonHandler::kAS_START: + case GpgAutomatonHandler::kAS_ERROR: default: return QString(""); } @@ -81,7 +78,7 @@ auto GpgSmartCardManager::Fetch(const QString& serial_number) -> bool { }; return GpgAutomatonHandler::GetInstance(GetChannel()) - .DoCardInteract(next_state_handler, action_handler); + .DoCardInteract(serial_number, next_state_handler, action_handler); } auto GpgSmartCardManager::GetSerialNumbers() -> QStringList { @@ -256,4 +253,126 @@ auto GpgSmartCardManager::ModifyPin(const QString& pin_ref) return {true, {}}; } +auto GpgSmartCardManager::GenerateKey( + const QString& serial_number, const QString& name, const QString& email, + const QString& comment, const QDateTime& expire, + bool non_expire) -> std::tuple<bool, QString> { + if (name.isEmpty() || email.isEmpty()) { + return {false, "name or email is empty"}; + } + + qint64 days_before_expire = 0; + if (!non_expire) { + days_before_expire = QDateTime::currentDateTime().daysTo(expire); + } + + GpgAutomatonHandler::AutomatonNextStateHandler next_state_handler = + [=](AutomatonState state, const QString& status, const QString& args) { + auto tokens = args.split(' '); + + switch (state) { + case GpgAutomatonHandler::kAS_START: + if (status == "GET_LINE" && args == "cardedit.prompt") { + return GpgAutomatonHandler::kAS_ADMIN; + } + return GpgAutomatonHandler::kAS_ERROR; + case GpgAutomatonHandler::kAS_ADMIN: + if (status == "GET_LINE" && args == "cardedit.prompt") { + return GpgAutomatonHandler::kAS_COMMAND; + } + return GpgAutomatonHandler::kAS_ERROR; + case GpgAutomatonHandler::kAS_COMMAND: + if (status == "GET_LINE" && args == "cardedit.genkeys.backup_enc") { + return GpgAutomatonHandler::kAS_COMMAND; + } + if (status == "GET_BOOL" && + args == "cardedit.genkeys.replace_keys") { + return GpgAutomatonHandler::kAS_COMMAND; + } + if (status == "GET_LINE" && args == "keygen.valid") { + return GpgAutomatonHandler::kAS_COMMAND; + } + if (status == "GET_LINE" && args == "keygen.name") { + return GpgAutomatonHandler::kAS_COMMAND; + } + if (status == "GET_LINE" && args == "keygen.email") { + return GpgAutomatonHandler::kAS_COMMAND; + } + if (status == "GET_LINE" && args == "keygen.comment") { + return GpgAutomatonHandler::kAS_COMMAND; + } + if (status == "PINENTRY_LAUNCHED" || + status == "BACKUP_KEY_CREATED" || status == "KEY_CONSIDERED" || + status == "KEY_CREATED") { + return GpgAutomatonHandler::kAS_INFO; + } + return GpgAutomatonHandler::kAS_ERROR; + case GpgAutomatonHandler::kAS_INFO: + if (status == "PINENTRY_LAUNCHED" || + status == "BACKUP_KEY_CREATED" || status == "KEY_CONSIDERED" || + status == "KEY_CREATED") { + return GpgAutomatonHandler::kAS_INFO; + } + if (status == "GET_LINE" && args == "cardedit.prompt") { + return GpgAutomatonHandler::kAS_QUIT; + } + return GpgAutomatonHandler::kAS_ERROR; + case GpgAutomatonHandler::kAS_QUIT: + case GpgAutomatonHandler::kAS_ERROR: + if (status == "GET_LINE" && args == "keyedit.prompt") { + return GpgAutomatonHandler::kAS_QUIT; + } + return GpgAutomatonHandler::kAS_ERROR; + default: + return GpgAutomatonHandler::kAS_ERROR; + }; + }; + + AutomatonActionHandler action_handler = [=](AutomatonHandelStruct& handler, + AutomatonState state) { + switch (state) { + case GpgAutomatonHandler::kAS_ADMIN: + return QString("admin"); + case GpgAutomatonHandler::kAS_COMMAND: { + auto [status, args] = handler.PromptStatus(); + if (args == "cardedit.prompt") { + return QString("generate"); + } + if (args == "cardedit.genkeys.backup_enc") { + return QString("y"); + } + if (args == "cardedit.genkeys.replace_keys") { + return QString("y"); + } + if (args == "keygen.valid") { + return QString::number(days_before_expire); + } + if (args == "keygen.name") { + return name; + } + if (args == "keygen.email") { + return email; + } + if (args == "keygen.comment") { + return comment; + } + return QString{}; + } + case GpgAutomatonHandler::kAS_QUIT: + return QString("quit"); + case GpgAutomatonHandler::kAS_INFO: + case GpgAutomatonHandler::kAS_START: + case GpgAutomatonHandler::kAS_ERROR: + default: + return QString{}; + } + + return QString{}; + }; + + GpgAutomatonHandler::GetInstance(GetChannel()) + .DoCardInteract(serial_number, next_state_handler, action_handler); + + return {true, {}}; +} } // namespace GpgFrontend
\ No newline at end of file diff --git a/src/core/function/gpg/GpgSmartCardManager.h b/src/core/function/gpg/GpgSmartCardManager.h index 2d3038b4..78c21bc0 100644 --- a/src/core/function/gpg/GpgSmartCardManager.h +++ b/src/core/function/gpg/GpgSmartCardManager.h @@ -99,6 +99,16 @@ class GPGFRONTEND_CORE_EXPORT GpgSmartCardManager */ auto ModifyPin(const QString& pin_ref) -> std::tuple<bool, QString>; + /** + * @brief + * + * @return auto + */ + auto GenerateKey(const QString& serial_number, const QString& name, + const QString& email, const QString& comment, + const QDateTime& expire, + bool non_expire) -> std::tuple<bool, QString>; + private: GpgContext& ctx_ = GpgContext::GetInstance(SingletonFunctionObject::GetChannel()); ///< diff --git a/src/core/function/gpg/GpgUIDOperator.cpp b/src/core/function/gpg/GpgUIDOperator.cpp index e34d224a..e07b4192 100644 --- a/src/core/function/gpg/GpgUIDOperator.cpp +++ b/src/core/function/gpg/GpgUIDOperator.cpp @@ -70,60 +70,60 @@ auto GpgUIDOperator::DeleteUID(const GpgKeyPtr& key, int uid_index) -> bool { auto tokens = args.split(' '); switch (state) { - case GpgAutomatonHandler::AS_START: + case GpgAutomatonHandler::kAS_START: if (status == "GET_LINE" && args == "keyedit.prompt") { - return GpgAutomatonHandler::AS_SELECT; + return GpgAutomatonHandler::kAS_SELECT; } - return GpgAutomatonHandler::AS_ERROR; - case GpgAutomatonHandler::AS_SELECT: + return GpgAutomatonHandler::kAS_ERROR; + case GpgAutomatonHandler::kAS_SELECT: if (status == "GET_LINE" && args == "keyedit.prompt") { - return GpgAutomatonHandler::AS_COMMAND; + return GpgAutomatonHandler::kAS_COMMAND; } - return GpgAutomatonHandler::AS_ERROR; - case GpgAutomatonHandler::AS_COMMAND: + return GpgAutomatonHandler::kAS_ERROR; + case GpgAutomatonHandler::kAS_COMMAND: if (status == "GET_LINE" && args == "keyedit.prompt") { - return GpgAutomatonHandler::AS_QUIT; + return GpgAutomatonHandler::kAS_QUIT; } else if (status == "GET_BOOL" && args == "keyedit.remove.uid.okay") { - return GpgAutomatonHandler::AS_REALLY_ULTIMATE; + return GpgAutomatonHandler::kAS_REALLY_ULTIMATE; } - return GpgAutomatonHandler::AS_ERROR; - case GpgAutomatonHandler::AS_REALLY_ULTIMATE: + return GpgAutomatonHandler::kAS_ERROR; + case GpgAutomatonHandler::kAS_REALLY_ULTIMATE: if (status == "GET_LINE" && args == "keyedit.prompt") { - return GpgAutomatonHandler::AS_QUIT; + return GpgAutomatonHandler::kAS_QUIT; } - return GpgAutomatonHandler::AS_ERROR; - case GpgAutomatonHandler::AS_QUIT: + return GpgAutomatonHandler::kAS_ERROR; + case GpgAutomatonHandler::kAS_QUIT: if (status == "GET_BOOL" && args == "keyedit.save.okay") { - return GpgAutomatonHandler::AS_SAVE; + return GpgAutomatonHandler::kAS_SAVE; } - return GpgAutomatonHandler::AS_ERROR; - case GpgAutomatonHandler::AS_ERROR: + return GpgAutomatonHandler::kAS_ERROR; + case GpgAutomatonHandler::kAS_ERROR: if (status == "GET_LINE" && args == "keyedit.prompt") { - return GpgAutomatonHandler::AS_QUIT; + return GpgAutomatonHandler::kAS_QUIT; } - return GpgAutomatonHandler::AS_ERROR; + return GpgAutomatonHandler::kAS_ERROR; default: - return GpgAutomatonHandler::AS_ERROR; + return GpgAutomatonHandler::kAS_ERROR; }; }; AutomatonActionHandler action_handler = [uid_index](AutomatonHandelStruct& handler, AutomatonState state) { switch (state) { - case GpgAutomatonHandler::AS_SELECT: + case GpgAutomatonHandler::kAS_SELECT: return QString("uid %1").arg(uid_index); - case GpgAutomatonHandler::AS_COMMAND: + case GpgAutomatonHandler::kAS_COMMAND: return QString("deluid"); - case GpgAutomatonHandler::AS_REALLY_ULTIMATE: + case GpgAutomatonHandler::kAS_REALLY_ULTIMATE: handler.SetSuccess(true); return QString("Y"); - case GpgAutomatonHandler::AS_QUIT: + case GpgAutomatonHandler::kAS_QUIT: return QString("quit"); - case GpgAutomatonHandler::AS_SAVE: + case GpgAutomatonHandler::kAS_SAVE: handler.SetSuccess(true); return QString("Y"); - case GpgAutomatonHandler::AS_START: - case GpgAutomatonHandler::AS_ERROR: + case GpgAutomatonHandler::kAS_START: + case GpgAutomatonHandler::kAS_ERROR: return QString(""); default: return QString(""); @@ -131,12 +131,6 @@ auto GpgUIDOperator::DeleteUID(const GpgKeyPtr& key, int uid_index) -> bool { return QString(""); }; - auto key_fpr = key->Fingerprint(); - AutomatonHandelStruct handel_struct(key_fpr); - handel_struct.SetHandler(next_state_handler, action_handler); - - GpgData data_out; - return GpgAutomatonHandler::GetInstance(GetChannel()) .DoInteract(key, next_state_handler, action_handler); } @@ -164,62 +158,62 @@ auto GpgUIDOperator::RevokeUID(const GpgKeyPtr& key, int uid_index, auto tokens = args.split(' '); switch (state) { - case GpgAutomatonHandler::AS_START: + case GpgAutomatonHandler::kAS_START: if (status == "GET_LINE" && args == "keyedit.prompt") { - return GpgAutomatonHandler::AS_SELECT; + return GpgAutomatonHandler::kAS_SELECT; } - return GpgAutomatonHandler::AS_ERROR; - case GpgAutomatonHandler::AS_SELECT: + return GpgAutomatonHandler::kAS_ERROR; + case GpgAutomatonHandler::kAS_SELECT: if (status == "GET_LINE" && args == "keyedit.prompt") { - return GpgAutomatonHandler::AS_COMMAND; + return GpgAutomatonHandler::kAS_COMMAND; } - return GpgAutomatonHandler::AS_ERROR; - case GpgAutomatonHandler::AS_COMMAND: + return GpgAutomatonHandler::kAS_ERROR; + case GpgAutomatonHandler::kAS_COMMAND: if (status == "GET_LINE" && args == "keyedit.prompt") { - return GpgAutomatonHandler::AS_QUIT; + return GpgAutomatonHandler::kAS_QUIT; } else if (status == "GET_BOOL" && args == "keyedit.revoke.uid.okay") { - return GpgAutomatonHandler::AS_REALLY_ULTIMATE; + return GpgAutomatonHandler::kAS_REALLY_ULTIMATE; } - return GpgAutomatonHandler::AS_ERROR; - case GpgAutomatonHandler::AS_REASON_CODE: + return GpgAutomatonHandler::kAS_ERROR; + case GpgAutomatonHandler::kAS_REASON_CODE: if (status == "GET_LINE" && args == "keyedit.prompt") { - return GpgAutomatonHandler::AS_QUIT; + return GpgAutomatonHandler::kAS_QUIT; } else if (status == "GET_LINE" && args == "ask_revocation_reason.text") { - return GpgAutomatonHandler::AS_REASON_TEXT; + return GpgAutomatonHandler::kAS_REASON_TEXT; } - return GpgAutomatonHandler::AS_ERROR; - case GpgAutomatonHandler::AS_REASON_TEXT: + return GpgAutomatonHandler::kAS_ERROR; + case GpgAutomatonHandler::kAS_REASON_TEXT: if (status == "GET_LINE" && args == "keyedit.prompt") { - return GpgAutomatonHandler::AS_QUIT; + return GpgAutomatonHandler::kAS_QUIT; } else if (status == "GET_LINE" && args == "ask_revocation_reason.text") { - return GpgAutomatonHandler::AS_REASON_TEXT; + return GpgAutomatonHandler::kAS_REASON_TEXT; } else if (status == "GET_BOOL" && args == "ask_revocation_reason.okay") { - return GpgAutomatonHandler::AS_REALLY_ULTIMATE; + return GpgAutomatonHandler::kAS_REALLY_ULTIMATE; } - return GpgAutomatonHandler::AS_ERROR; - case GpgAutomatonHandler::AS_REALLY_ULTIMATE: + return GpgAutomatonHandler::kAS_ERROR; + case GpgAutomatonHandler::kAS_REALLY_ULTIMATE: if (status == "GET_LINE" && args == "keyedit.prompt") { - return GpgAutomatonHandler::AS_QUIT; + return GpgAutomatonHandler::kAS_QUIT; } else if (status == "GET_LINE" && args == "ask_revocation_reason.code") { - return GpgAutomatonHandler::AS_REASON_CODE; + return GpgAutomatonHandler::kAS_REASON_CODE; } - return GpgAutomatonHandler::AS_ERROR; - case GpgAutomatonHandler::AS_QUIT: + return GpgAutomatonHandler::kAS_ERROR; + case GpgAutomatonHandler::kAS_QUIT: if (status == "GET_BOOL" && args == "keyedit.save.okay") { - return GpgAutomatonHandler::AS_SAVE; + return GpgAutomatonHandler::kAS_SAVE; } - return GpgAutomatonHandler::AS_ERROR; - case GpgAutomatonHandler::AS_ERROR: + return GpgAutomatonHandler::kAS_ERROR; + case GpgAutomatonHandler::kAS_ERROR: if (status == "GET_LINE" && args == "keyedit.prompt") { - return GpgAutomatonHandler::AS_QUIT; + return GpgAutomatonHandler::kAS_QUIT; } - return GpgAutomatonHandler::AS_ERROR; + return GpgAutomatonHandler::kAS_ERROR; default: - return GpgAutomatonHandler::AS_ERROR; + return GpgAutomatonHandler::kAS_ERROR; }; }; @@ -227,25 +221,25 @@ auto GpgUIDOperator::RevokeUID(const GpgKeyPtr& key, int uid_index, [uid_index, reason_code, reason_text_lines]( AutomatonHandelStruct& handler, AutomatonState state) { switch (state) { - case GpgAutomatonHandler::AS_SELECT: + case GpgAutomatonHandler::kAS_SELECT: return QString("uid %1").arg(uid_index); - case GpgAutomatonHandler::AS_COMMAND: + case GpgAutomatonHandler::kAS_COMMAND: return QString("revuid"); - case GpgAutomatonHandler::AS_REASON_CODE: + case GpgAutomatonHandler::kAS_REASON_CODE: return QString::number(reason_code); - case GpgAutomatonHandler::AS_REASON_TEXT: + case GpgAutomatonHandler::kAS_REASON_TEXT: return reason_text_lines->isEmpty() ? QString("") : QString(reason_text_lines->takeFirst().toUtf8()); - case GpgAutomatonHandler::AS_REALLY_ULTIMATE: + case GpgAutomatonHandler::kAS_REALLY_ULTIMATE: return QString("Y"); - case GpgAutomatonHandler::AS_QUIT: + case GpgAutomatonHandler::kAS_QUIT: return QString("quit"); - case GpgAutomatonHandler::AS_SAVE: + case GpgAutomatonHandler::kAS_SAVE: handler.SetSuccess(true); return QString("Y"); - case GpgAutomatonHandler::AS_START: - case GpgAutomatonHandler::AS_ERROR: + case GpgAutomatonHandler::kAS_START: + case GpgAutomatonHandler::kAS_ERROR: return QString(""); default: return QString(""); @@ -253,12 +247,6 @@ auto GpgUIDOperator::RevokeUID(const GpgKeyPtr& key, int uid_index, return QString(""); }; - auto key_fpr = key->Fingerprint(); - AutomatonHandelStruct handel_struct(key_fpr); - handel_struct.SetHandler(next_state_handler, action_handler); - - GpgData data_out; - return GpgAutomatonHandler::GetInstance(GetChannel()) .DoInteract(key, next_state_handler, action_handler); } diff --git a/src/core/model/DataObject.h b/src/core/model/DataObject.h index efd75c16..ea8fc4c4 100644 --- a/src/core/model/DataObject.h +++ b/src/core/model/DataObject.h @@ -80,13 +80,13 @@ class GPGFRONTEND_CORE_EXPORT DataObject { }; template <typename... Args> -auto TransferParams(Args&&... args) -> std::shared_ptr<DataObject> { +auto TransferParams(Args&&... args) -> QSharedPointer<DataObject> { return GpgFrontend::SecureCreateSharedObject<DataObject>( DataObject{std::forward<Args>(args)...}); } template <typename T> -auto ExtractParams(const std::shared_ptr<DataObject>& d_o, int index) -> T { +auto ExtractParams(const QSharedPointer<DataObject>& d_o, int index) -> T { if (!d_o) { throw std::invalid_argument("nullptr provided for DataObjectPtr"); } @@ -95,7 +95,7 @@ auto ExtractParams(const std::shared_ptr<DataObject>& d_o, int index) -> T { void swap(DataObject& a, DataObject& b) noexcept; -using DataObjectPtr = std::shared_ptr<DataObject>; ///< +using DataObjectPtr = QSharedPointer<DataObject>; ///< using OperaRunnable = std::function<GFError(DataObjectPtr)>; using OperationCallback = std::function<void(GFError, DataObjectPtr)>; diff --git a/src/core/model/GpgDecryptResult.cpp b/src/core/model/GpgDecryptResult.cpp index a2e2c9a7..bcfbe908 100644 --- a/src/core/model/GpgDecryptResult.cpp +++ b/src/core/model/GpgDecryptResult.cpp @@ -31,7 +31,7 @@ namespace GpgFrontend { GpgDecryptResult::GpgDecryptResult(gpgme_decrypt_result_t r) - : result_ref_(std::shared_ptr<struct _gpgme_op_decrypt_result>( + : result_ref_(QSharedPointer<struct _gpgme_op_decrypt_result>( (gpgme_result_ref(r), r), [](gpgme_decrypt_result_t p) { if (p != nullptr) { gpgme_result_unref(p); diff --git a/src/core/model/GpgDecryptResult.h b/src/core/model/GpgDecryptResult.h index 1b755868..772b24cb 100644 --- a/src/core/model/GpgDecryptResult.h +++ b/src/core/model/GpgDecryptResult.h @@ -48,7 +48,7 @@ class GPGFRONTEND_CORE_EXPORT GpgDecryptResult { virtual ~GpgDecryptResult(); private: - std::shared_ptr<struct _gpgme_op_decrypt_result> result_ref_ = nullptr; ///< + QSharedPointer<struct _gpgme_op_decrypt_result> result_ref_ = nullptr; ///< }; } // namespace GpgFrontend
\ No newline at end of file diff --git a/src/core/model/GpgEncryptResult.cpp b/src/core/model/GpgEncryptResult.cpp index 69a8535a..a3a29fcc 100644 --- a/src/core/model/GpgEncryptResult.cpp +++ b/src/core/model/GpgEncryptResult.cpp @@ -30,7 +30,7 @@ namespace GpgFrontend { GpgEncryptResult::GpgEncryptResult(gpgme_encrypt_result_t r) - : result_ref_(std::shared_ptr<struct _gpgme_op_encrypt_result>( + : result_ref_(QSharedPointer<struct _gpgme_op_encrypt_result>( (gpgme_result_ref(r), r), [](gpgme_encrypt_result_t p) { if (p != nullptr) { gpgme_result_unref(p); diff --git a/src/core/model/GpgEncryptResult.h b/src/core/model/GpgEncryptResult.h index 97a52a03..9167f28d 100644 --- a/src/core/model/GpgEncryptResult.h +++ b/src/core/model/GpgEncryptResult.h @@ -47,7 +47,7 @@ class GPGFRONTEND_CORE_EXPORT GpgEncryptResult { virtual ~GpgEncryptResult(); private: - std::shared_ptr<struct _gpgme_op_encrypt_result> result_ref_ = nullptr; ///< + QSharedPointer<struct _gpgme_op_encrypt_result> result_ref_ = nullptr; ///< }; } // namespace GpgFrontend
\ No newline at end of file diff --git a/src/core/model/GpgGenerateKeyResult.cpp b/src/core/model/GpgGenerateKeyResult.cpp index 2b455a22..928321c7 100644 --- a/src/core/model/GpgGenerateKeyResult.cpp +++ b/src/core/model/GpgGenerateKeyResult.cpp @@ -33,7 +33,7 @@ namespace GpgFrontend { GpgGenerateKeyResult::GpgGenerateKeyResult(gpgme_genkey_result_t r) - : result_ref_(std::shared_ptr<struct _gpgme_op_genkey_result>( + : result_ref_(QSharedPointer<struct _gpgme_op_genkey_result>( (gpgme_result_ref(r), r), [](gpgme_genkey_result_t p) { if (p != nullptr) { gpgme_result_unref(p); diff --git a/src/core/model/GpgGenerateKeyResult.h b/src/core/model/GpgGenerateKeyResult.h index ac5d6b05..80e49a38 100644 --- a/src/core/model/GpgGenerateKeyResult.h +++ b/src/core/model/GpgGenerateKeyResult.h @@ -52,8 +52,7 @@ class GPGFRONTEND_CORE_EXPORT GpgGenerateKeyResult { virtual ~GpgGenerateKeyResult(); private: - using ResultRefHandler = - std::shared_ptr<struct _gpgme_op_genkey_result>; ///< + using ResultRefHandler = QSharedPointer<struct _gpgme_op_genkey_result>; ///< ResultRefHandler result_ref_ = nullptr; ///< }; diff --git a/src/core/model/GpgKeyTreeModel.cpp b/src/core/model/GpgKeyTreeModel.cpp index 92a0f77c..f521e8c9 100644 --- a/src/core/model/GpgKeyTreeModel.cpp +++ b/src/core/model/GpgKeyTreeModel.cpp @@ -218,6 +218,7 @@ auto GpgKeyTreeModel::create_gpg_key_tree_items(const GpgAbstractKeyPtr &key) columns << g_key->Algo(); columns << QLocale().toString(g_key->CreationTime(), "yyyy-MM-dd"); + assert(key != nullptr); auto i_key = QSharedPointer<GpgKeyTreeItem>::create(key, columns); i_key->SetEnable(true); i_key->SetCheckable(checkable_detector_(i_key->Key())); @@ -317,9 +318,15 @@ void GpgKeyTreeItem::SetChecked(bool checked) { checked_ = checked; } void GpgKeyTreeItem::SetCheckable(bool checkable) { checkable_ = checkable; } -auto GpgKeyTreeItem::Key() const -> GpgAbstractKey * { return key_.get(); } +auto GpgKeyTreeItem::Key() const -> GpgAbstractKey * { + assert(key_ != nullptr); + return key_.get(); +} -auto GpgKeyTreeItem::SharedKey() const -> GpgAbstractKeyPtr { return key_; } +auto GpgKeyTreeItem::SharedKey() const -> GpgAbstractKeyPtr { + assert(key_ != nullptr); + return key_; +} auto GpgKeyTreeItem::Enable() const -> bool { return enable_; } diff --git a/src/core/model/GpgSignResult.cpp b/src/core/model/GpgSignResult.cpp index 8227d46e..6428a461 100644 --- a/src/core/model/GpgSignResult.cpp +++ b/src/core/model/GpgSignResult.cpp @@ -29,7 +29,7 @@ #include "GpgSignResult.h" namespace GpgFrontend { GpgSignResult::GpgSignResult(gpgme_sign_result_t r) - : result_ref_(std::shared_ptr<struct _gpgme_op_sign_result>( + : result_ref_(QSharedPointer<struct _gpgme_op_sign_result>( (gpgme_result_ref(r), r), [](gpgme_sign_result_t p) { if (p != nullptr) { gpgme_result_unref(p); diff --git a/src/core/model/GpgSignResult.h b/src/core/model/GpgSignResult.h index 75f106f6..434a590e 100644 --- a/src/core/model/GpgSignResult.h +++ b/src/core/model/GpgSignResult.h @@ -50,6 +50,6 @@ class GPGFRONTEND_CORE_EXPORT GpgSignResult { virtual ~GpgSignResult(); private: - std::shared_ptr<struct _gpgme_op_sign_result> result_ref_ = nullptr; ///< + QSharedPointer<struct _gpgme_op_sign_result> result_ref_ = nullptr; ///< }; } // namespace GpgFrontend
\ No newline at end of file diff --git a/src/core/model/GpgVerifyResult.cpp b/src/core/model/GpgVerifyResult.cpp index ca5784d8..aab23028 100644 --- a/src/core/model/GpgVerifyResult.cpp +++ b/src/core/model/GpgVerifyResult.cpp @@ -32,7 +32,7 @@ namespace GpgFrontend { GpgVerifyResult::GpgVerifyResult(gpgme_verify_result_t r) - : result_ref_(std::shared_ptr<struct _gpgme_op_verify_result>( + : result_ref_(QSharedPointer<struct _gpgme_op_verify_result>( (gpgme_result_ref(r), r), [](gpgme_verify_result_t p) { if (p != nullptr) { gpgme_result_unref(p); diff --git a/src/core/model/GpgVerifyResult.h b/src/core/model/GpgVerifyResult.h index 6e61497e..b928d2ca 100644 --- a/src/core/model/GpgVerifyResult.h +++ b/src/core/model/GpgVerifyResult.h @@ -48,6 +48,6 @@ class GPGFRONTEND_CORE_EXPORT GpgVerifyResult { virtual ~GpgVerifyResult(); private: - std::shared_ptr<struct _gpgme_op_verify_result> result_ref_ = nullptr; ///< + QSharedPointer<struct _gpgme_op_verify_result> result_ref_ = nullptr; ///< }; } // namespace GpgFrontend
\ No newline at end of file diff --git a/src/core/module/Event.h b/src/core/module/Event.h index d37992b7..a6660266 100644 --- a/src/core/module/Event.h +++ b/src/core/module/Event.h @@ -40,7 +40,7 @@ namespace GpgFrontend::Module { class Event; -using EventReference = std::shared_ptr<Event>; +using EventReference = QSharedPointer<Event>; using EventIdentifier = QString; using EventTriggerIdentifier = QString; using Evnets = QContainer<Event>; diff --git a/src/core/module/GlobalModuleContext.cpp b/src/core/module/GlobalModuleContext.cpp index fd530432..6e971089 100644 --- a/src/core/module/GlobalModuleContext.cpp +++ b/src/core/module/GlobalModuleContext.cpp @@ -353,7 +353,7 @@ class GlobalModuleContext::Impl { QStringList listening_event_ids; }; - using ModuleRegisterInfoPtr = std::shared_ptr<ModuleRegisterInfo>; + using ModuleRegisterInfoPtr = QSharedPointer<ModuleRegisterInfo>; std::unordered_map<ModuleIdentifier, ModuleRegisterInfoPtr> module_register_table_; diff --git a/src/core/module/GlobalModuleContext.h b/src/core/module/GlobalModuleContext.h index e0f8e644..611926b1 100644 --- a/src/core/module/GlobalModuleContext.h +++ b/src/core/module/GlobalModuleContext.h @@ -43,13 +43,13 @@ class GlobalRegisterTable; class Module; class ModuleManager; using ModuleIdentifier = QString; -using ModulePtr = std::shared_ptr<Module>; +using ModulePtr = QSharedPointer<Module>; using ModuleRawPtr = Module*; -using GMCPtr = std::shared_ptr<GlobalModuleContext>; -using GRTPtr = std::shared_ptr<GlobalRegisterTable>; +using GMCPtr = QSharedPointer<GlobalModuleContext>; +using GRTPtr = QSharedPointer<GlobalRegisterTable>; -using TaskRunnerPtr = std::shared_ptr<Thread::TaskRunner>; +using TaskRunnerPtr = QSharedPointer<Thread::TaskRunner>; class GPGFRONTEND_CORE_EXPORT GlobalModuleContext : public QObject { Q_OBJECT diff --git a/src/core/module/GlobalRegisterTable.cpp b/src/core/module/GlobalRegisterTable.cpp index 6d83c2fb..e873f527 100644 --- a/src/core/module/GlobalRegisterTable.cpp +++ b/src/core/module/GlobalRegisterTable.cpp @@ -58,7 +58,7 @@ class GlobalRegisterTable::Impl { explicit Impl(GlobalRegisterTable* parent) : parent_(parent), - root_node_(SecureCreateQSharedObject<RTNode>("", nullptr)) {} + root_node_(SecureCreateSharedObject<RTNode>("", nullptr)) {} auto PublishKV(const Namespace& n, const Key& k, std::any v) -> bool { QStringList const segments = (n + "." + k).split('.'); @@ -72,7 +72,7 @@ class GlobalRegisterTable::Impl { auto it = current->children.find(segment); if (it == current->children.end()) { it = current->children.insert( - segment, SecureCreateQSharedObject<RTNode>(segment, current)); + segment, SecureCreateSharedObject<RTNode>(segment, current)); } current = it.value(); } diff --git a/src/core/module/Module.h b/src/core/module/Module.h index d6182688..19c86be4 100644 --- a/src/core/module/Module.h +++ b/src/core/module/Module.h @@ -40,9 +40,9 @@ class ModuleManager; using ModuleIdentifier = QString; using ModuleVersion = QString; using ModuleMetaData = QMap<QString, QString>; -using ModulePtr = std::shared_ptr<Module>; +using ModulePtr = QSharedPointer<Module>; -using TaskRunnerPtr = std::shared_ptr<Thread::TaskRunner>; +using TaskRunnerPtr = QSharedPointer<Thread::TaskRunner>; class GPGFRONTEND_CORE_EXPORT Module : public QObject { Q_OBJECT diff --git a/src/core/module/ModuleManager.h b/src/core/module/ModuleManager.h index 0077fe44..2c7d3bee 100644 --- a/src/core/module/ModuleManager.h +++ b/src/core/module/ModuleManager.h @@ -41,7 +41,7 @@ class TaskRunner; namespace GpgFrontend::Module { -using TaskRunnerPtr = std::shared_ptr<Thread::TaskRunner>; +using TaskRunnerPtr = QSharedPointer<Thread::TaskRunner>; class Event; class Module; @@ -49,11 +49,11 @@ class GlobalModuleContext; class ModuleManager; class GlobalRegisterTable; -using EventReference = std::shared_ptr<Event>; +using EventReference = QSharedPointer<Event>; using ModuleIdentifier = QString; -using ModulePtr = std::shared_ptr<Module>; -using ModuleMangerPtr = std::shared_ptr<ModuleManager>; -using GMCPtr = std::shared_ptr<GlobalModuleContext>; +using ModulePtr = QSharedPointer<Module>; +using ModuleMangerPtr = QSharedPointer<ModuleManager>; +using GMCPtr = QSharedPointer<GlobalModuleContext>; using Namespace = QString; using Key = QString; using LPCallback = std::function<void(Namespace, Key, int, std::any)>; diff --git a/src/core/thread/TaskRunnerGetter.h b/src/core/thread/TaskRunnerGetter.h index cea775f9..dd69c888 100644 --- a/src/core/thread/TaskRunnerGetter.h +++ b/src/core/thread/TaskRunnerGetter.h @@ -36,7 +36,7 @@ namespace GpgFrontend::Thread { -using TaskRunnerPtr = std::shared_ptr<TaskRunner>; +using TaskRunnerPtr = QSharedPointer<TaskRunner>; class GPGFRONTEND_CORE_EXPORT TaskRunnerGetter : public GpgFrontend::SingletonFunctionObject<TaskRunnerGetter> { diff --git a/src/core/utils/CommonUtils.cpp b/src/core/utils/CommonUtils.cpp index 0adc4d7f..ce36c71e 100644 --- a/src/core/utils/CommonUtils.cpp +++ b/src/core/utils/CommonUtils.cpp @@ -107,4 +107,11 @@ auto GPGFRONTEND_CORE_EXPORT ParseHexEncodedVersionTuple(const QString& s) const auto version = s.toUtf8().toUInt(&ok, 16); return ok ? static_cast<int>(version) : -1; } + +const auto kReEmail = QRegularExpression{ + R"((?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\]))"}; + +auto GPGFRONTEND_CORE_EXPORT IsEmailAddress(const QString& str) -> bool { + return kReEmail.match(str).hasMatch(); +} } // namespace GpgFrontend
\ No newline at end of file diff --git a/src/core/utils/CommonUtils.h b/src/core/utils/CommonUtils.h index 468d8a59..d62f4867 100644 --- a/src/core/utils/CommonUtils.h +++ b/src/core/utils/CommonUtils.h @@ -82,4 +82,12 @@ auto GPGFRONTEND_CORE_EXPORT IsFlatpakENV() -> bool; auto GPGFRONTEND_CORE_EXPORT ParseHexEncodedVersionTuple(const QString &s) -> int; +/** + * @brief + * + * @return true + * @return false + */ +auto GPGFRONTEND_CORE_EXPORT IsEmailAddress(const QString &) -> bool; + } // namespace GpgFrontend
\ No newline at end of file diff --git a/src/core/utils/MemoryUtils.h b/src/core/utils/MemoryUtils.h index 223c6f82..6c2bb69f 100644 --- a/src/core/utils/MemoryUtils.h +++ b/src/core/utils/MemoryUtils.h @@ -143,24 +143,7 @@ static auto SecureCreateUniqueObject(Args &&...args) } template <typename T, typename... Args> -auto SecureCreateSharedObject(Args &&...args) -> std::shared_ptr<T> { - void *mem = SecureMemoryAllocator::Allocate(sizeof(T)); - if (!mem) throw std::bad_alloc(); - - try { - T *obj = new (mem) T(std::forward<Args>(args)...); - return std::shared_ptr<T>(obj, [](T *ptr) { - ptr->~T(); - SecureMemoryAllocator::Deallocate(ptr); - }); - } catch (...) { - SecureMemoryAllocator::Deallocate(mem); - throw; - } -} - -template <typename T, typename... Args> -auto SecureCreateQSharedObject(Args &&...args) -> QSharedPointer<T> { +auto SecureCreateSharedObject(Args &&...args) -> QSharedPointer<T> { void *mem = SecureMemoryAllocator::Allocate(sizeof(T)); if (!mem) throw std::bad_alloc(); diff --git a/src/ui/UserInterfaceUtils.cpp b/src/ui/UserInterfaceUtils.cpp index 7cae0648..8d277ab4 100644 --- a/src/ui/UserInterfaceUtils.cpp +++ b/src/ui/UserInterfaceUtils.cpp @@ -479,7 +479,7 @@ void CommonUtils::slot_update_key_status() { void CommonUtils::slot_update_key_from_server_finished( int channel, bool success, QString err_msg, QByteArray buffer, - std::shared_ptr<GpgImportInformation> info) { + QSharedPointer<GpgImportInformation> info) { if (!success) { LOG_W() << "get err from reply: " << buffer; QMessageBox::critical(nullptr, tr("Error"), err_msg); diff --git a/src/ui/UserInterfaceUtils.h b/src/ui/UserInterfaceUtils.h index 9f79cec2..fe912fcf 100644 --- a/src/ui/UserInterfaceUtils.h +++ b/src/ui/UserInterfaceUtils.h @@ -278,7 +278,7 @@ class CommonUtils : public QWidget { */ void slot_update_key_from_server_finished( int channel, bool, QString, QByteArray, - std::shared_ptr<GpgImportInformation>); + QSharedPointer<GpgImportInformation>); private: static QScopedPointer<CommonUtils> instance; ///< diff --git a/src/ui/dialog/KeyDatabaseEditDialog.cpp b/src/ui/dialog/KeyDatabaseEditDialog.cpp index a4744c85..a9516754 100644 --- a/src/ui/dialog/KeyDatabaseEditDialog.cpp +++ b/src/ui/dialog/KeyDatabaseEditDialog.cpp @@ -29,7 +29,6 @@ #include "KeyDatabaseEditDialog.h" #include "core/function/GlobalSettingStation.h" -#include "core/struct/settings_object/KeyDatabaseItemSO.h" #include "core/utils/MemoryUtils.h" #include "ui_KeyDatabaseEditDialog.h" diff --git a/src/ui/dialog/KeyDatabaseEditDialog.h b/src/ui/dialog/KeyDatabaseEditDialog.h index c2e9f435..7e9cdb60 100644 --- a/src/ui/dialog/KeyDatabaseEditDialog.h +++ b/src/ui/dialog/KeyDatabaseEditDialog.h @@ -49,7 +49,7 @@ class KeyDatabaseEditDialog : public GeneralDialog { void SignalKeyDatabaseInfoAccepted(QString name, QString path); private: - std::shared_ptr<Ui_KeyDatabaseEditDialog> ui_; ///< + QSharedPointer<Ui_KeyDatabaseEditDialog> ui_; ///< QString default_name_; QString default_path_; diff --git a/src/ui/dialog/KeyGroupCreationDialog.cpp b/src/ui/dialog/KeyGroupCreationDialog.cpp index 16e34536..02642482 100644 --- a/src/ui/dialog/KeyGroupCreationDialog.cpp +++ b/src/ui/dialog/KeyGroupCreationDialog.cpp @@ -30,6 +30,7 @@ #include "core/function/gpg/GpgKeyGroupGetter.h" #include "core/model/GpgKeyGroup.h" +#include "core/utils/CommonUtils.h" #include "ui/UISignalStation.h" namespace GpgFrontend::UI { @@ -96,9 +97,10 @@ void KeyGroupCreationDialog::slot_create_new_uid() { error_stream << " " << tr("Name must contain at least five characters.") << Qt::endl; } - if (email_->text().isEmpty() || !check_email_address(email_->text())) { + if (email_->text().isEmpty() || !IsEmailAddress(email_->text())) { error_stream << " " << tr("Please give a email address.") << Qt::endl; } + auto error_string = error_stream.readAll(); if (error_string.isEmpty()) { auto p_kg = @@ -109,9 +111,6 @@ void KeyGroupCreationDialog::slot_create_new_uid() { emit SignalCreated(); this->close(); } else { - /** - * create error message - */ error_label_->setAutoFillBackground(true); QPalette error = error_label_->palette(); error.setColor(QPalette::Window, "#ff8080"); @@ -124,7 +123,4 @@ void KeyGroupCreationDialog::slot_create_new_uid() { } } -auto KeyGroupCreationDialog::check_email_address(const QString& str) -> bool { - return re_email_.match(str).hasMatch(); -} } // namespace GpgFrontend::UI diff --git a/src/ui/dialog/KeyGroupCreationDialog.h b/src/ui/dialog/KeyGroupCreationDialog.h index 634c9148..d03c2cbc 100644 --- a/src/ui/dialog/KeyGroupCreationDialog.h +++ b/src/ui/dialog/KeyGroupCreationDialog.h @@ -28,11 +28,7 @@ #pragma once -#include "core/function/gpg/GpgContext.h" -#include "core/model/GpgKey.h" -#include "core/typedef/GpgTypedef.h" #include "ui/dialog/GeneralDialog.h" - namespace GpgFrontend::UI { class KeyGroupCreationDialog : public GeneralDialog { Q_OBJECT @@ -45,7 +41,7 @@ class KeyGroupCreationDialog : public GeneralDialog { * @param parent */ KeyGroupCreationDialog(int channel, QStringList key_ids, - QWidget* parent = nullptr); + QWidget* parent = nullptr); signals: /** @@ -74,17 +70,5 @@ class KeyGroupCreationDialog : public GeneralDialog { QStringList error_messages_; ///< QLabel* error_label_{}; ///< - - QRegularExpression re_email_{ - R"((?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\]))"}; - - /** - * @brief - * - * @param str - * @return true - * @return false - */ - auto check_email_address(const QString& str) -> bool; }; } // namespace GpgFrontend::UI diff --git a/src/ui/dialog/KeyGroupManageDialog.cpp b/src/ui/dialog/KeyGroupManageDialog.cpp index d7b9b3d3..59d54f20 100644 --- a/src/ui/dialog/KeyGroupManageDialog.cpp +++ b/src/ui/dialog/KeyGroupManageDialog.cpp @@ -88,7 +88,7 @@ KeyGroupManageDialog::KeyGroupManageDialog( ui_->removeButton->setDisabled(true); ui_->keyGroupTipLabel->setText(tr("Key(s) in Key Group: ")); - ui_->keyDBTipLabel->setText(tr("Key(s) in Key Dayabase: ")); + ui_->keyDBTipLabel->setText(tr("Key(s) in Key Database: ")); QTimer::singleShot(200, [=]() { slot_notify_invalid_key_ids(); }); diff --git a/src/ui/dialog/RevocationOptionsDialog.h b/src/ui/dialog/RevocationOptionsDialog.h index 1ccdaac3..c9b18b35 100644 --- a/src/ui/dialog/RevocationOptionsDialog.h +++ b/src/ui/dialog/RevocationOptionsDialog.h @@ -46,7 +46,7 @@ class RevocationOptionsDialog : public GeneralDialog { void SignalRevokeOptionAccepted(int code, QString text); private: - std::shared_ptr<Ui_RevocationOptionsDialog> ui_; ///< + QSharedPointer<Ui_RevocationOptionsDialog> ui_; ///< int code_; QString text_; diff --git a/src/ui/dialog/controller/GnuPGControllerDialog.h b/src/ui/dialog/controller/GnuPGControllerDialog.h index 3ee129b9..0337b141 100644 --- a/src/ui/dialog/controller/GnuPGControllerDialog.h +++ b/src/ui/dialog/controller/GnuPGControllerDialog.h @@ -126,7 +126,7 @@ class GnuPGControllerDialog : public GeneralDialog { void slot_edit_key_database(); private: - std::shared_ptr<Ui_GnuPGControllerDialog> ui_; ///< + QSharedPointer<Ui_GnuPGControllerDialog> ui_; ///< const QString app_path_; int restart_mode_{0}; ///< QString custom_key_database_path_; diff --git a/src/ui/dialog/controller/ModuleControllerDialog.cpp b/src/ui/dialog/controller/ModuleControllerDialog.cpp index 2ad13151..f9b8e58f 100644 --- a/src/ui/dialog/controller/ModuleControllerDialog.cpp +++ b/src/ui/dialog/controller/ModuleControllerDialog.cpp @@ -41,7 +41,7 @@ namespace GpgFrontend::UI { ModuleControllerDialog::ModuleControllerDialog(QWidget* parent) : GeneralDialog("ModuleControllerDialog", parent), - ui_(std::make_shared<Ui_ModuleControllerDialog>()), + ui_(QSharedPointer<Ui_ModuleControllerDialog>::create()), module_manager_(&Module::ModuleManager::GetInstance()) { ui_->setupUi(this); ui_->actionsGroupBox->hide(); diff --git a/src/ui/dialog/controller/ModuleControllerDialog.h b/src/ui/dialog/controller/ModuleControllerDialog.h index 94520a76..455a39c8 100644 --- a/src/ui/dialog/controller/ModuleControllerDialog.h +++ b/src/ui/dialog/controller/ModuleControllerDialog.h @@ -55,7 +55,7 @@ class ModuleControllerDialog : public GeneralDialog { void slot_load_module_details(Module::ModuleIdentifier); private: - std::shared_ptr<Ui_ModuleControllerDialog> ui_; ///< + QSharedPointer<Ui_ModuleControllerDialog> ui_; ///< Module::ModuleManager* module_manager_; }; diff --git a/src/ui/dialog/controller/SmartCardControllerDialog.cpp b/src/ui/dialog/controller/SmartCardControllerDialog.cpp index b48d49af..fb812ad6 100644 --- a/src/ui/dialog/controller/SmartCardControllerDialog.cpp +++ b/src/ui/dialog/controller/SmartCardControllerDialog.cpp @@ -29,12 +29,11 @@ #include "SmartCardControllerDialog.h" #include "core/function/gpg/GpgAdvancedOperator.h" -#include "core/function/gpg/GpgAssuanHelper.h" #include "core/function/gpg/GpgCommandExecutor.h" #include "core/function/gpg/GpgSmartCardManager.h" -#include "core/module/ModuleManager.h" #include "core/utils/GpgUtils.h" #include "ui/UISignalStation.h" +#include "ui/dialog/key_generate/GenerateCardKeyDialog.h" // #include "ui_SmartCardControllerDialog.h" @@ -59,6 +58,7 @@ SmartCardControllerDialog::SmartCardControllerDialog(QWidget* parent) ui_->cResetCodeButton->setText(tr("Change Reset Code")); ui_->fetchButton->setText(tr("Fetch")); ui_->restartGpgAgentButton->setText(tr("Restart All Gpg-Agents")); + ui_->generateKeysButton->setText(tr("Generate Card Keys")); ui_->refreshButton->setText(tr("Refresh")); ui_->operationGroupBox->setTitle(tr("Operations")); @@ -122,6 +122,16 @@ SmartCardControllerDialog::SmartCardControllerDialog(QWidget* parent) }); }); + connect(ui_->generateKeysButton, &QPushButton::clicked, this, [=](bool) { + auto serial_number = ui_->currentCardComboBox->currentText(); + auto* d = new GenerateCardKeyDialog(channel_, serial_number, this); + connect(d, &GenerateCardKeyDialog::finished, this, [=](int ret) { + if (ret == 1) { + fetch_smart_card_info(serial_number); + } + }); + }); + connect(UISignalStation::GetInstance(), &UISignalStation::SignalKeyDatabaseRefreshDone, this, [=]() { refresh_key_tree_view(ui_->keyDBIndexComboBox->currentIndex()); @@ -325,17 +335,19 @@ void SmartCardControllerDialog::slot_refresh() { void SmartCardControllerDialog::refresh_key_tree_view(int channel) { if (!has_card_) return; + ui_->cardKeysTreeView->SetChannel(channel); + QStringList card_fprs; for (const auto& key_info : card_info_.card_keys_info.values()) { card_fprs.append(key_info.fingerprint); } + LOG_D() << "card key fingerprints:" << card_fprs; if (card_fprs.isEmpty()) { ui_->cardKeysTreeView->SetKeyFilter([](auto) { return false; }); return; } - ui_->cardKeysTreeView->SetChannel(channel); ui_->cardKeysTreeView->SetKeyFilter([=](const GpgAbstractKey* k) { return card_fprs.contains(k->Fingerprint()); }); diff --git a/src/ui/dialog/import_export/ExportKeyPackageDialog.h b/src/ui/dialog/import_export/ExportKeyPackageDialog.h index f457e405..6698ecac 100644 --- a/src/ui/dialog/import_export/ExportKeyPackageDialog.h +++ b/src/ui/dialog/import_export/ExportKeyPackageDialog.h @@ -54,7 +54,7 @@ class ExportKeyPackageDialog : public GeneralDialog { QWidget* parent); private: - std::shared_ptr<Ui_exportKeyPackageDialog> ui_; ///< + QSharedPointer<Ui_exportKeyPackageDialog> ui_; ///< int current_gpg_context_channel_; GpgAbstractKeyPtrList keys_; ///< QString passphrase_; ///< diff --git a/src/ui/dialog/import_export/KeyImportDetailDialog.cpp b/src/ui/dialog/import_export/KeyImportDetailDialog.cpp index 92e45eb6..ea1cd478 100644 --- a/src/ui/dialog/import_export/KeyImportDetailDialog.cpp +++ b/src/ui/dialog/import_export/KeyImportDetailDialog.cpp @@ -33,7 +33,7 @@ namespace GpgFrontend::UI { KeyImportDetailDialog::KeyImportDetailDialog( - int channel, std::shared_ptr<GpgImportInformation> result, QWidget* parent) + int channel, QSharedPointer<GpgImportInformation> result, QWidget* parent) : GeneralDialog(typeid(KeyImportDetailDialog).name(), parent), current_gpg_context_channel_(channel), m_result_(std::move(result)) { @@ -147,7 +147,7 @@ void KeyImportDetailDialog::create_keys_table() { int row = 0; for (const auto& imp_key : m_result_->imported_keys) { keys_table_->setRowCount(row + 1); - + auto key = GpgAbstractKeyGetter::GetInstance(current_gpg_context_channel_) .GetKey(imp_key.fpr); if (key == nullptr) continue; diff --git a/src/ui/dialog/import_export/KeyImportDetailDialog.h b/src/ui/dialog/import_export/KeyImportDetailDialog.h index 3058f6a3..f0bf815a 100644 --- a/src/ui/dialog/import_export/KeyImportDetailDialog.h +++ b/src/ui/dialog/import_export/KeyImportDetailDialog.h @@ -53,7 +53,7 @@ class KeyImportDetailDialog : public GeneralDialog { * @param parent */ explicit KeyImportDetailDialog(int channel, - std::shared_ptr<GpgImportInformation> result, + QSharedPointer<GpgImportInformation> result, QWidget* parent = nullptr); private: @@ -89,6 +89,6 @@ class KeyImportDetailDialog : public GeneralDialog { QDialogButtonBox* button_box_{}; ///< int current_gpg_context_channel_; - std::shared_ptr<GpgImportInformation> m_result_; ///< + QSharedPointer<GpgImportInformation> m_result_; ///< }; } // namespace GpgFrontend::UI diff --git a/src/ui/dialog/import_export/KeyServerImportDialog.cpp b/src/ui/dialog/import_export/KeyServerImportDialog.cpp index ad80f1a1..37ca5a3d 100644 --- a/src/ui/dialog/import_export/KeyServerImportDialog.cpp +++ b/src/ui/dialog/import_export/KeyServerImportDialog.cpp @@ -408,7 +408,7 @@ void KeyServerImportDialog::SlotImport(QStringList key_ids, void KeyServerImportDialog::slot_import_finished( int channel, bool success, QString err_msg, QByteArray buffer, - std::shared_ptr<GpgImportInformation> info) { + QSharedPointer<GpgImportInformation> info) { set_loading(false); if (!success) { diff --git a/src/ui/dialog/import_export/KeyServerImportDialog.h b/src/ui/dialog/import_export/KeyServerImportDialog.h index 25c55c3e..529cd9fc 100644 --- a/src/ui/dialog/import_export/KeyServerImportDialog.h +++ b/src/ui/dialog/import_export/KeyServerImportDialog.h @@ -99,7 +99,7 @@ class KeyServerImportDialog : public GeneralDialog { */ void slot_import_finished(int channel, bool success, QString err_msg, QByteArray buffer, - std::shared_ptr<GpgImportInformation> info); + QSharedPointer<GpgImportInformation> info); /** * @brief diff --git a/src/ui/dialog/key_generate/GenerateCardKeyDialog.cpp b/src/ui/dialog/key_generate/GenerateCardKeyDialog.cpp new file mode 100644 index 00000000..91498d43 --- /dev/null +++ b/src/ui/dialog/key_generate/GenerateCardKeyDialog.cpp @@ -0,0 +1,110 @@ +/** + * Copyright (C) 2021-2024 Saturneric <[email protected]> + * + * This file is part of GpgFrontend. + * + * GpgFrontend is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GpgFrontend is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from + * the gpg4usb project, which is under GPL-3.0-or-later. + * + * All the source code of GpgFrontend was modified and released by + * Saturneric <[email protected]> starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#include "GenerateCardKeyDialog.h" + +#include "core/function/gpg/GpgSmartCardManager.h" +#include "core/utils/CommonUtils.h" +#include "ui/UISignalStation.h" +#include "ui/function/GpgOperaHelper.h" + +// +#include "ui_GenerateCardKeyDialog.h" + +namespace GpgFrontend::UI { + +GenerateCardKeyDialog::GenerateCardKeyDialog(int channel, + const QString& serial_number, + QWidget* parent) + : GeneralDialog("GenerateCardKeyDialog", parent), + channel_(channel), + serial_number_(serial_number), + ui_(QSharedPointer<Ui_GenerateCardKeyDialog>::create()) { + ui_->setupUi(this); + + const auto min_date_time = QDateTime::currentDateTime().addDays(3); + ui_->dateEdit->setMinimumDateTime(min_date_time); + + connect(ui_->generateButton, &QPushButton::clicked, this, + &GenerateCardKeyDialog::slot_generate_card_key); + + movePosition2CenterOfParent(); + + this->show(); + this->raise(); + this->activateWindow(); +} + +void GenerateCardKeyDialog::slot_generate_card_key() { + QString buffer; + QTextStream error_stream(&buffer); + + if ((ui_->nameEdit->text()).size() < 5) { + error_stream << " " << tr("Name must contain at least five characters.") + << Qt::endl; + } + + if (ui_->nameEdit->text().isEmpty() || + !IsEmailAddress(ui_->emailEdit->text())) { + error_stream << " " << tr("Please give a email address.") << Qt::endl; + } + + auto error_string = error_stream.readAll(); + if (!error_string.isEmpty()) { + ui_->errLabel->setAutoFillBackground(true); + QPalette error = ui_->errLabel->palette(); + error.setColor(QPalette::Window, "#ff8080"); + ui_->errLabel->setPalette(error); + ui_->errLabel->setText(error_string); + + this->show(); + this->raise(); + this->activateWindow(); + return; + } + + auto f = [=](const OperaWaitingHd& hd) { + auto [ret, err] = GpgSmartCardManager::GetInstance(channel_).GenerateKey( + serial_number_, ui_->nameEdit->text(), ui_->emailEdit->text(), + ui_->commentEdit->text(), ui_->dateEdit->dateTime(), + ui_->nonExpireCheckBox->isChecked()); + + hd(); + + UISignalStation::GetInstance()->SignalKeyDatabaseRefresh(); + + connect(UISignalStation::GetInstance(), + &UISignalStation::SignalKeyDatabaseRefreshDone, this, + [=, ret = ret]() { + emit finished(ret ? 1 : -1); + this->close(); + }); + }; + GpgOperaHelper::WaitForOpera(this, tr("Generating"), f); +} +} // namespace GpgFrontend::UI
\ No newline at end of file diff --git a/src/ui/dialog/key_generate/GenerateCardKeyDialog.h b/src/ui/dialog/key_generate/GenerateCardKeyDialog.h new file mode 100644 index 00000000..93df5aaa --- /dev/null +++ b/src/ui/dialog/key_generate/GenerateCardKeyDialog.h @@ -0,0 +1,58 @@ +/** + * Copyright (C) 2021-2024 Saturneric <[email protected]> + * + * This file is part of GpgFrontend. + * + * GpgFrontend is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GpgFrontend is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from + * the gpg4usb project, which is under GPL-3.0-or-later. + * + * All the source code of GpgFrontend was modified and released by + * Saturneric <[email protected]> starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#pragma once + +#include "ui/dialog/GeneralDialog.h" + +class Ui_GenerateCardKeyDialog; + +namespace GpgFrontend::UI { +class GenerateCardKeyDialog : public GeneralDialog { + public: + /** + * @brief Construct a new Generate Card Key Dialog object + * + * @param parent + */ + explicit GenerateCardKeyDialog(int channel_, const QString& serial_number, + QWidget* parent); + + private: + /** + * @brief + * + */ + void slot_generate_card_key(); + + private: + int channel_; + const QString& serial_number_; + QSharedPointer<Ui_GenerateCardKeyDialog> ui_; ///< +}; +}; // namespace GpgFrontend::UI
\ No newline at end of file diff --git a/src/ui/dialog/key_generate/KeyGenerateDialog.cpp b/src/ui/dialog/key_generate/KeyGenerateDialog.cpp index 0a2dbe1a..d738029d 100644 --- a/src/ui/dialog/key_generate/KeyGenerateDialog.cpp +++ b/src/ui/dialog/key_generate/KeyGenerateDialog.cpp @@ -157,7 +157,7 @@ void KeyGenerateDialog::slot_key_gen_accept() { << Qt::endl; } if (ui_->emailEdit->text().isEmpty() || - !check_email_address(ui_->emailEdit->text())) { + !IsEmailAddress(ui_->emailEdit->text())) { err_stream << " -> " << tr("Please give a valid email address.") << Qt::endl; } @@ -454,10 +454,6 @@ void KeyGenerateDialog::set_signal_slot_config() { &UISignalStation::SignalKeyDatabaseRefresh); } -auto KeyGenerateDialog::check_email_address(const QString& str) -> bool { - return re_email_.match(str).hasMatch(); -} - void KeyGenerateDialog::sync_gen_key_algo_info() { auto [found, algo] = GetAlgoByName(ui_->pAlgoComboBox->currentText(), diff --git a/src/ui/dialog/key_generate/KeyGenerateDialog.h b/src/ui/dialog/key_generate/KeyGenerateDialog.h index ad927446..6217d520 100644 --- a/src/ui/dialog/key_generate/KeyGenerateDialog.h +++ b/src/ui/dialog/key_generate/KeyGenerateDialog.h @@ -105,13 +105,6 @@ class KeyGenerateDialog : public GeneralDialog { * @brief * */ - QRegularExpression re_email_{ - R"((?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\]))"}; - - /** - * @brief - * - */ QStringList error_messages_; ///< List of errors occurring when checking ///< entries of line edits @@ -138,15 +131,6 @@ class KeyGenerateDialog : public GeneralDialog { /** * @brief * - * @param str - * @return true - * @return false - */ - auto check_email_address(const QString& str) -> bool; - - /** - * @brief - * */ void sync_gen_key_algo_info(); diff --git a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp index b182e017..fd592733 100644 --- a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp +++ b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp @@ -66,6 +66,8 @@ SubkeyGenerateDialog::SubkeyGenerateDialog(int channel, GpgKeyPtr key, const auto min_date_time = QDateTime::currentDateTime().addDays(3); ui_->expireDateTimeEdit->setMinimumDateTime(min_date_time); + ui_->expireDateTimeEdit->setDateTime( + QDateTime::currentDateTime().addYears(2)); QSet<QString> algo_set; for (const auto& algo : supported_subkey_algos_) { diff --git a/src/ui/dialog/keypair_details/KeyNewUIDDialog.cpp b/src/ui/dialog/keypair_details/KeyNewUIDDialog.cpp index 6a6745da..37688b44 100644 --- a/src/ui/dialog/keypair_details/KeyNewUIDDialog.cpp +++ b/src/ui/dialog/keypair_details/KeyNewUIDDialog.cpp @@ -29,6 +29,7 @@ #include "KeyNewUIDDialog.h" #include "core/function/gpg/GpgUIDOperator.h" +#include "core/utils/CommonUtils.h" #include "ui/UISignalStation.h" namespace GpgFrontend::UI { @@ -81,14 +82,11 @@ void KeyNewUIDDialog::slot_create_new_uid() { QString buffer; QTextStream error_stream(&buffer); - /** - * check for errors in keygen dialog input - */ if ((name_->text()).size() < 5) { error_stream << " " << tr("Name must contain at least five characters.") << Qt::endl; } - if (email_->text().isEmpty() || !check_email_address(email_->text())) { + if (email_->text().isEmpty() || !IsEmailAddress(email_->text())) { error_stream << " " << tr("Please give a email address.") << Qt::endl; } auto error_string = error_stream.readAll(); @@ -117,7 +115,4 @@ void KeyNewUIDDialog::slot_create_new_uid() { } } -auto KeyNewUIDDialog::check_email_address(const QString& str) -> bool { - return re_email_.match(str).hasMatch(); -} } // namespace GpgFrontend::UI diff --git a/src/ui/dialog/keypair_details/KeyNewUIDDialog.h b/src/ui/dialog/keypair_details/KeyNewUIDDialog.h index f298a46b..f6ab93e5 100644 --- a/src/ui/dialog/keypair_details/KeyNewUIDDialog.h +++ b/src/ui/dialog/keypair_details/KeyNewUIDDialog.h @@ -74,17 +74,5 @@ class KeyNewUIDDialog : public GeneralDialog { QStringList error_messages_; ///< QLabel* error_label_{}; ///< - - QRegularExpression re_email_{ - R"((?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\]))"}; - - /** - * @brief - * - * @param str - * @return true - * @return false - */ - auto check_email_address(const QString& str) -> bool; }; } // namespace GpgFrontend::UI diff --git a/src/ui/dialog/keypair_details/KeySetExpireDateDialog.h b/src/ui/dialog/keypair_details/KeySetExpireDateDialog.h index b75339a0..55d09b4b 100644 --- a/src/ui/dialog/keypair_details/KeySetExpireDateDialog.h +++ b/src/ui/dialog/keypair_details/KeySetExpireDateDialog.h @@ -75,10 +75,10 @@ class KeySetExpireDateDialog : public GeneralDialog { */ void init(); - std::shared_ptr<Ui_ModifiedExpirationDateTime> ui_; ///< - int current_gpg_context_channel_; ///< - const GpgKeyPtr m_key_; ///< - const SubkeyId m_subkey_; ///< + QSharedPointer<Ui_ModifiedExpirationDateTime> ui_; ///< + int current_gpg_context_channel_; ///< + const GpgKeyPtr m_key_; ///< + const SubkeyId m_subkey_; ///< private slots: /** diff --git a/src/ui/dialog/settings/SettingsAppearance.h b/src/ui/dialog/settings/SettingsAppearance.h index 388234f7..fb50522c 100644 --- a/src/ui/dialog/settings/SettingsAppearance.h +++ b/src/ui/dialog/settings/SettingsAppearance.h @@ -58,7 +58,7 @@ class AppearanceTab : public QWidget { void ApplySettings(); private: - std::shared_ptr<Ui_AppearanceSettings> ui_; ///< + QSharedPointer<Ui_AppearanceSettings> ui_; ///< QButtonGroup* icon_style_group_; ///< QButtonGroup* icon_size_group_; diff --git a/src/ui/dialog/settings/SettingsGeneral.h b/src/ui/dialog/settings/SettingsGeneral.h index 2bd717d0..25cf7e41 100644 --- a/src/ui/dialog/settings/SettingsGeneral.h +++ b/src/ui/dialog/settings/SettingsGeneral.h @@ -80,9 +80,9 @@ class GeneralTab : public QWidget { void SignalDeepRestartNeeded(); private: - std::shared_ptr<Ui_GeneralSettings> ui_; ///< - QHash<QString, QString> lang_; ///< - QStringList key_ids_list_; ///< - KeyList* m_key_list_{}; ///< + QSharedPointer<Ui_GeneralSettings> ui_; ///< + QHash<QString, QString> lang_; ///< + QStringList key_ids_list_; ///< + KeyList* m_key_list_{}; ///< }; } // namespace GpgFrontend::UI diff --git a/src/ui/dialog/settings/SettingsKeyServer.h b/src/ui/dialog/settings/SettingsKeyServer.h index b280cf9d..133f69d2 100644 --- a/src/ui/dialog/settings/SettingsKeyServer.h +++ b/src/ui/dialog/settings/SettingsKeyServer.h @@ -61,7 +61,7 @@ class KeyserverTab : public QWidget { void ApplySettings(); private: - std::shared_ptr<Ui_KeyServerSettings> ui_; + QSharedPointer<Ui_KeyServerSettings> ui_; QString default_key_server_; QStringList key_server_str_list_; QMenu* popup_menu_{}; diff --git a/src/ui/dialog/settings/SettingsNetwork.h b/src/ui/dialog/settings/SettingsNetwork.h index 5d598a6c..a6dd613d 100644 --- a/src/ui/dialog/settings/SettingsNetwork.h +++ b/src/ui/dialog/settings/SettingsNetwork.h @@ -67,7 +67,7 @@ class NetworkTab : public QWidget { void slot_test_proxy_connection_result(); private: - std::shared_ptr<Ui_NetworkSettings> ui_; ///< + QSharedPointer<Ui_NetworkSettings> ui_; ///< QNetworkProxy::ProxyType proxy_type_ = QNetworkProxy::HttpProxy; ///< /** diff --git a/src/ui/model/GpgKeyTreeProxyModel.cpp b/src/ui/model/GpgKeyTreeProxyModel.cpp index bff18dd6..4dd645e9 100644 --- a/src/ui/model/GpgKeyTreeProxyModel.cpp +++ b/src/ui/model/GpgKeyTreeProxyModel.cpp @@ -59,9 +59,10 @@ auto GpgKeyTreeProxyModel::filterAcceptsRow( : nullptr; const auto *key = i->Key(); + assert(key != nullptr && key->IsGood()); LOG_D() << "get key: " << key->ID() - << "from channel: " << model_->GetGpgContextChannel(); - assert(key->IsGood()); + << "from channel: " << model_->GetGpgContextChannel() + << "fingerprint: " << key->Fingerprint(); if (!(display_mode_ & GpgKeyTreeDisplayMode::kPRIVATE_KEY) && key->IsPrivateKey()) { diff --git a/src/ui/thread/KeyServerImportTask.h b/src/ui/thread/KeyServerImportTask.h index 4e98a43a..84501ff1 100644 --- a/src/ui/thread/KeyServerImportTask.h +++ b/src/ui/thread/KeyServerImportTask.h @@ -65,7 +65,7 @@ class KeyServerImportTask : public Thread::Task { * @param result */ void SignalKeyServerImportResult(int, bool, QString, QByteArray, - std::shared_ptr<GpgImportInformation>); + QSharedPointer<GpgImportInformation>); private slots: diff --git a/src/ui/widgets/FilePage.h b/src/ui/widgets/FilePage.h index 7c90b62f..fbf99ae9 100644 --- a/src/ui/widgets/FilePage.h +++ b/src/ui/widgets/FilePage.h @@ -119,7 +119,7 @@ class FilePage : public QWidget { void keyPressEvent(QKeyEvent* event) override; private: - std::shared_ptr<Ui_FilePage> ui_; ///< + QSharedPointer<Ui_FilePage> ui_; ///< QCompleter* path_edit_completer_; ///< QStringListModel* path_complete_model_; ///< diff --git a/src/ui/widgets/InfoBoardWidget.h b/src/ui/widgets/InfoBoardWidget.h index c0416e2d..8fbd836a 100644 --- a/src/ui/widgets/InfoBoardWidget.h +++ b/src/ui/widgets/InfoBoardWidget.h @@ -122,7 +122,7 @@ class InfoBoardWidget : public QWidget { void slot_save(); private: - std::shared_ptr<Ui_InfoBoard> ui_; ///< + QSharedPointer<Ui_InfoBoard> ui_; ///< QTextEdit* m_text_page_{ nullptr}; ///< TextEdit associated to the notification diff --git a/src/ui/widgets/KeyList.h b/src/ui/widgets/KeyList.h index bb48c63b..b2bd8928 100644 --- a/src/ui/widgets/KeyList.h +++ b/src/ui/widgets/KeyList.h @@ -318,7 +318,7 @@ class KeyList : public QWidget { void slot_new_key_group(); private: - std::shared_ptr<Ui_KeyList> ui_; ///< + QSharedPointer<Ui_KeyList> ui_; ///< std::function<void(const GpgKey&, QWidget*)> m_action_ = nullptr; ///< int current_gpg_context_channel_; KeyMenuAbility menu_ability_ = KeyMenuAbility::kALL; ///< diff --git a/src/ui/widgets/KeyTreeView.cpp b/src/ui/widgets/KeyTreeView.cpp index a6fb23bf..2d4d8d8c 100644 --- a/src/ui/widgets/KeyTreeView.cpp +++ b/src/ui/widgets/KeyTreeView.cpp @@ -116,7 +116,7 @@ void KeyTreeView::init() { }); connect(UISignalStation::GetInstance(), - &UISignalStation::SignalKeyDatabaseRefresh, this, [=] { + &UISignalStation::SignalKeyDatabaseRefreshDone, this, [=] { model_ = QSharedPointer<GpgKeyTreeModel>::create( channel_, GpgAbstractKeyGetter::GetInstance(channel_).Fetch(), [](auto) { return false; }, this); @@ -143,11 +143,14 @@ void KeyTreeView::SetChannel(int channel) { } auto KeyTreeView::GetKeyByIndex(QModelIndex index) -> GpgAbstractKeyPtr { - auto* i = index.isValid() - ? static_cast<GpgKeyTreeItem*>(index.internalPointer()) + auto s_index = proxy_model_.mapToSource(index); + auto* i = s_index.isValid() + ? static_cast<GpgKeyTreeItem*>(s_index.internalPointer()) : nullptr; assert(i != nullptr); return i->SharedKey(); } + +void KeyTreeView::Refresh() { SetChannel(channel_); } } // namespace GpgFrontend::UI diff --git a/src/ui/widgets/KeyTreeView.h b/src/ui/widgets/KeyTreeView.h index af903273..b5a07f29 100644 --- a/src/ui/widgets/KeyTreeView.h +++ b/src/ui/widgets/KeyTreeView.h @@ -69,7 +69,7 @@ class KeyTreeView : public QTreeView { * @param index * @return GpgAbstractKeyPtr */ - static auto GetKeyByIndex(QModelIndex index) -> GpgAbstractKeyPtr; + auto GetKeyByIndex(QModelIndex index) -> GpgAbstractKeyPtr; /** * @brief Get the All Checked Key Ids object @@ -99,6 +99,12 @@ class KeyTreeView : public QTreeView { */ void SetChannel(int channel); + /** + * @brief + * + */ + void Refresh(); + protected: /** * @brief diff --git a/src/ui/widgets/PlainTextEditorPage.h b/src/ui/widgets/PlainTextEditorPage.h index 86ec0a56..8c4f9b12 100644 --- a/src/ui/widgets/PlainTextEditorPage.h +++ b/src/ui/widgets/PlainTextEditorPage.h @@ -116,7 +116,7 @@ class PlainTextEditorPage : public QWidget { void SignalUIBytesDisplayed(); protected: - std::shared_ptr<Ui_PlainTextEditor> ui_; ///< + QSharedPointer<Ui_PlainTextEditor> ui_; ///< private: QString full_file_path_; ///< The path to the file handled in the tab diff --git a/ui/GenerateCardKeyDialog.ui b/ui/GenerateCardKeyDialog.ui new file mode 100644 index 00000000..9e284ce4 --- /dev/null +++ b/ui/GenerateCardKeyDialog.ui @@ -0,0 +1,110 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>GenerateCardKeyDialog</class> + <widget class="QDialog" name="GenerateCardKeyDialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>508</width> + <height>395</height> + </rect> + </property> + <property name="windowTitle"> + <string>Card Key Generation</string> + </property> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <layout class="QGridLayout" name="gridLayout"> + <item row="1" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Name</string> + </property> + </widget> + </item> + <item row="4" column="0"> + <widget class="QLabel" name="label_4"> + <property name="text"> + <string>Expire Date</string> + </property> + </widget> + </item> + <item row="3" column="0"> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>Comment</string> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Email</string> + </property> + </widget> + </item> + <item row="1" column="2"> + <widget class="QLineEdit" name="nameEdit"/> + </item> + <item row="2" column="2"> + <widget class="QLineEdit" name="emailEdit"/> + </item> + <item row="5" column="0" colspan="3"> + <widget class="QCheckBox" name="nonExpireCheckBox"> + <property name="text"> + <string>Non Expire</string> + </property> + </widget> + </item> + <item row="3" column="2"> + <widget class="QLineEdit" name="commentEdit"/> + </item> + <item row="4" column="2"> + <widget class="QDateEdit" name="dateEdit"/> + </item> + </layout> + </item> + <item> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Orientation::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QLabel" name="errLabel"> + <property name="text"> + <string/> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="label_5"> + <property name="text"> + <string>Warning: This Operation will overwrite keys which exist on card!</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="generateButton"> + <property name="text"> + <string>Generate</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/ui/SmartCardControllerDialog.ui b/ui/SmartCardControllerDialog.ui index 07ec386d..476e93d4 100644 --- a/ui/SmartCardControllerDialog.ui +++ b/ui/SmartCardControllerDialog.ui @@ -174,7 +174,7 @@ <item> <widget class="QPushButton" name="generateKeysButton"> <property name="text"> - <string>Generate Keys</string> + <string>Generate Card Keys</string> </property> </widget> </item> |