diff options
Diffstat (limited to 'src')
41 files changed, 993 insertions, 352 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4ec07d66..fb0aecc2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -102,7 +102,7 @@ if (APPLICATION_BUILD) if (APPLE) set(RESOURCE_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Resources) elseif (LINUX AND NOT LINUX_INSTALL_SOFTWARE) - file(COPY ${CMAKE_SOURCE_DIR}/resource/gpgfrontend DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN) + file(COPY ${CMAKE_SOURCE_DIR}/resource/lfs/app-image/gpgfrontend DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN) set(RESOURCE_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/gpgfrontend/usr/share) else () set(RESOURCE_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) @@ -127,16 +127,16 @@ if (MULTI_LANG_SUPPORT) if (NOT GETTEXT_MSGFMT_EXECUTABLE OR NOT GETTEXT_XGETTEXT_EXECUTABLE) message(ERROR "msgfmt or xgettext not found. Translations will *not* be installed") - else (NOT GETTEXT_MSGFMT_EXECUTABLE) + else() message(STATUS "Setting target translations") add_custom_target(translations) - set(OUTPUT_POT_PATH ${CMAKE_SOURCE_DIR}/resource/locale/template/${PROJECT_NAME}.pot) + set(OUTPUT_POT_PATH ${CMAKE_SOURCE_DIR}/resource/lfs/locale/template/${PROJECT_NAME}.pot) add_custom_command( TARGET translations COMMAND find ${CMAKE_SOURCE_DIR}/src -iname \"*.cpp\" | xargs xgettext --package-name=${PROJECT_NAME} --copyright-holder=Saturneric --package-version=${PROJECT_VERSION} [email protected] --add-comments="/*" --c++ -k_ -o ${OUTPUT_POT_PATH} ) - file(GLOB ALL_PO_FILES ${CMAKE_SOURCE_DIR}/resource/locale/po/*.po) + file(GLOB ALL_PO_FILES ${CMAKE_SOURCE_DIR}/resource/lfs/locale/po/*.po) SET(GMO_FILES) foreach (_poFile ${ALL_PO_FILES}) @@ -171,7 +171,7 @@ endif () if (APPLICATION_BUILD) # Copy Resource Files file(COPY ${CMAKE_SOURCE_DIR}/resource/css DESTINATION ${RESOURCE_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN) - file(COPY ${CMAKE_SOURCE_DIR}/resource/icons DESTINATION ${RESOURCE_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN) + file(COPY ${CMAKE_SOURCE_DIR}/resource/lfs/icons DESTINATION ${RESOURCE_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN) file(COPY ${CMAKE_SOURCE_DIR}/TRANSLATORS DESTINATION ${RESOURCE_OUTPUT_DIRECTORY} FOLLOW_SYMLINK_CHAIN) if (GPG_STANDALONE_MODE) file(COPY ${CMAKE_SOURCE_DIR}/resource/gpg1.4 DESTINATION ${RESOURCE_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN) @@ -419,12 +419,17 @@ if (APPLICATION_BUILD) # option for sandbox mode, still under test if(GPGFRONTEND_XOCDE_ENABLE_SANDBOX) + message(STATUS "Build Application With App Sandbox") set(CUSTOM_ATTRIBUTE_ENABLE_APP_SANDBOX "Yes") add_custom_command(TARGET ${AppName} POST_BUILD COMMAND /bin/cp -rf ${CMAKE_SOURCE_DIR}/resource/lfs/macOS/GnuPG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_BUILD_TYPE}/${AppName}.app/Contents/ WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMENT "Copying Buddled GnuPG into App Bundle Resource") + set_target_properties(${AppName} PROPERTIES + XCODE_ATTRIBUTE_CODE_SIGN_ENTITLEMENTS "${CMAKE_SOURCE_DIR}/GpgFrontend.entitlements" + ) else() + message(STATUS "Build Application Without App Sandbox") set(CUSTOM_ATTRIBUTE_ENABLE_APP_SANDBOX "No") endif() @@ -434,7 +439,6 @@ if (APPLICATION_BUILD) XCODE_ATTRIBUTE_OTHER_CODE_SIGN_FLAGS "--deep --entitlements ${CMAKE_SOURCE_DIR}/resource/plist/entitlement.plist" XCODE_ATTRIBUTE_ENABLE_APP_SANDBOX "${CUSTOM_ATTRIBUTE_ENABLE_APP_SANDBOX}" XCODE_ATTRIBUTE_ENABLE_HARDENED_RUNTIME "Yes" - XCODE_ATTRIBUTE_CODE_SIGN_ENTITLEMENTS "${CMAKE_SOURCE_DIR}/GpgFrontend.entitlements" XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "${GPGFRONTEND_XOCDE_CODE_SIGN_IDENTITY}" ) else () @@ -510,9 +514,9 @@ if (LINUX AND LINUX_INSTALL_SOFTWARE) DESTINATION /usr/share/metainfo/) install(DIRECTORY ${CMAKE_SOURCE_DIR}/resource/desktop/ DESTINATION /usr/share/applications/) - install(DIRECTORY ${CMAKE_SOURCE_DIR}/resource/pixmaps/ + install(DIRECTORY ${CMAKE_SOURCE_DIR}/resource/lfs/pixmaps/ DESTINATION /usr/share/pixmaps/) - install(DIRECTORY ${CMAKE_SOURCE_DIR}/resource/hicolor/ + install(DIRECTORY ${CMAKE_SOURCE_DIR}/resource/lfs/hicolor/ DESTINATION /usr/share/icons/hicolor/) endif () if (MULTI_LANG_SUPPORT) diff --git a/src/SECURITY.md b/src/SECURITY.md new file mode 100644 index 00000000..0d6b2add --- /dev/null +++ b/src/SECURITY.md @@ -0,0 +1,43 @@ +# Security Policy + +## Supported Versions + +The application white check mark is still in support, without it means there +version will no longer have a update including security fixture. That's beacuse +currently I have a job and a hard learning plain, which means I don't have too +much time to dealing with this project now, sincerely, I am sorry for that. +Maybe this situation will get better in the future. So it is recommand to use +the latest version. + +| Version | Supported | +| ------- | ------------------ | +| 1.x.x | :x: | +| 2.x.x | :x: | +| 2.1.x | :white_check_mark: | + +## Platform & Library Support + +According to security concern and my limiting time to contributing, GpgFrontend +will gradually drop the support of some old platforms. + +Starting from v1.0.0, x32 operating system is no longer support. Mainly because +I have limit time and the fact that x32 machime is getting less and less in the +pc market, so I plan to stop spending tons of time dealing with lots of complex +problem which might made me crazy. x64 is just enough, or you can use gpg4usb. + +Starting from v2.0.1, Ubuntu 16.04 is no longer support. Mainly because this +Ubuntu 16.04 LTS's life time had come into an end at during that time. Keep +using this version of Ubuntu is not safty anymore. + +Starting from v2.1.0, macOS 10.15 is no longer support. Mainly because this +system will no longer support by github action in the near future. Also, I think +this version is old enough to drop it out, and Apple might not longer to support +it soon. + +## Reporting a Vulnerability + +If you want to report a vulnerability, it's not good to raise an issue in +public. You should send an email to [email protected] to contract me. In the email, +You can describe the vulnerability you have just discovered and request a +hot-fix. Or you can just provide a git patch to fix it and send it to me using +the email. This is a better way to solve the vulnerability as quick as possible.
\ No newline at end of file diff --git a/src/core/GpgContext.cpp b/src/core/GpgContext.cpp index a5213134..f8dbebc6 100644 --- a/src/core/GpgContext.cpp +++ b/src/core/GpgContext.cpp @@ -40,8 +40,10 @@ #include "core/GpgModel.h" #include "core/common/CoreCommonUtil.h" #include "core/function/CoreSignalStation.h" +#include "core/function/GlobalSettingStation.h" #include "core/function/gpg/GpgCommandExecutor.h" #include "core/thread/TaskRunnerGetter.h" +#include "spdlog/spdlog.h" #include "thread/Task.h" #ifdef _WIN32 @@ -58,20 +60,12 @@ GpgContext::GpgContext(int channel) * Set up gpgme-context, set paths to app-run path */ GpgContext::GpgContext(const GpgContextInitArgs &args) : args_(args) { - static bool _first = true; - - if (_first) { - /* Initialize the locale environment. */ - SPDLOG_DEBUG("locale: {}", setlocale(LC_CTYPE, nullptr)); - info_.GpgMEVersion = gpgme_check_version(nullptr); - gpgme_set_locale(nullptr, LC_CTYPE, setlocale(LC_CTYPE, nullptr)); -#ifdef LC_MESSAGES - gpgme_set_locale(nullptr, LC_MESSAGES, setlocale(LC_MESSAGES, nullptr)); -#endif - _first = false; - } - gpgme_ctx_t _p_ctx; + + // get gpgme library version + info_.GpgMEVersion = gpgme_check_version(nullptr); + + // create a new context check_gpg_error(gpgme_new(&_p_ctx)); _ctx_ref = CtxRefHandler(_p_ctx); @@ -83,6 +77,17 @@ GpgContext::GpgContext(const GpgContextInitArgs &args) : args_(args) { assert(check_gpg_error_2_err_code(err) == GPG_ERR_NO_ERROR); } + // set context offline mode + SPDLOG_DEBUG("gpg context offline mode: {}", args_.offline_mode); + gpgme_set_offline(_ctx_ref.get(), args_.offline_mode ? 1 : 0); + + // set option auto import missing key + // invalid at offline mode + SPDLOG_DEBUG("gpg context auto import missing key: {}", args_.offline_mode); + if (!args.offline_mode && args.auto_import_missing_key) + check_gpg_error(gpgme_set_ctx_flag(_ctx_ref.get(), "auto-key-import", "1")); + + // get engine info auto engine_info = gpgme_ctx_get_engine_info(*this); // Check ENV before running bool check_passed = false, find_openpgp = false, find_gpgconf = false, @@ -219,8 +224,22 @@ void GpgContext::post_init_ctx() { // preload info auto &info = GetInfo(); - // listen passphrase input event - SetPassphraseCb(custom_passphrase_cb); + auto &settings = GlobalSettingStation::GetInstance().GetUISettings(); + + bool use_pinentry_as_password_input_dialog = false; + try { + use_pinentry_as_password_input_dialog = + settings.lookup("general.use_pinentry_as_password_input_dialog"); + } catch (...) { + SPDLOG_ERROR( + "setting operation error: use_pinentry_as_password_input_dialog"); + } + + // use custom qt dialog to replace pinentry + if (!use_pinentry_as_password_input_dialog) { + SetPassphraseCb(custom_passphrase_cb); + } + connect(this, &GpgContext::SignalNeedUserInputPassphrase, CoreSignalStation::GetInstance(), &CoreSignalStation::SignalNeedUserInputPassphrase); @@ -372,6 +391,16 @@ const GpgInfo &GpgContext::GetInfo(bool refresh) { auto component_name = info_split_list[0]; auto component_desc = info_split_list[1]; auto component_path = info_split_list[2]; + + boost::algorithm::trim(component_name); + boost::algorithm::trim(component_desc); + boost::algorithm::trim(component_path); + +#ifdef WINDOWS + // replace some special substrings on windows platform + boost::replace_all(component_path, "%3a", ":"); +#endif + auto binary_checksum = check_binary_chacksum(component_path); SPDLOG_DEBUG( @@ -386,13 +415,13 @@ const GpgInfo &GpgContext::GetInfo(bool refresh) { version = info_.GnupgVersion; } if (component_name == "gpg-agent") { - info_.GpgAgentPath = info_split_list[2]; + info_.GpgAgentPath = component_path; } if (component_name == "dirmngr") { - info_.DirmngrPath = info_split_list[2]; + info_.DirmngrPath = component_path; } if (component_name == "keyboxd") { - info_.KeyboxdPath = info_split_list[2]; + info_.KeyboxdPath = component_path; } { @@ -436,16 +465,25 @@ const GpgInfo &GpgContext::GetInfo(bool refresh) { if (info_split_list.size() != 2) continue; + auto configuration_name = info_split_list[0]; + auto configuration_value = info_split_list[1]; + boost::algorithm::trim(configuration_name); + boost::algorithm::trim(configuration_value); + +#ifdef WINDOWS + // replace some special substrings on windows platform + boost::replace_all(configuration_value, "%3a", ":"); +#endif + // record gnupg home path - if (info_split_list[0] == "homedir") { + if (configuration_name == "homedir") { info_.GnuPGHomePath = info_split_list[1]; } - auto configuration_name = info_split_list[0]; { // try lock std::unique_lock lock(info_.Lock); - configurations_info[configuration_name] = {info_split_list[1]}; + configurations_info[configuration_name] = {configuration_value}; } } }); @@ -489,12 +527,19 @@ const GpgInfo &GpgContext::GetInfo(bool refresh) { if (info_split_list.size() != 6) continue; auto configuration_name = info_split_list[0]; + boost::algorithm::trim(configuration_name); { // try lock std::unique_lock lock(info_.Lock); options_info[configuration_name] = { info_split_list[1], info_split_list[2], info_split_list[3], info_split_list[4], info_split_list[5]}; + + boost::algorithm::trim(options_info[configuration_name][0]); + boost::algorithm::trim(options_info[configuration_name][1]); + boost::algorithm::trim(options_info[configuration_name][2]); + boost::algorithm::trim(options_info[configuration_name][3]); + boost::algorithm::trim(options_info[configuration_name][4]); } } }); @@ -540,6 +585,7 @@ const GpgInfo &GpgContext::GetInfo(bool refresh) { if (info_split_list.size() != 10) continue; auto configuration_name = info_split_list[0]; + boost::algorithm::trim(configuration_name); { // try lock std::unique_lock lock(info_.Lock); @@ -547,6 +593,25 @@ const GpgInfo &GpgContext::GetInfo(bool refresh) { info_split_list[1], info_split_list[2], info_split_list[3], info_split_list[4], info_split_list[5], info_split_list[6], info_split_list[7], info_split_list[8], info_split_list[9]}; + + boost::algorithm::trim( + available_options_info[configuration_name][0]); + boost::algorithm::trim( + available_options_info[configuration_name][1]); + boost::algorithm::trim( + available_options_info[configuration_name][2]); + boost::algorithm::trim( + available_options_info[configuration_name][3]); + boost::algorithm::trim( + available_options_info[configuration_name][4]); + boost::algorithm::trim( + available_options_info[configuration_name][5]); + boost::algorithm::trim( + available_options_info[configuration_name][6]); + boost::algorithm::trim( + available_options_info[configuration_name][7]); + boost::algorithm::trim( + available_options_info[configuration_name][8]); } } }); @@ -561,20 +626,33 @@ const GpgInfo &GpgContext::GetInfo(bool refresh) { std::optional<std::string> GpgContext::check_binary_chacksum( std::filesystem::path path) { - QFile f(QString::fromStdString(path.u8string())); - if (!f.open(QFile::ReadOnly)) return {}; + // check file info and access rights + QFileInfo info(QString::fromStdString(path.u8string())); + if (!info.exists() || !info.isFile() || !info.isReadable()) { + SPDLOG_ERROR("get info for file {} error, exists: {}", + info.filePath().toStdString(), info.exists()); + return {}; + } + + // open and read file + QFile f(info.filePath()); + if (!f.open(QIODevice::ReadOnly)) { + SPDLOG_ERROR("open {} to calculate check sum error: {}", path.u8string(), + f.errorString().toStdString()); + return {}; + } // read all data from file auto buffer = f.readAll(); f.close(); - auto hash_md5 = QCryptographicHash(QCryptographicHash::Md5); + auto hash_sha = QCryptographicHash(QCryptographicHash::Sha256); // md5 - hash_md5.addData(buffer); - auto md5 = hash_md5.result().toHex().toStdString(); - SPDLOG_DEBUG("md5 {}", md5); + hash_sha.addData(buffer); + auto sha = hash_sha.result().toHex().toStdString(); + SPDLOG_DEBUG("checksum for file {} is {}", path.u8string(), sha); - return md5.substr(0, 6); + return sha.substr(0, 6); } void GpgContext::_ctx_ref_deleter::operator()(gpgme_ctx_t _ctx) { diff --git a/src/core/GpgContext.h b/src/core/GpgContext.h index 384271a6..2ff87e6b 100644 --- a/src/core/GpgContext.h +++ b/src/core/GpgContext.h @@ -51,6 +51,8 @@ struct GpgContextInitArgs { std::string gpg_path = {}; bool test_mode = false; bool ascii = true; + bool offline_mode = false; + bool auto_import_missing_key = false; GpgContextInitArgs() = default; }; diff --git a/src/core/GpgCoreInit.cpp b/src/core/GpgCoreInit.cpp index 840b2b87..9395bac7 100644 --- a/src/core/GpgCoreInit.cpp +++ b/src/core/GpgCoreInit.cpp @@ -36,6 +36,10 @@ #include "core/GpgContext.h" #include "core/function/GlobalSettingStation.h" #include "function/gpg/GpgAdvancedOperator.h" +#include "spdlog/spdlog.h" +#include "thread/Task.h" +#include "thread/TaskRunner.h" +#include "thread/TaskRunnerGetter.h" namespace GpgFrontend { @@ -93,12 +97,38 @@ void ShutdownCoreLoggingSystem() { void ResetGpgFrontendCore() { reset_gpgfrontend_core(); } void init_gpgfrontend_core() { - // read from settings file + /* Initialize the locale environment. */ + SPDLOG_DEBUG("locale: {}", setlocale(LC_CTYPE, nullptr)); + // init gpgme subsystem + gpgme_check_version(nullptr); + gpgme_set_locale(nullptr, LC_CTYPE, setlocale(LC_CTYPE, nullptr)); +#ifdef LC_MESSAGES + gpgme_set_locale(nullptr, LC_MESSAGES, setlocale(LC_MESSAGES, nullptr)); +#endif + + // get settings + auto& settings = GlobalSettingStation::GetInstance().GetUISettings(); + + // read settings + bool forbid_all_gnupg_connection = false; + try { + forbid_all_gnupg_connection = + settings.lookup("network.forbid_all_gnupg_connection"); + } catch (...) { + SPDLOG_ERROR("setting operation error: forbid_all_gnupg_connection"); + } + + bool auto_import_missing_key = false; + try { + auto_import_missing_key = + settings.lookup("network.auto_import_missing_key"); + } catch (...) { + SPDLOG_ERROR("setting operation error: auto_import_missing_key"); + } + // read from settings file bool use_custom_key_database_path = false; try { - auto& settings = - GpgFrontend::GlobalSettingStation::GetInstance().GetUISettings(); use_custom_key_database_path = settings.lookup("general.use_custom_key_database_path"); } catch (...) { @@ -110,8 +140,6 @@ void init_gpgfrontend_core() { std::string custom_key_database_path; try { - auto& settings = - GpgFrontend::GlobalSettingStation::GetInstance().GetUISettings(); custom_key_database_path = static_cast<std::string>( settings.lookup("general.custom_key_database_path")); @@ -123,7 +151,7 @@ void init_gpgfrontend_core() { custom_key_database_path); // init default channel - GpgFrontend::GpgContext::CreateInstance( + auto& default_ctx = GpgFrontend::GpgContext::CreateInstance( GPGFRONTEND_DEFAULT_CHANNEL, [=]() -> std::unique_ptr<ChannelObject> { GpgFrontend::GpgContextInitArgs args; @@ -132,23 +160,46 @@ void init_gpgfrontend_core() { args.db_path = custom_key_database_path; } - return std::unique_ptr<ChannelObject>(new GpgContext(args)); - }); - - // init non-ascii channel - GpgFrontend::GpgContext::CreateInstance( - GPGFRONTEND_NON_ASCII_CHANNEL, [=]() -> std::unique_ptr<ChannelObject> { - GpgFrontend::GpgContextInitArgs args; - args.ascii = false; - - // set key database path - if (use_custom_key_database_path && !custom_key_database_path.empty()) { - args.db_path = custom_key_database_path; - } + args.offline_mode = forbid_all_gnupg_connection; + args.auto_import_missing_key = auto_import_missing_key; return std::unique_ptr<ChannelObject>(new GpgContext(args)); }); + // exit if failed + if (!default_ctx.good()) { + SPDLOG_ERROR("default gpgme context init error, exit."); + QCoreApplication::exit(); + }; + + // async init no-ascii channel + Thread::TaskRunnerGetter::GetInstance() + .GetTaskRunner(Thread::TaskRunnerGetter::kTaskRunnerType_GPG) + ->PostTask( + new Thread::Task([=](Thread::Task::DataObjectPtr data_obj) -> int { + // init non-ascii channel + auto& ctx = GpgFrontend::GpgContext::CreateInstance( + GPGFRONTEND_NON_ASCII_CHANNEL, + [=]() -> std::unique_ptr<ChannelObject> { + GpgFrontend::GpgContextInitArgs args; + args.ascii = false; + + // set key database path + if (use_custom_key_database_path && + !custom_key_database_path.empty()) { + args.db_path = custom_key_database_path; + } + + args.offline_mode = forbid_all_gnupg_connection; + args.auto_import_missing_key = auto_import_missing_key; + + return std::unique_ptr<ChannelObject>(new GpgContext(args)); + }); + if (!ctx.good()) SPDLOG_ERROR("no-ascii channel init error"); + + return ctx.good() ? 0 : -1; + })); + // try to restart all components GpgFrontend::GpgAdvancedOperator::GetInstance().RestartGpgComponents(); } diff --git a/src/core/function/ArchiveFileOperator.cpp b/src/core/function/ArchiveFileOperator.cpp index 04c9326f..8aad0500 100644 --- a/src/core/function/ArchiveFileOperator.cpp +++ b/src/core/function/ArchiveFileOperator.cpp @@ -136,8 +136,6 @@ void GpgFrontend::ArchiveFileOperator::CreateArchive( } for (;;) { - bool needcr = false; - entry = archive_entry_new(); r = archive_read_next_header2(disk, entry); @@ -149,15 +147,6 @@ void GpgFrontend::ArchiveFileOperator::CreateArchive( } archive_read_disk_descend(disk); -#ifdef WINDOWS - auto entry_path = - QString::fromStdWString(std::wstring(archive_entry_pathname_w(entry))) - .toUtf8() - .toStdString(); -#else - auto entry_path = std::string(archive_entry_pathname_utf8(entry)); -#endif - SPDLOG_DEBUG("Adding: {} size: {} bytes: {} file type: {}", archive_entry_pathname_utf8(entry), archive_entry_size(entry), archive_entry_filetype(entry)); @@ -201,7 +190,6 @@ void GpgFrontend::ArchiveFileOperator::ExtractArchive( struct archive *a; struct archive *ext; struct archive_entry *entry; - int r; a = archive_read_new(); ext = archive_write_disk_new(); @@ -241,8 +229,9 @@ void GpgFrontend::ArchiveFileOperator::ExtractArchive( archive_error_string(a)); throw std::runtime_error("archive_read_open_filename() failed"); } + for (;;) { - r = archive_read_next_header(a, &entry); + int r = archive_read_next_header(a, &entry); if (r == ARCHIVE_EOF) break; if (r != ARCHIVE_OK) { SPDLOG_ERROR("archive_read_next_header() failed: {}", diff --git a/src/core/function/CharsetOperator.cpp b/src/core/function/CharsetOperator.cpp index 0e40e317..72c5e72b 100644 --- a/src/core/function/CharsetOperator.cpp +++ b/src/core/function/CharsetOperator.cpp @@ -117,12 +117,10 @@ bool GpgFrontend::CharsetOperator::Convert2Utf8(const std::string &buffer, if (status == U_BUFFER_OVERFLOW_ERROR) { status = U_ZERO_ERROR; - target_limit = target_capacity + 1; out_buffer.clear(); out_buffer.resize(target_capacity); - target_capacity = - ucnv_convert(from_encode.c_str(), to_encode.c_str(), out_buffer.data(), - out_buffer.size(), buffer.data(), buffer.size(), &status); + ucnv_convert(from_encode.c_str(), to_encode.c_str(), out_buffer.data(), + out_buffer.size(), buffer.data(), buffer.size(), &status); } if (U_FAILURE(status)) { diff --git a/src/core/function/aes/aes_ssl_cbc.cpp b/src/core/function/aes/aes_ssl_cbc.cpp index 88a54baa..3aa80ef5 100644 --- a/src/core/function/aes/aes_ssl_cbc.cpp +++ b/src/core/function/aes/aes_ssl_cbc.cpp @@ -59,7 +59,7 @@ uint8_t *aes_256_cbc_encrypt(EVP_CIPHER_CTX *e, uint8_t *plaintext, int *len) { /* max ciphertext len for a n bytes of plaintext is n + AES_BLOCK_SIZE -1 * bytes */ int c_len = *len + AES_BLOCK_SIZE, f_len = 0; - auto *ciphertext = (uint8_t *)malloc(c_len); + auto *ciphertext = static_cast<uint8_t *>(malloc(c_len)); /* allows reusing of 'e' for multiple encryption cycles */ EVP_EncryptInit_ex(e, nullptr, nullptr, nullptr, nullptr); @@ -86,7 +86,7 @@ uint8_t *aes_256_cbc_encrypt(EVP_CIPHER_CTX *e, uint8_t *plaintext, int *len) { uint8_t *aes_256_cbc_decrypt(EVP_CIPHER_CTX *e, uint8_t *ciphertext, int *len) { /* plaintext will always be equal to or lesser than length of ciphertext*/ int p_len = *len, f_len = 0; - auto *plaintext = (uint8_t *)malloc(p_len); + auto *plaintext = static_cast<uint8_t *>(malloc(p_len)); EVP_DecryptInit_ex(e, nullptr, nullptr, nullptr, nullptr); EVP_DecryptUpdate(e, plaintext, &p_len, ciphertext, *len); diff --git a/src/core/model/GpgData.cpp b/src/core/model/GpgData.cpp index 5aa95dc6..05f61a46 100644 --- a/src/core/model/GpgData.cpp +++ b/src/core/model/GpgData.cpp @@ -40,7 +40,8 @@ GpgFrontend::GpgData::GpgData() { GpgFrontend::GpgData::GpgData(void* buffer, size_t size, bool copy) { gpgme_data_t data; - auto err = gpgme_data_new_from_mem(&data, (const char*)buffer, size, copy); + auto err = gpgme_data_new_from_mem(&data, static_cast<const char*>(buffer), + size, copy); assert(gpgme_err_code(err) == GPG_ERR_NO_ERROR); data_ref_ = std::unique_ptr<struct gpgme_data, _data_ref_deleter>(data); diff --git a/src/core/thread/Task.cpp b/src/core/thread/Task.cpp index f3c6ae86..7173b69e 100644 --- a/src/core/thread/Task.cpp +++ b/src/core/thread/Task.cpp @@ -218,7 +218,7 @@ void GpgFrontend::Thread::Task::DataObject::free_heap_ptr(Destructor *ptr) { if (ptr->destroy != nullptr) { ptr->destroy(ptr->p_obj); } - free((void *)ptr->p_obj); + free(const_cast<void *>(ptr->p_obj)); delete ptr; } diff --git a/src/main.cpp b/src/main.cpp index 98c02a0e..6b0eb727 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -126,6 +126,7 @@ int main(int argc, char* argv[]) { * with changed translation when settings change. */ int return_from_event_loop_code; + int restart_count = 0; do { do { @@ -154,16 +155,20 @@ int main(int argc, char* argv[]) { return_from_event_loop_code = CRASH_CODE; } - SPDLOG_DEBUG("restart loop refresh, event loop code: {}", - return_from_event_loop_code); - } while (return_from_event_loop_code == RESTART_CODE); + restart_count++; + + SPDLOG_DEBUG( + "restart loop refresh, event loop code: {}, restart count: {}", + return_from_event_loop_code, restart_count); + } while (return_from_event_loop_code == RESTART_CODE && restart_count < 2); if (return_from_event_loop_code == DEEP_RESTART_CODE || return_from_event_loop_code == CRASH_CODE) { // reset core GpgFrontend::ResetGpgFrontendCore(); // log for debug - SPDLOG_DEBUG("deep restart or cash loop refresh"); + SPDLOG_DEBUG("deep restart or cash loop refresh, restart count: {}", + restart_count); } else { // log for debug SPDLOG_DEBUG("need to close application, event loop code: {}", @@ -171,9 +176,9 @@ int main(int argc, char* argv[]) { } // deep restart mode - } while (return_from_event_loop_code == DEEP_RESTART_CODE || - return_from_event_loop_code == CRASH_CODE); - + } while ((return_from_event_loop_code == DEEP_RESTART_CODE || + return_from_event_loop_code == CRASH_CODE) && + restart_count < 3); // shutdown the logging system for ui GpgFrontend::UI::ShutdownUILoggingSystem(); @@ -181,8 +186,6 @@ int main(int argc, char* argv[]) { // shutdown the logging system for core GpgFrontend::ShutdownCoreLoggingSystem(); - - // log for debug SPDLOG_INFO("GpgFrontend about to exit."); diff --git a/src/ui/GpgFrontendApplication.cpp b/src/ui/GpgFrontendApplication.cpp index 1b2bb9ad..3697adde 100644 --- a/src/ui/GpgFrontendApplication.cpp +++ b/src/ui/GpgFrontendApplication.cpp @@ -59,9 +59,11 @@ GpgFrontendApplication *GpgFrontendApplication::GetInstance(int argc, if (new_instance || !instance) { if (instance != nullptr) { + SPDLOG_DEBUG("old application exists, quitting..."); instance->quit(); delete instance; } + SPDLOG_DEBUG("creating new application instance, argc: {}", argc); instance = new GpgFrontendApplication(static_argc, static_argv); } return instance; diff --git a/src/ui/GpgFrontendUIInit.cpp b/src/ui/GpgFrontendUIInit.cpp index 6e41f81f..b90493a5 100644 --- a/src/ui/GpgFrontendUIInit.cpp +++ b/src/ui/GpgFrontendUIInit.cpp @@ -71,6 +71,63 @@ void InitGpgFrontendUI(QApplication* app) { // init common utils CommonUtils::GetInstance(); + // application proxy configure + + auto& settings = GlobalSettingStation::GetInstance().GetUISettings(); + bool proxy_enable = false; + try { + proxy_enable = settings.lookup("proxy.enable"); + } catch (...) { + SPDLOG_ERROR("setting operation error: proxy_enable"); + } + SPDLOG_DEBUG("loading proxy configure, proxy_enable: {}", proxy_enable); + + // if enable proxy for application + if (proxy_enable) { + try { + std::string proxy_type = settings.lookup("proxy.proxy_type"); + std::string proxy_host = settings.lookup("proxy.proxy_host"); + int proxy_port = settings.lookup("proxy.port"); + std::string proxy_username = settings.lookup("proxy.username"); + std::string proxy_password = settings.lookup("proxy.password"); + + SPDLOG_DEBUG("proxy settings: type {}, host {}, port: {}", proxy_type, + proxy_host, proxy_port); + + QNetworkProxy::ProxyType proxy_type_qt = QNetworkProxy::NoProxy; + if (proxy_type == "HTTP") { + proxy_type_qt = QNetworkProxy::HttpProxy; + } else if (proxy_type == "Socks5") { + proxy_type_qt = QNetworkProxy::Socks5Proxy; + } else { + proxy_type_qt = QNetworkProxy::DefaultProxy; + } + + // create proxy object and apply settings + QNetworkProxy proxy; + if (proxy_type_qt != QNetworkProxy::DefaultProxy) { + proxy.setType(proxy_type_qt); + proxy.setHostName(QString::fromStdString(proxy_host)); + proxy.setPort(proxy_port); + if (!proxy_username.empty()) + proxy.setUser(QString::fromStdString(proxy_username)); + if (!proxy_password.empty()) + proxy.setPassword(QString::fromStdString(proxy_password)); + } else { + proxy.setType(proxy_type_qt); + } + QNetworkProxy::setApplicationProxy(proxy); + + } catch (...) { + SPDLOG_ERROR("setting operation error: proxy setings"); + // no proxy by default + QNetworkProxy::setApplicationProxy(QNetworkProxy::NoProxy); + } + } else { + // no proxy by default + QNetworkProxy::setApplicationProxy(QNetworkProxy::NoProxy); + } + // create the thread to load the gpg context auto* init_ctx_task = new Thread::CtxCheckTask(); @@ -213,7 +270,7 @@ void init_locale() { #ifndef WINDOWS if (!lang.empty()) { - std::string lc = lang.empty() ? "" : lang + ".UTF-8"; + std::string lc = lang + ".UTF-8"; // set LC_ALL auto* locale_name = setlocale(LC_ALL, lc.c_str()); @@ -229,7 +286,7 @@ void init_locale() { } #else if (!lang.empty()) { - std::string lc = lang.empty() ? "" : lang; + std::string lc = lang; // set LC_ALL auto* locale_name = setlocale(LC_ALL, lc.c_str()); diff --git a/src/ui/UserInterfaceUtils.cpp b/src/ui/UserInterfaceUtils.cpp index f944e037..5a11e119 100644 --- a/src/ui/UserInterfaceUtils.cpp +++ b/src/ui/UserInterfaceUtils.cpp @@ -299,38 +299,36 @@ void CommonUtils::SlotExecuteGpgCommand( void CommonUtils::SlotImportKeyFromKeyServer( const KeyIdArgsList &key_ids, const ImportCallbackFunctiopn &callback) { + // target key server that we need to import key from it std::string target_keyserver; - if (target_keyserver.empty()) { - try { - auto &settings = GlobalSettingStation::GetInstance().GetUISettings(); - SettingsObject key_server_json("key_server"); + try { + auto &settings = GlobalSettingStation::GetInstance().GetUISettings(); + SettingsObject key_server_json("key_server"); - // get key servers from settings - const auto key_server_list = - key_server_json.Check("server_list", nlohmann::json::array()); - if (key_server_list.empty()) { - throw std::runtime_error("No key server configured"); - } + // get key servers from settings + const auto key_server_list = + key_server_json.Check("server_list", nlohmann::json::array()); + if (key_server_list.empty()) { + throw std::runtime_error("No key server configured"); + } - const int target_key_server_index = - key_server_json.Check("default_server", 0); - if (target_key_server_index >= key_server_list.size()) { - throw std::runtime_error("default_server index out of range"); - } - target_keyserver = - key_server_list[target_key_server_index].get<std::string>(); - - SPDLOG_DEBUG("set target key server to default Key Server: {}", - target_keyserver); - } catch (...) { - SPDLOG_ERROR(_("Cannot read default_keyserver From Settings")); - QMessageBox::critical( - nullptr, _("Default Keyserver Not Found"), - _("Cannot read default keyserver from your settings, " - "please set a default keyserver first")); - return; + const int target_key_server_index = + key_server_json.Check("default_server", 0); + if (target_key_server_index >= key_server_list.size()) { + throw std::runtime_error("default_server index out of range"); } + target_keyserver = + key_server_list[target_key_server_index].get<std::string>(); + + SPDLOG_DEBUG("set target key server to default Key Server: {}", + target_keyserver); + } catch (...) { + SPDLOG_ERROR(_("Cannot read default_keyserver From Settings")); + QMessageBox::critical(nullptr, _("Default Keyserver Not Found"), + _("Cannot read default keyserver from your settings, " + "please set a default keyserver first")); + return; } auto thread = QThread::create([target_keyserver, key_ids, callback]() { diff --git a/src/ui/dialog/GeneralDialog.cpp b/src/ui/dialog/GeneralDialog.cpp index 9367aa44..90c56b8a 100644 --- a/src/ui/dialog/GeneralDialog.cpp +++ b/src/ui/dialog/GeneralDialog.cpp @@ -57,53 +57,17 @@ void GpgFrontend::UI::GeneralDialog::slot_restore_settings() noexcept { size_ = {width, height}; - if (this->parent() != nullptr) { - QPoint parent_pos = {0, 0}; - QSize parent_size = {0, 0}; - - auto *parent_widget = qobject_cast<QWidget *>(this->parent()); - if (parent_widget != nullptr) { - parent_pos = parent_widget->pos(); - parent_size = parent_widget->size(); - } - - auto *parent_dialog = qobject_cast<QDialog *>(this->parent()); - if (parent_dialog != nullptr) { - parent_pos = parent_dialog->pos(); - parent_size = parent_dialog->size(); - } - - auto *parent_window = qobject_cast<QMainWindow *>(this->parent()); - if (parent_window != nullptr) { - parent_pos = parent_window->pos(); - parent_size = parent_window->size(); - } - - SPDLOG_DEBUG("parent pos x: {} y: {}", parent_pos.x(), parent_pos.y()); - - SPDLOG_DEBUG("parent size width: {} height: {}", parent_size.width(), - parent_size.height()); - - SPDLOG_DEBUG("this dialog size width: {} height: {}", size_.width(), - size_.height()); - - if (parent_pos != QPoint{0, 0}) { - QPoint parent_center{parent_pos.x() + parent_size.width() / 2, - parent_pos.y() + parent_size.height() / 2}; - - pos_ = {parent_center.x() - size_.width() / 2, - parent_center.y() - size_.height() / 2}; - - // record parent_pos_ - this->parent_pos_ = parent_pos; - this->parent_size_ = parent_size; - } + // check for valid + if (!pos_.isNull() && pos_.x() > 50 && pos_.y() > 50 && size_.isValid()) { + this->move(pos_); + this->resize(size_); + return; } - - this->move(pos_); - this->resize(size_); } + // default action + movePosition2CenterOfParent(); + } catch (...) { SPDLOG_ERROR(name_, "error"); } @@ -148,8 +112,56 @@ void GpgFrontend::UI::GeneralDialog::setPosCenterOfScreen() { * */ void GpgFrontend::UI::GeneralDialog::movePosition2CenterOfParent() { - SPDLOG_DEBUG("parent pos x: {} y: {}", parent_pos_.x(), parent_pos_.y()); + // read pos and size from parent + if (this->parent() != nullptr) { + QPoint parent_pos = {0, 0}; + QSize parent_size = {0, 0}; + + auto *parent_widget = qobject_cast<QWidget *>(this->parent()); + if (parent_widget != nullptr) { + parent_pos = parent_widget->pos(); + parent_size = parent_widget->size(); + } + + auto *parent_dialog = qobject_cast<QDialog *>(this->parent()); + if (parent_dialog != nullptr) { + parent_pos = parent_dialog->pos(); + parent_size = parent_dialog->size(); + } + + auto *parent_window = qobject_cast<QMainWindow *>(this->parent()); + if (parent_window != nullptr) { + parent_pos = parent_window->pos(); + parent_size = parent_window->size(); + } + + SPDLOG_DEBUG("parent pos x: {} y: {}", parent_pos.x(), parent_pos.y()); + SPDLOG_DEBUG("parent size width: {} height: {}", parent_size.width(), + parent_size.height()); + + SPDLOG_DEBUG("this dialog size width: {} height: {}", size_.width(), + size_.height()); + + if (parent_pos != QPoint{0, 0}) { + QPoint parent_center{parent_pos.x() + parent_size.width() / 2, + parent_pos.y() + parent_size.height() / 2}; + + pos_ = {parent_center.x() - size_.width() / 2, + parent_center.y() - size_.height() / 2}; + + // record parent_pos_ + this->parent_pos_ = parent_pos; + this->parent_size_ = parent_size; + } + } else { + // reset parent's pos and size + this->parent_pos_ = QPoint{0, 0}; + this->parent_size_ = QSize{0, 0}; + } + + // log for debug + SPDLOG_DEBUG("parent pos x: {} y: {}", parent_pos_.x(), parent_pos_.y()); SPDLOG_DEBUG("parent size width: {}", parent_size_.width(), "height:", parent_size_.height()); @@ -164,5 +176,7 @@ void GpgFrontend::UI::GeneralDialog::movePosition2CenterOfParent() { pos_ = {parent_center.x() - size_.width() / 2, parent_center.y() - size_.height() / 2}; this->move(pos_); + } else { + setPosCenterOfScreen(); } }
\ No newline at end of file diff --git a/src/ui/dialog/details/VerifyDetailsDialog.h b/src/ui/dialog/details/VerifyDetailsDialog.h index 97e2cc2d..5bc09884 100644 --- a/src/ui/dialog/details/VerifyDetailsDialog.h +++ b/src/ui/dialog/details/VerifyDetailsDialog.h @@ -60,7 +60,6 @@ class VerifyDetailsDialog : public QDialog { void slot_refresh(); private: - KeyList* key_list_; ///< QHBoxLayout* main_layout_; ///< QWidget* m_vbox_{}; ///< QByteArray* input_data_{}; ///< diff --git a/src/ui/dialog/help/AboutDialog.cpp b/src/ui/dialog/help/AboutDialog.cpp index 3cf6c2a2..faf2b316 100644 --- a/src/ui/dialog/help/AboutDialog.cpp +++ b/src/ui/dialog/help/AboutDialog.cpp @@ -28,6 +28,8 @@ #include "AboutDialog.h" +#include <openssl/opensslv.h> + #include "GpgFrontendBuildInfo.h" #include "core/function/GlobalSettingStation.h" #include "core/thread/TaskRunnerGetter.h" @@ -83,9 +85,9 @@ InfoTab::InfoTab(QWidget* parent) : QWidget(parent) { "<center><b>" + qApp->applicationVersion() + "</b></center>" + "<center>" + GIT_VERSION + "</center>" + "<br><center>" + _("GpgFrontend is an easy-to-use, compact, cross-platform, " - "and installation-free gpg front-end tool." - "It visualizes most of the common operations of gpg commands." - "It's licensed under the GPL v3") + + "and installation-free GnuPG Frontend." + "It visualizes most of the common operations of GnuPG." + "GpgFrontend is licensed under the GPLv3") + "<br><br>" "<b>" + _("Developer:") + "</b><br>" + "Saturneric" + "<br><br>" + @@ -94,7 +96,8 @@ InfoTab::InfoTab(QWidget* parent) : QWidget(parent) { " <a href=\"https://github.com/saturneric/GpgFrontend\">GitHub</a> " + _("or send a mail to my mailing list at") + " <a " + "href=\"mailto:[email protected]\">[email protected]</a>." + "<br><br> " + - _("Built with Qt") + " " + qVersion() + " " + _("and GPGME") + " " + + _("Built with Qt") + " " + qVersion() + ", " + OPENSSL_VERSION_TEXT + + " " + _("and") + " " + "GPGME" + " " + GpgFrontend::GpgContext::GetInstance() .GetInfo(false) .GpgMEVersion.c_str() + diff --git a/src/ui/dialog/help/AboutDialog.h b/src/ui/dialog/help/AboutDialog.h index 09a63734..6d7ce265 100644 --- a/src/ui/dialog/help/AboutDialog.h +++ b/src/ui/dialog/help/AboutDialog.h @@ -80,7 +80,6 @@ class UpdateTab : public QWidget { QLabel* upgrade_label_; ///< QProgressBar* pb_; ///< QString current_version_; ///< - QPushButton* download_button_; ///< public: /** diff --git a/src/ui/dialog/help/GnupgTab.cpp b/src/ui/dialog/help/GnupgTab.cpp index 2758cbe1..996d4ad9 100644 --- a/src/ui/dialog/help/GnupgTab.cpp +++ b/src/ui/dialog/help/GnupgTab.cpp @@ -42,7 +42,10 @@ GpgFrontend::UI::GnupgTab::GnupgTab(QWidget* parent) QStringList components_column_titles; components_column_titles << _("Name") << _("Description") << _("Version") - << _("Checksum") << _("Path"); + << _("Checksum") << _("Binary Path"); + + ui_->tabWidget->setTabText(0, _("Components")); + ui_->tabWidget->setTabText(1, _("Configurations")); ui_->componentDetailsTable->setColumnCount(components_column_titles.length()); ui_->componentDetailsTable->setHorizontalHeaderLabels( @@ -52,7 +55,7 @@ GpgFrontend::UI::GnupgTab::GnupgTab(QWidget* parent) QAbstractItemView::SelectRows); QStringList configurations_column_titles; - configurations_column_titles << _("Name") << _("Path"); + configurations_column_titles << _("Key") << _("Value"); ui_->configurationDetailsTable->setColumnCount( configurations_column_titles.length()); diff --git a/src/ui/dialog/import_export/KeyImportDetailDialog.cpp b/src/ui/dialog/import_export/KeyImportDetailDialog.cpp index e9b1af93..32ae63fa 100644 --- a/src/ui/dialog/import_export/KeyImportDetailDialog.cpp +++ b/src/ui/dialog/import_export/KeyImportDetailDialog.cpp @@ -124,7 +124,6 @@ void KeyImportDetailDialog::create_general_info_box() { new QLabel(QString(_("Private Unchanged")) + ": "), row, 0); generalInfoBoxLayout->addWidget( new QLabel(QString::number(m_result_.secret_unchanged)), row, 1); - row++; } } @@ -162,36 +161,36 @@ void KeyImportDetailDialog::create_keys_table() { keys_table_->resizeColumnsToContents(); } -QString KeyImportDetailDialog::get_status_string(int keyStatus) { - QString statusString; +QString KeyImportDetailDialog::get_status_string(int key_status) { + QString status_string; // keystatus is greater than 15, if key is private - if (keyStatus > 15) { - statusString.append(_("Private")); - keyStatus = keyStatus - 16; + if (key_status > 15) { + status_string.append(_("Private")); + key_status = key_status - 16; } else { - statusString.append(_("Public")); + status_string.append(_("Public")); } - if (keyStatus == 0) { - statusString.append(", " + QString(_("Unchanged"))); + if (key_status == 0) { + status_string.append(", " + QString(_("Unchanged"))); } else { - if (keyStatus == 1) { - statusString.append(", " + QString(_("New Key"))); + if (key_status == 1) { + status_string.append(", " + QString(_("New Key"))); } else { - if (keyStatus > 7) { - statusString.append(", " + QString(_("New Subkey"))); - keyStatus = keyStatus - 8; + if (key_status > 7) { + status_string.append(", " + QString(_("New Subkey"))); + return status_string; } - if (keyStatus > 3) { - statusString.append(", " + QString(_("New Signature"))); - keyStatus = keyStatus - 4; + if (key_status > 3) { + status_string.append(", " + QString(_("New Signature"))); + return status_string; } - if (keyStatus > 1) { - statusString.append(", " + QString(_("New UID"))); - keyStatus = keyStatus - 2; + if (key_status > 1) { + status_string.append(", " + QString(_("New UID"))); + return status_string; } } } - return statusString; + return status_string; } void KeyImportDetailDialog::create_button_box() { diff --git a/src/ui/dialog/import_export/KeyServerImportDialog.cpp b/src/ui/dialog/import_export/KeyServerImportDialog.cpp index 713c5a58..5692f607 100644 --- a/src/ui/dialog/import_export/KeyServerImportDialog.cpp +++ b/src/ui/dialog/import_export/KeyServerImportDialog.cpp @@ -47,6 +47,23 @@ KeyServerImportDialog::KeyServerImportDialog(bool automatic, QWidget* parent) // Layout for messagebox auto* message_layout = new QHBoxLayout(); + // get settings + auto& settings = GlobalSettingStation::GetInstance().GetUISettings(); + // read settings + bool forbid_all_gnupg_connection = false; + try { + forbid_all_gnupg_connection = + settings.lookup("network.forbid_all_gnupg_connection"); + } catch (...) { + SPDLOG_ERROR("setting operation error: forbid_all_gnupg_connection"); + } + + if (forbid_all_gnupg_connection) { + QMessageBox::critical(this, "Forbidden", "GnuPG is in offline mode now."); + this->close(); + this->deleteLater(); + } + if (automatic) { setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint); } else { @@ -249,6 +266,10 @@ void KeyServerImportDialog::slot_search() { Thread::TaskRunnerGetter::GetInstance() .GetTaskRunner(Thread::TaskRunnerGetter::kTaskRunnerType_Network) ->PostTask(task); + + QEventLoop loop; + connect(task, &Thread::Task::SignalTaskEnd, &loop, &QEventLoop::quit); + loop.exec(); } void KeyServerImportDialog::slot_search_finished( diff --git a/src/ui/dialog/key_generate/KeygenDialog.cpp b/src/ui/dialog/key_generate/KeygenDialog.cpp index d6f61215..ea874ed2 100644 --- a/src/ui/dialog/key_generate/KeygenDialog.cpp +++ b/src/ui/dialog/key_generate/KeygenDialog.cpp @@ -28,6 +28,8 @@ #include "KeygenDialog.h" +#include <qobject.h> + #include "core/common/CoreCommonUtil.h" #include "core/function/GlobalSettingStation.h" #include "core/function/gpg/GpgKeyOpera.h" @@ -53,6 +55,16 @@ KeyGenDialog::KeyGenDialog(QWidget* parent) SPDLOG_ERROR("setting operation error: longer_expiration_date"); } + bool use_pinentry_as_password_input_dialog = false; + try { + use_pinentry_as_password_input_dialog = + settings.lookup("general.use_pinentry_as_password_input_dialog"); + } catch (...) { + SPDLOG_ERROR( + "setting operation error: use_pinentry_as_password_input_dialog"); + } + use_pinentry_ = use_pinentry_as_password_input_dialog; + max_date_time_ = longer_expiration_date ? QDateTime::currentDateTime().toLocalTime().addYears(30) : QDateTime::currentDateTime().toLocalTime().addYears(2); @@ -111,7 +123,8 @@ void KeyGenDialog::slot_key_gen_accept() { error_stream << " " << _("Expiration time too long.") << std::endl; } - if (passphrase_edit_->isEnabled() && passphrase_edit_->text().size() == 0) { + if (!use_pinentry_ && passphrase_edit_->isEnabled() && + passphrase_edit_->text().size() == 0) { error_stream << " " << _("Password is empty.") << std::endl; } @@ -139,7 +152,7 @@ void KeyGenDialog::slot_key_gen_accept() { #endif } - if (!gen_key_info_->IsNoPassPhrase()) { + if (!use_pinentry_ && !gen_key_info_->IsNoPassPhrase()) { CoreCommonUtil::GetInstance()->SetTempCacheValue( "__key_passphrase", this->passphrase_edit_->text().toStdString()); } @@ -160,14 +173,14 @@ void KeyGenDialog::slot_key_gen_accept() { dialog->close(); - if (!gen_key_info_->IsNoPassPhrase()) { + if (!use_pinentry_ && !gen_key_info_->IsNoPassPhrase()) { CoreCommonUtil::GetInstance()->ResetTempCacheValue("__key_passphrase"); } SPDLOG_DEBUG("generate done"); if (gpgme_err_code(error) == GPG_ERR_NO_ERROR) { - auto* msg_box = new QMessageBox((QWidget*)this->parent()); + auto* msg_box = new QMessageBox(qobject_cast<QWidget*>(this->parent())); msg_box->setAttribute(Qt::WA_DeleteOnClose); msg_box->setStandardButtons(QMessageBox::Ok); msg_box->setWindowTitle(_("Success")); @@ -391,6 +404,7 @@ QGroupBox* KeyGenDialog::create_basic_info_group_box() { expire_check_box_->setCheckState(Qt::Unchecked); passphrase_edit_->setEchoMode(QLineEdit::Password); + passphrase_edit_->setHidden(use_pinentry_); no_pass_phrase_check_box_ = new QCheckBox(this); no_pass_phrase_check_box_->setCheckState(Qt::Unchecked); @@ -404,8 +418,9 @@ QGroupBox* KeyGenDialog::create_basic_info_group_box() { vbox1->addWidget(new QLabel(QString(_("Never Expire")) + ": "), 3, 3); vbox1->addWidget(new QLabel(QString(_("KeySize (in Bit)")) + ": "), 4, 0); vbox1->addWidget(new QLabel(QString(_("Key Type")) + ": "), 5, 0); - vbox1->addWidget(new QLabel(QString(_("Password")) + ": "), 6, 0); - vbox1->addWidget(new QLabel(QString(_("Non Pass Phrase")) + ": "), 6, 3); + if (!use_pinentry_) + vbox1->addWidget(new QLabel(QString(_("Password")) + ": "), 6, 0); + vbox1->addWidget(new QLabel(QString(_("Non Pass Phrase"))), 6, 3); vbox1->addWidget(name_edit_, 0, 1, 1, 3); vbox1->addWidget(email_edit_, 1, 1, 1, 3); @@ -414,7 +429,7 @@ QGroupBox* KeyGenDialog::create_basic_info_group_box() { vbox1->addWidget(expire_check_box_, 3, 2); vbox1->addWidget(key_size_spin_box_, 4, 1); vbox1->addWidget(key_type_combo_box_, 5, 1); - vbox1->addWidget(passphrase_edit_, 6, 1); + if (!use_pinentry_) vbox1->addWidget(passphrase_edit_, 6, 1); vbox1->addWidget(no_pass_phrase_check_box_, 6, 2); auto basicInfoGroupBox = new QGroupBox(); diff --git a/src/ui/dialog/key_generate/KeygenDialog.h b/src/ui/dialog/key_generate/KeygenDialog.h index a1d7f39a..31b5f9c7 100644 --- a/src/ui/dialog/key_generate/KeygenDialog.h +++ b/src/ui/dialog/key_generate/KeygenDialog.h @@ -103,6 +103,7 @@ class KeyGenDialog : public GeneralDialog { ///< of the Key QDateTime max_date_time_; ///< std::vector<QCheckBox*> key_usage_check_boxes_; ///< ENCR, SIGN, CERT, AUTH + bool use_pinentry_ = false; /** * @brief diff --git a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp index 50f38413..f4263962 100644 --- a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp +++ b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp @@ -52,6 +52,16 @@ SubkeyGenerateDialog::SubkeyGenerateDialog(const KeyId& key_id, QWidget* parent) SPDLOG_ERROR("setting operation error: longer_expiration_date"); } + bool use_pinentry_as_password_input_dialog = false; + try { + use_pinentry_as_password_input_dialog = + settings.lookup("general.use_pinentry_as_password_input_dialog"); + } catch (...) { + SPDLOG_ERROR( + "setting operation error: use_pinentry_as_password_input_dialog"); + } + use_pinentry_ = use_pinentry_as_password_input_dialog; + max_date_time_ = longer_expiration_date ? QDateTime::currentDateTime().toLocalTime().addYears(30) : QDateTime::currentDateTime().toLocalTime().addYears(2); @@ -148,20 +158,24 @@ QGroupBox* SubkeyGenerateDialog::create_basic_info_group_box() { expire_check_box_ = new QCheckBox(this); expire_check_box_->setCheckState(Qt::Unchecked); + passphrase_edit_->setEchoMode(QLineEdit::Password); + passphrase_edit_->setHidden(use_pinentry_); + auto* vbox1 = new QGridLayout; vbox1->addWidget(new QLabel(QString(_("Key Type")) + ": "), 0, 0); vbox1->addWidget(new QLabel(QString(_("KeySize (in Bit)")) + ": "), 1, 0); vbox1->addWidget(new QLabel(QString(_("Expiration Date")) + ": "), 2, 0); vbox1->addWidget(new QLabel(QString(_("Never Expire"))), 2, 3); - vbox1->addWidget(new QLabel(QString(_("Password")) + ": "), 3, 0); + if (!use_pinentry_) + vbox1->addWidget(new QLabel(QString(_("Password")) + ": "), 3, 0); vbox1->addWidget(new QLabel(QString(_("Non Pass Phrase"))), 3, 3); vbox1->addWidget(key_type_combo_box_, 0, 1); vbox1->addWidget(key_size_spin_box_, 1, 1); vbox1->addWidget(date_edit_, 2, 1); vbox1->addWidget(expire_check_box_, 2, 2); - vbox1->addWidget(passphrase_edit_, 3, 1); + if (!use_pinentry_) vbox1->addWidget(passphrase_edit_, 3, 1); vbox1->addWidget(no_pass_phrase_check_box_, 3, 2); auto basicInfoGroupBox = new QGroupBox(); @@ -265,7 +279,8 @@ void SubkeyGenerateDialog::slot_key_gen_accept() { err_stream << " " << _("Expiration time no more than 2 years.") << " "; } - if (passphrase_edit_->isEnabled() && passphrase_edit_->text().size() == 0) { + if (!use_pinentry_ && passphrase_edit_->isEnabled() && + passphrase_edit_->text().size() == 0) { err_stream << " " << _("Password is empty.") << std::endl; } @@ -286,7 +301,7 @@ void SubkeyGenerateDialog::slot_key_gen_accept() { #endif } - if (!gen_key_info_->IsNoPassPhrase()) { + if (!use_pinentry_ && !gen_key_info_->IsNoPassPhrase()) { CoreCommonUtil::GetInstance()->SetTempCacheValue( "__key_passphrase", this->passphrase_edit_->text().toStdString()); } @@ -307,12 +322,12 @@ void SubkeyGenerateDialog::slot_key_gen_accept() { } waiting_dialog->close(); - if (!gen_key_info_->IsNoPassPhrase()) { + if (!use_pinentry_ && !gen_key_info_->IsNoPassPhrase()) { CoreCommonUtil::GetInstance()->ResetTempCacheValue("__key_passphrase"); } if (check_gpg_error_2_err_code(error) == GPG_ERR_NO_ERROR) { - auto* msg_box = new QMessageBox((QWidget*)this->parent()); + auto* msg_box = new QMessageBox(qobject_cast<QWidget*>(this->parent())); msg_box->setAttribute(Qt::WA_DeleteOnClose); msg_box->setStandardButtons(QMessageBox::Ok); msg_box->setWindowTitle(_("Success")); diff --git a/src/ui/dialog/key_generate/SubkeyGenerateDialog.h b/src/ui/dialog/key_generate/SubkeyGenerateDialog.h index 731bb951..2b88bd61 100644 --- a/src/ui/dialog/key_generate/SubkeyGenerateDialog.h +++ b/src/ui/dialog/key_generate/SubkeyGenerateDialog.h @@ -74,6 +74,7 @@ class SubkeyGenerateDialog : public GeneralDialog { std::vector<QCheckBox*> key_usage_check_boxes_; ///< ENCR, SIGN, CERT, AUTH QDateTime max_date_time_; ///< + bool use_pinentry_ = false; /** * @brief Create a key usage group box object diff --git a/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp b/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp index a1452033..9be77923 100644 --- a/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp +++ b/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp @@ -27,6 +27,7 @@ #include "KeyPairOperaTab.h" #include "KeySetExpireDateDialog.h" +#include "core/function/GlobalSettingStation.h" #include "core/function/gpg/GpgKeyImportExporter.h" #include "core/function/gpg/GpgKeyOpera.h" #include "ui/SignalStation.h" @@ -73,10 +74,23 @@ KeyPairOperaTab::KeyPairOperaTab(const std::string& key_id, QWidget* parent) } auto advance_h_box_layout = new QHBoxLayout(); + + // get settings + auto& settings = GlobalSettingStation::GetInstance().GetUISettings(); + // read settings + bool forbid_all_gnupg_connection = false; + try { + forbid_all_gnupg_connection = + settings.lookup("network.forbid_all_gnupg_connection"); + } catch (...) { + SPDLOG_ERROR("setting operation error: forbid_all_gnupg_connection"); + } + auto* key_server_opera_button = new QPushButton(_("Key Server Operation (Pubkey)")); key_server_opera_button->setStyleSheet("text-align:center;"); key_server_opera_button->setMenu(key_server_opera_menu_); + key_server_opera_button->setDisabled(forbid_all_gnupg_connection); advance_h_box_layout->addWidget(key_server_opera_button); if (m_key_.IsPrivateKey() && m_key_.IsHasMasterKey()) { @@ -147,8 +161,13 @@ void KeyPairOperaTab::slot_export_public_key() { } // generate a file name +#ifndef WINDOWS auto file_string = m_key_.GetName() + "<" + m_key_.GetEmail() + ">(" + m_key_.GetId() + ")_pub.asc"; +#else + auto file_string = m_key_.GetName() + "[" + m_key_.GetEmail() + "](" + + m_key_.GetId() + ")_pub.asc"; +#endif std::replace(file_string.begin(), file_string.end(), ' ', '_'); auto file_name = @@ -193,8 +212,14 @@ void KeyPairOperaTab::slot_export_short_private_key() { return; } + // generate a file name +#ifndef WINDOWS auto file_string = m_key_.GetName() + "<" + m_key_.GetEmail() + ">(" + m_key_.GetId() + ")_short_secret.asc"; +#else + auto file_string = m_key_.GetName() + "[" + m_key_.GetEmail() + "](" + + m_key_.GetId() + ")_short_secret.asc"; +#endif std::replace(file_string.begin(), file_string.end(), ' ', '_'); auto file_name = @@ -235,8 +260,15 @@ void KeyPairOperaTab::slot_export_private_key() { _("An error occurred during the export operation.")); return; } + + // generate a file name +#ifndef WINDOWS auto file_string = m_key_.GetName() + "<" + m_key_.GetEmail() + ">(" + m_key_.GetId() + ")_full_secret.asc"; +#else + auto file_string = m_key_.GetName() + "[" + m_key_.GetEmail() + "](" + + m_key_.GetId() + ")_full_secret.asc"; +#endif std::replace(file_string.begin(), file_string.end(), ' ', '_'); auto file_name = diff --git a/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp b/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp index d1367541..9c243a39 100644 --- a/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp +++ b/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp @@ -312,7 +312,7 @@ void KeyPairSubkeyTab::slot_refresh_subkey_detail() { } fingerprint_var_label_->setText( - QString::fromStdString(subkey.GetFingerprint())); + QString::fromStdString(beautify_fingerprint(subkey.GetFingerprint()))); } void KeyPairSubkeyTab::create_subkey_opera_menu() { diff --git a/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp b/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp index d09662e1..89d2ce74 100644 --- a/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp +++ b/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp @@ -79,7 +79,7 @@ void KeySetExpireDateDialog::slot_confirm() { auto err = GpgKeyOpera::GetInstance().SetExpire(m_key_, m_subkey_, expires); if (check_gpg_error_2_err_code(err) == GPG_ERR_NO_ERROR) { - auto* msg_box = new QMessageBox((QWidget*)this->parent()); + auto* msg_box = new QMessageBox(qobject_cast<QWidget*>(this->parent())); msg_box->setAttribute(Qt::WA_DeleteOnClose); msg_box->setStandardButtons(QMessageBox::Ok); msg_box->setWindowTitle(_("Success")); diff --git a/src/ui/dialog/settings/SettingsGeneral.cpp b/src/ui/dialog/settings/SettingsGeneral.cpp index 7e48b4e1..17d9251c 100644 --- a/src/ui/dialog/settings/SettingsGeneral.cpp +++ b/src/ui/dialog/settings/SettingsGeneral.cpp @@ -47,7 +47,7 @@ GeneralTab::GeneralTab(QWidget* parent) ui_->saveCheckedKeysCheckBox->setText( _("Save checked private keys on exit and restore them on next start.")); ui_->clearGpgPasswordCacheCheckBox->setText( - "Clear gpg password cache when closing GpgFrontend."); + _("Clear gpg password cache when closing GpgFrontend.")); ui_->importConfirmationBox->setTitle(_("Operation")); ui_->longerKeyExpirationDateCheckBox->setText( @@ -57,6 +57,8 @@ GeneralTab::GeneralTab(QWidget* parent) ui_->gnupgDatabaseBox->setTitle(_("GnuPG")); ui_->asciiModeCheckBox->setText(_("No ASCII Mode")); + ui_->usePinentryAsPasswordInputDialogCheckBox->setText( + _("Use Pinentry as Password Input Dialog")); ui_->useCustomGnuPGInstallPathCheckBox->setText(_("Use Custom GnuPG")); ui_->useCustomGnuPGInstallPathButton->setText(_("Select GnuPG Path")); ui_->keyDatabseUseCustomCheckBox->setText( @@ -167,6 +169,12 @@ GeneralTab::GeneralTab(QWidget* parent) } }); + connect(ui_->usePinentryAsPasswordInputDialogCheckBox, + &QCheckBox::stateChanged, this, [=](int state) { + // announce the restart + this->slot_gnupg_stettings_changed(); + }); + SetSettings(); } @@ -260,6 +268,16 @@ void GeneralTab::SetSettings() { SPDLOG_ERROR("setting operation error: use_custom_gnupg_install_path"); } + try { + bool use_pinentry_as_password_input_dialog = + settings.lookup("general.use_pinentry_as_password_input_dialog"); + if (use_pinentry_as_password_input_dialog) + ui_->usePinentryAsPasswordInputDialogCheckBox->setCheckState(Qt::Checked); + } catch (...) { + SPDLOG_ERROR( + "setting operation error: use_pinentry_as_password_input_dialog"); + } + this->slot_update_custom_gnupg_install_path_label( ui_->useCustomGnuPGInstallPathCheckBox->checkState()); } @@ -343,6 +361,15 @@ void GeneralTab::ApplySettings() { general["use_custom_gnupg_install_path"] = ui_->useCustomGnuPGInstallPathCheckBox->isChecked(); } + + if (!general.exists("use_pinentry_as_password_input_dialog")) + general.add("use_pinentry_as_password_input_dialog", + libconfig::Setting::TypeBoolean) = + ui_->usePinentryAsPasswordInputDialogCheckBox->isChecked(); + else { + general["use_pinentry_as_password_input_dialog"] = + ui_->usePinentryAsPasswordInputDialogCheckBox->isChecked(); + } } #ifdef MULTI_LANG_SUPPORT diff --git a/src/ui/dialog/settings/SettingsKeyServer.cpp b/src/ui/dialog/settings/SettingsKeyServer.cpp index 8719ab9a..83bd2c80 100644 --- a/src/ui/dialog/settings/SettingsKeyServer.cpp +++ b/src/ui/dialog/settings/SettingsKeyServer.cpp @@ -284,6 +284,11 @@ void KeyserverTab::slot_test_listed_key_server() { Thread::TaskRunnerGetter::GetInstance() .GetTaskRunner(Thread::TaskRunnerGetter::kTaskRunnerType_Network) ->PostTask(task); + + QEventLoop loop; + connect(task, &Thread::Task::SignalTaskEnd, &loop, &QEventLoop::quit); + connect(waiting_dialog, &QProgressDialog::canceled, &loop, &QEventLoop::quit); + loop.exec(); } void KeyserverTab::contextMenuEvent(QContextMenuEvent* event) { diff --git a/src/ui/dialog/settings/SettingsNetwork.cpp b/src/ui/dialog/settings/SettingsNetwork.cpp index fe3d450e..0713856d 100644 --- a/src/ui/dialog/settings/SettingsNetwork.cpp +++ b/src/ui/dialog/settings/SettingsNetwork.cpp @@ -29,7 +29,7 @@ #include "SettingsNetwork.h" #include "core/function/GlobalSettingStation.h" -#include "ui/thread/ProxyConnectionTestThread.h" +#include "ui/thread/ProxyConnectionTestTask.h" #include "ui_NetworkSettings.h" GpgFrontend::UI::NetworkTab::NetworkTab(QWidget *parent) @@ -37,7 +37,28 @@ GpgFrontend::UI::NetworkTab::NetworkTab(QWidget *parent) ui_->setupUi(this); connect(ui_->enableProxyCheckBox, &QCheckBox::stateChanged, this, - [=](int state) { switch_ui_enabled(state == Qt::Checked); }); + [=](int state) { + switch_ui_enabled(state == Qt::Checked); + // when selecting no proxy option, apply it immediately + if (state != Qt::Checked) apply_proxy_settings(); + }); + + connect( + ui_->autoImportMissingKeyCheckBox, &QCheckBox::stateChanged, this, + [=](int state) { + ui_->forbidALLGnuPGNetworkConnectionCheckBox->setCheckState( + state == Qt::Checked + ? Qt::Unchecked + : ui_->forbidALLGnuPGNetworkConnectionCheckBox->checkState()); + }); + + connect(ui_->forbidALLGnuPGNetworkConnectionCheckBox, + &QCheckBox::stateChanged, this, [=](int state) { + ui_->autoImportMissingKeyCheckBox->setCheckState( + state == Qt::Checked + ? Qt::Unchecked + : ui_->autoImportMissingKeyCheckBox->checkState()); + }); connect( ui_->proxyTypeComboBox, &QComboBox::currentTextChanged, this, @@ -47,7 +68,7 @@ GpgFrontend::UI::NetworkTab::NetworkTab(QWidget *parent) &NetworkTab::slot_test_proxy_connection_result); ui_->proxyGroupBox->setTitle(_("Proxy")); - ui_->capabilityGroupBox->setTitle(_("Network Capability")); + ui_->capabilityGroupBox->setTitle(_("Network Ability")); ui_->operationsGroupBox->setTitle(_("Operations")); ui_->enableProxyCheckBox->setText(_("Enable Proxy")); @@ -59,12 +80,18 @@ GpgFrontend::UI::NetworkTab::NetworkTab(QWidget *parent) ui_->usernameLabel->setText(_("Username")); ui_->passwordLabel->setText(_("Password")); - ui_->forbidALLCheckBox->setText(_("Forbid all network connection.")); - ui_->forbidALLCheckBox->setDisabled(true); + ui_->checkProxyConnectionButton->setText( + _("Apply Proxy Settings and Check Proxy Connection")); + ui_->forbidALLGnuPGNetworkConnectionCheckBox->setText( + _("Forbid all GnuPG network connection.")); ui_->prohibitUpdateCheck->setText( _("Prohibit checking for version updates when the program starts.")); - ui_->checkProxyConnectionButton->setText(_("Check Proxy Connection")); + ui_->autoImportMissingKeyCheckBox->setText( + _("Automatically import a missing key for signature verification.")); + ui_->networkAbilityTipsLabel->setText( + _("Tips: These Option Changes take effect only after the " + "application restart.")); SetSettings(); } @@ -120,21 +147,17 @@ void GpgFrontend::UI::NetworkTab::SetSettings() { SPDLOG_ERROR("setting operation error: proxy_enable"); } - { - auto state = ui_->enableProxyCheckBox->checkState(); - switch_ui_enabled(state == Qt::Checked); - } - - ui_->forbidALLCheckBox->setCheckState(Qt::Unchecked); + ui_->forbidALLGnuPGNetworkConnectionCheckBox->setCheckState(Qt::Unchecked); try { - bool forbid_all_connection = - settings.lookup("network.forbid_all_connection"); - if (forbid_all_connection) - ui_->forbidALLCheckBox->setCheckState(Qt::Checked); + bool forbid_all_gnupg_connection = + settings.lookup("network.forbid_all_gnupg_connection"); + if (forbid_all_gnupg_connection) + ui_->forbidALLGnuPGNetworkConnectionCheckBox->setCheckState(Qt::Checked); else - ui_->forbidALLCheckBox->setCheckState(Qt::Unchecked); + ui_->forbidALLGnuPGNetworkConnectionCheckBox->setCheckState( + Qt::Unchecked); } catch (...) { - SPDLOG_ERROR("setting operation error: forbid_all_connection"); + SPDLOG_ERROR("setting operation error: forbid_all_gnupg_connection"); } ui_->prohibitUpdateCheck->setCheckState(Qt::Unchecked); @@ -148,6 +171,21 @@ void GpgFrontend::UI::NetworkTab::SetSettings() { } catch (...) { SPDLOG_ERROR("setting operation error: prohibit_update_checking"); } + + ui_->autoImportMissingKeyCheckBox->setCheckState(Qt::Unchecked); + try { + bool auto_import_missing_key = + settings.lookup("network.auto_import_missing_key"); + if (auto_import_missing_key) + ui_->autoImportMissingKeyCheckBox->setCheckState(Qt::Checked); + else + ui_->autoImportMissingKeyCheckBox->setCheckState(Qt::Unchecked); + } catch (...) { + SPDLOG_ERROR("setting operation error: auto_import_missing_key"); + } + + switch_ui_enabled(ui_->enableProxyCheckBox->isChecked()); + switch_ui_proxy_type(ui_->proxyTypeComboBox->currentText()); } void GpgFrontend::UI::NetworkTab::ApplySettings() { @@ -207,11 +245,13 @@ void GpgFrontend::UI::NetworkTab::ApplySettings() { auto &network = settings["network"]; - if (!network.exists("forbid_all_connection")) - network.add("forbid_all_connection", libconfig::Setting::TypeBoolean) = - ui_->forbidALLCheckBox->isChecked(); + if (!network.exists("forbid_all_gnupg_connection")) + network.add("forbid_all_gnupg_connection", + libconfig::Setting::TypeBoolean) = + ui_->forbidALLGnuPGNetworkConnectionCheckBox->isChecked(); else { - network["forbid_all_connection"] = ui_->forbidALLCheckBox->isChecked(); + network["forbid_all_gnupg_connection"] = + ui_->forbidALLGnuPGNetworkConnectionCheckBox->isChecked(); } if (!network.exists("prohibit_update_checking")) @@ -221,6 +261,14 @@ void GpgFrontend::UI::NetworkTab::ApplySettings() { network["prohibit_update_checking"] = ui_->prohibitUpdateCheck->isChecked(); } + if (!network.exists("auto_import_missing_key")) + network.add("auto_import_missing_key", libconfig::Setting::TypeBoolean) = + ui_->autoImportMissingKeyCheckBox->isChecked(); + else { + network["auto_import_missing_key"] = + ui_->autoImportMissingKeyCheckBox->isChecked(); + } + apply_proxy_settings(); } @@ -232,9 +280,9 @@ void GpgFrontend::UI::NetworkTab::slot_test_proxy_connection_result() { tr("Server Url"), QLineEdit::Normal, "https://", &ok); if (ok && !url.isEmpty()) { - auto thread = new ProxyConnectionTestThread(url, 800, this); - connect(thread, - &GpgFrontend::UI::ProxyConnectionTestThread:: + auto task = new ProxyConnectionTestTask(url, 800); + connect(task, + &GpgFrontend::UI::ProxyConnectionTestTask:: SignalProxyConnectionTestResult, this, [=](const QString &result) { if (result == "Reachable") { @@ -248,7 +296,6 @@ void GpgFrontend::UI::NetworkTab::slot_test_proxy_connection_result() { "proxy server. Proxy settings may be invalid.")); } }); - connect(thread, &QThread::finished, thread, &QThread::deleteLater); // Waiting Dialog auto *waiting_dialog = new QProgressDialog(this); @@ -261,43 +308,43 @@ void GpgFrontend::UI::NetworkTab::slot_test_proxy_connection_result() { waiting_dialog_label->setWordWrap(true); waiting_dialog->setLabel(waiting_dialog_label); waiting_dialog->resize(420, 120); - connect(thread, &QThread::finished, [=]() { - waiting_dialog->finished(0); + connect(task, &Thread::Task::SignalTaskEnd, [=]() { + waiting_dialog->close(); waiting_dialog->deleteLater(); }); - connect(waiting_dialog, &QProgressDialog::canceled, [=]() { - SPDLOG_DEBUG("cancel clicked"); - if (thread->isRunning()) thread->terminate(); - }); // Show Waiting Dialog waiting_dialog->show(); waiting_dialog->setFocus(); - thread->start(); + Thread::TaskRunnerGetter::GetInstance() + .GetTaskRunner(Thread::TaskRunnerGetter::kTaskRunnerType_Network) + ->PostTask(task); + QEventLoop loop; - connect(thread, &QThread::finished, &loop, &QEventLoop::quit); + connect(task, &Thread::Task::SignalTaskEnd, &loop, &QEventLoop::quit); + connect(waiting_dialog, &QProgressDialog::canceled, &loop, + &QEventLoop::quit); loop.exec(); } } void GpgFrontend::UI::NetworkTab::apply_proxy_settings() { // apply settings - QNetworkProxy _proxy; + QNetworkProxy proxy; if (ui_->enableProxyCheckBox->isChecked() && proxy_type_ != QNetworkProxy::DefaultProxy) { - _proxy.setType(proxy_type_); - _proxy.setHostName(ui_->proxyServerAddressEdit->text()); - _proxy.setPort(ui_->portSpin->value()); + proxy.setType(proxy_type_); + proxy.setHostName(ui_->proxyServerAddressEdit->text()); + proxy.setPort(ui_->portSpin->value()); if (!ui_->usernameEdit->text().isEmpty()) { - _proxy.setUser(ui_->usernameEdit->text()); - _proxy.setPassword(ui_->passwordEdit->text()); + proxy.setUser(ui_->usernameEdit->text()); + proxy.setPassword(ui_->passwordEdit->text()); } } else { - _proxy.setType(proxy_type_); + proxy.setType(proxy_type_); } - - QNetworkProxy::setApplicationProxy(_proxy); + QNetworkProxy::setApplicationProxy(proxy); } void GpgFrontend::UI::NetworkTab::switch_ui_enabled(bool enabled) { diff --git a/src/ui/main_window/KeyMgmt.cpp b/src/ui/main_window/KeyMgmt.cpp index 9183d9d7..949ef071 100644 --- a/src/ui/main_window/KeyMgmt.cpp +++ b/src/ui/main_window/KeyMgmt.cpp @@ -91,7 +91,7 @@ KeyMgmt::KeyMgmt(QWidget* parent) setCentralWidget(key_list_); key_list_->SetDoubleClickedAction([this](const GpgKey& key, QWidget* parent) { - new KeyDetailsDialog(key, parent); + new KeyDetailsDialog(key, this); }); key_list_->SlotRefresh(); @@ -109,8 +109,10 @@ KeyMgmt::KeyMgmt(QWidget* parent) this->statusBar()->show(); setWindowTitle(_("KeyPair Management")); + key_list_->AddMenuAction(generate_subkey_act_); key_list_->AddMenuAction(delete_selected_keys_act_); + key_list_->AddSeparator(); key_list_->AddMenuAction(show_key_details_act_); connect(this, &KeyMgmt::SignalKeyStatusUpdated, SignalStation::GetInstance(), @@ -163,11 +165,23 @@ void KeyMgmt::create_actions() { CommonUtils::GetInstance()->SlotImportKeyFromClipboard(this); }); + // get settings + auto& settings = GlobalSettingStation::GetInstance().GetUISettings(); + // read settings + bool forbid_all_gnupg_connection = false; + try { + forbid_all_gnupg_connection = + settings.lookup("network.forbid_all_gnupg_connection"); + } catch (...) { + SPDLOG_ERROR("setting operation error: forbid_all_gnupg_connection"); + } + import_key_from_key_server_act_ = new QAction(_("Keyserver"), this); import_key_from_key_server_act_->setIcon( QIcon(":import_key_from_server.png")); import_key_from_key_server_act_->setToolTip( _("Import New Key From Keyserver")); + import_key_from_key_server_act_->setDisabled(forbid_all_gnupg_connection); connect(import_key_from_key_server_act_, &QAction::triggered, this, [&]() { CommonUtils::GetInstance()->SlotImportKeyFromKeyServer(this); }); @@ -241,35 +255,28 @@ void KeyMgmt::create_menus() { } void KeyMgmt::create_tool_bars() { - QToolBar* keyToolBar = addToolBar(_("Key")); - keyToolBar->setObjectName("keytoolbar"); + QToolBar* key_tool_bar = addToolBar(_("Key")); + key_tool_bar->setObjectName("keytoolbar"); - // add button with popup menu for import - auto* generateToolButton = new QToolButton(this); - generateToolButton->setMenu(generate_key_menu_); - generateToolButton->setPopupMode(QToolButton::InstantPopup); - generateToolButton->setIcon(QIcon(":key_generate.png")); - generateToolButton->setText(_("Generate")); - generateToolButton->setToolTip(_("Generate A New Keypair or Subkey")); - generateToolButton->setToolButtonStyle(icon_style_); - keyToolBar->addWidget(generateToolButton); + // genrate key pair + key_tool_bar->addAction(generate_key_pair_act_); // add button with popup menu for import - auto* toolButton = new QToolButton(this); - toolButton->setMenu(import_key_menu_); - toolButton->setPopupMode(QToolButton::InstantPopup); - toolButton->setIcon(QIcon(":key_import.png")); - toolButton->setToolTip(_("Import key")); - toolButton->setText(_("Import Key")); - toolButton->setToolButtonStyle(icon_style_); - keyToolBar->addWidget(toolButton); - - keyToolBar->addSeparator(); - keyToolBar->addAction(delete_checked_keys_act_); - keyToolBar->addSeparator(); - keyToolBar->addAction(export_key_to_file_act_); - keyToolBar->addAction(export_key_to_clipboard_act_); - keyToolBar->addAction(export_key_as_open_ssh_format_); + auto* tool_button = new QToolButton(this); + tool_button->setMenu(import_key_menu_); + tool_button->setPopupMode(QToolButton::InstantPopup); + tool_button->setIcon(QIcon(":key_import.png")); + tool_button->setToolTip(_("Import key")); + tool_button->setText(_("Import Key")); + tool_button->setToolButtonStyle(icon_style_); + key_tool_bar->addWidget(tool_button); + + key_tool_bar->addSeparator(); + key_tool_bar->addAction(delete_checked_keys_act_); + key_tool_bar->addSeparator(); + key_tool_bar->addAction(export_key_to_file_act_); + key_tool_bar->addAction(export_key_to_clipboard_act_); + key_tool_bar->addAction(export_key_as_open_ssh_format_); } void KeyMgmt::SlotDeleteSelectedKeys() { @@ -323,7 +330,7 @@ void KeyMgmt::SlotShowKeyDetails() { return; } - new KeyDetailsDialog(key); + new KeyDetailsDialog(key, this); } void KeyMgmt::SlotExportKeyToKeyPackage() { diff --git a/src/ui/main_window/MainWindow.cpp b/src/ui/main_window/MainWindow.cpp index fff3ab63..b38646cf 100644 --- a/src/ui/main_window/MainWindow.cpp +++ b/src/ui/main_window/MainWindow.cpp @@ -84,7 +84,13 @@ void MainWindow::Init() noexcept { }); m_key_list_->AddMenuAction(append_selected_keys_act_); + m_key_list_->AddMenuAction(append_key_create_date_to_editor_act_); + m_key_list_->AddMenuAction(append_key_expire_date_to_editor_act_); + m_key_list_->AddMenuAction(append_key_fingerprint_to_editor_act_); + m_key_list_->AddSeparator(); m_key_list_->AddMenuAction(copy_mail_address_to_clipboard_act_); + m_key_list_->AddMenuAction(copy_key_default_uid_to_clipboard_act_); + m_key_list_->AddMenuAction(copy_key_id_to_clipboard_act_); m_key_list_->AddSeparator(); m_key_list_->AddMenuAction(show_key_details_act_); diff --git a/src/ui/main_window/MainWindow.h b/src/ui/main_window/MainWindow.h index e32a02ff..04a82759 100644 --- a/src/ui/main_window/MainWindow.h +++ b/src/ui/main_window/MainWindow.h @@ -225,12 +225,42 @@ class MainWindow : public GeneralMainWindow { void slot_append_selected_keys(); /** + * @brief + * + */ + void slot_append_keys_create_datetime(); + + /** + * @brief + * + */ + void slot_append_keys_expire_datetime(); + + /** + * @brief + * + */ + void slot_append_keys_fingerprint(); + + /** * @details Copy the mailaddress of selected key to clipboard. * Method for keylists contextmenu. */ void slot_copy_mail_address_to_clipboard(); /** + * @details Copy the mailaddress of selected key to clipboard. + * Method for keylists contextmenu. + */ + void slot_copy_default_uid_to_clipboard(); + + /** + * @details Copy the mailaddress of selected key to clipboard. + * Method for keylists contextmenu. + */ + void slot_copy_key_id_to_clipboard(); + + /** * @details Open key management dialog. */ void slot_open_key_management(); @@ -376,8 +406,15 @@ class MainWindow : public GeneralMainWindow { QAction* append_selected_keys_act_{}; ///< Action to append selected keys to edit + QAction* append_key_fingerprint_to_editor_act_{}; ///< + QAction* append_key_create_date_to_editor_act_{}; ///< + QAction* append_key_expire_date_to_editor_act_{}; ///< + QAction* copy_mail_address_to_clipboard_act_{}; ///< Action to copy mail to ///< clipboard + QAction* copy_key_id_to_clipboard_act_{}; ///< + QAction* copy_key_default_uid_to_clipboard_act_{}; ///< + QAction* open_key_management_act_{}; ///< Action to open key management QAction* copy_act_{}; ///< Action to copy text QAction* quote_act_{}; ///< Action to quote text diff --git a/src/ui/main_window/MainWindowSlotFunction.cpp b/src/ui/main_window/MainWindowSlotFunction.cpp index 6f702e34..841c8680 100644 --- a/src/ui/main_window/MainWindowSlotFunction.cpp +++ b/src/ui/main_window/MainWindowSlotFunction.cpp @@ -26,12 +26,15 @@ * */ +#include <boost/date_time/posix_time/posix_time.hpp> +#include <boost/date_time/posix_time/posix_time_io.hpp> #include <memory> #include <string> #include <utility> #include "MainWindow.h" #include "core/GpgConstants.h" +#include "core/GpgContext.h" #include "core/GpgModel.h" #include "core/function/gpg/GpgBasicOperator.h" #include "core/function/gpg/GpgKeyGetter.h" @@ -611,11 +614,88 @@ void MainWindow::slot_append_selected_keys() { auto exported = std::make_unique<ByteArray>(); auto key_ids = m_key_list_->GetSelected(); - GpgKeyImportExporter::GetInstance().ExportKeys(key_ids, exported); + if (key_ids->empty()) { + SPDLOG_ERROR("no key is selected"); + return; + } + + if (!GpgKeyImportExporter::GetInstance().ExportKeys(key_ids, exported)) { + QMessageBox::critical(this, _("Error"), _("Key Export Operation Failed.")); + return; + } edit_->CurTextPage()->GetTextPage()->appendPlainText( QString::fromStdString(*exported)); } +void MainWindow::slot_append_keys_create_datetime() { + if (edit_->TabCount() == 0 || edit_->SlotCurPageTextEdit() == nullptr) { + return; + } + + auto key_ids = m_key_list_->GetSelected(); + + if (key_ids->empty()) { + SPDLOG_ERROR("no key is selected"); + return; + } + + auto key = GpgKeyGetter::GetInstance().GetKey(key_ids->front()); + if (!key.IsGood()) { + QMessageBox::critical(this, _("Error"), _("Key Not Found.")); + return; + } + + auto create_datetime_format_str = + boost::posix_time::to_iso_extended_string(key.GetCreateTime()) + + " (UTC) " + "\n"; + + edit_->CurTextPage()->GetTextPage()->appendPlainText( + QString::fromStdString(create_datetime_format_str)); +} + +void MainWindow::slot_append_keys_expire_datetime() { + if (edit_->TabCount() == 0 || edit_->SlotCurPageTextEdit() == nullptr) { + return; + } + + auto key_ids = m_key_list_->GetSelected(); + + if (key_ids->empty()) { + SPDLOG_ERROR("no key is selected"); + return; + } + + auto key = GpgKeyGetter::GetInstance().GetKey(key_ids->front()); + if (!key.IsGood()) { + QMessageBox::critical(this, _("Error"), _("Key Not Found.")); + return; + } + + auto create_datetime_format_str = + boost::posix_time::to_iso_extended_string(key.GetCreateTime()) + + " (UTC) " + "\n"; + + edit_->CurTextPage()->GetTextPage()->appendPlainText( + QString::fromStdString(create_datetime_format_str)); +} + +void MainWindow::slot_append_keys_fingerprint() { + auto key_ids = m_key_list_->GetSelected(); + if (key_ids->empty()) return; + + auto key = GpgKeyGetter::GetInstance().GetKey(key_ids->front()); + if (!key.IsGood()) { + QMessageBox::critical(this, _("Error"), _("Key Not Found.")); + return; + } + + auto fingerprint_format_str = + beautify_fingerprint(key.GetFingerprint()) + "\n"; + + edit_->CurTextPage()->GetTextPage()->appendPlainText( + QString::fromStdString(fingerprint_format_str)); +} + void MainWindow::slot_copy_mail_address_to_clipboard() { auto key_ids = m_key_list_->GetSelected(); if (key_ids->empty()) return; @@ -629,6 +709,32 @@ void MainWindow::slot_copy_mail_address_to_clipboard() { cb->setText(QString::fromStdString(key.GetEmail())); } +void MainWindow::slot_copy_default_uid_to_clipboard() { + auto key_ids = m_key_list_->GetSelected(); + if (key_ids->empty()) return; + + auto key = GpgKeyGetter::GetInstance().GetKey(key_ids->front()); + if (!key.IsGood()) { + QMessageBox::critical(this, _("Error"), _("Key Not Found.")); + return; + } + QClipboard* cb = QApplication::clipboard(); + cb->setText(QString::fromStdString(key.GetUIDs()->front().GetUID())); +} + +void MainWindow::slot_copy_key_id_to_clipboard() { + auto key_ids = m_key_list_->GetSelected(); + if (key_ids->empty()) return; + + auto key = GpgKeyGetter::GetInstance().GetKey(key_ids->front()); + if (!key.IsGood()) { + QMessageBox::critical(this, _("Error"), _("Key Not Found.")); + return; + } + QClipboard* cb = QApplication::clipboard(); + cb->setText(QString::fromStdString(key.GetId())); +} + void MainWindow::slot_show_key_details() { auto key_ids = m_key_list_->GetSelected(); if (key_ids->empty()) return; diff --git a/src/ui/main_window/MainWindowUI.cpp b/src/ui/main_window/MainWindowUI.cpp index b9a01c15..1034df52 100644 --- a/src/ui/main_window/MainWindowUI.cpp +++ b/src/ui/main_window/MainWindowUI.cpp @@ -27,6 +27,7 @@ */ #include "MainWindow.h" +#include "core/function/GlobalSettingStation.h" #include "core/function/gpg/GpgAdvancedOperator.h" #include "ui/UserInterfaceUtils.h" @@ -251,11 +252,23 @@ void MainWindow::create_actions() { CommonUtils::GetInstance()->SlotImportKeyFromClipboard(this); }); + // get settings + auto& settings = GlobalSettingStation::GetInstance().GetUISettings(); + // read settings + bool forbid_all_gnupg_connection = false; + try { + forbid_all_gnupg_connection = + settings.lookup("network.forbid_all_gnupg_connection"); + } catch (...) { + SPDLOG_ERROR("setting operation error: forbid_all_gnupg_connection"); + } + import_key_from_key_server_act_ = new QAction(_("Keyserver"), this); import_key_from_key_server_act_->setIcon( QIcon(":import_key_from_server.png")); import_key_from_key_server_act_->setToolTip( _("Import New Key From Keyserver")); + import_key_from_key_server_act_->setDisabled(forbid_all_gnupg_connection); connect(import_key_from_key_server_act_, &QAction::triggered, this, [&]() { CommonUtils::GetInstance()->SlotImportKeyFromKeyServer(this); }); @@ -353,22 +366,53 @@ void MainWindow::create_actions() { connect(start_wizard_act_, &QAction::triggered, this, &MainWindow::slot_start_wizard); - /* Popup-Menu-Action for KeyList - */ - append_selected_keys_act_ = new QAction(_("Append To Text Editor"), this); + append_selected_keys_act_ = + new QAction(_("Append Public Key to Editor"), this); append_selected_keys_act_->setToolTip( - _("Append The Selected Public Key To Text in Editor")); + _("Append selected Keypair's Public Key to Editor")); connect(append_selected_keys_act_, &QAction::triggered, this, &MainWindow::slot_append_selected_keys); + append_key_create_date_to_editor_act_ = + new QAction(_("Append Create DateTime to Editor"), this); + append_key_create_date_to_editor_act_->setToolTip( + _("Append selected Key's creation date and time to Editor")); + connect(append_key_create_date_to_editor_act_, &QAction::triggered, this, + &MainWindow::slot_append_keys_create_datetime); + + append_key_expire_date_to_editor_act_ = + new QAction(_("Append Expire DateTime to Editor"), this); + append_key_expire_date_to_editor_act_->setToolTip( + _("Append selected Key's expiration date and time to Editor")); + connect(append_key_expire_date_to_editor_act_, &QAction::triggered, this, + &MainWindow::slot_append_keys_expire_datetime); + + append_key_fingerprint_to_editor_act_ = + new QAction(_("Append Fingerprint to Editor"), this); + append_key_expire_date_to_editor_act_->setToolTip( + _("Append selected Key's Fingerprint to Editor")); + connect(append_key_fingerprint_to_editor_act_, &QAction::triggered, this, + &MainWindow::slot_append_keys_fingerprint); + copy_mail_address_to_clipboard_act_ = new QAction(_("Copy Email"), this); copy_mail_address_to_clipboard_act_->setToolTip( - _("Copy selected Email to clipboard")); + _("Copy selected Keypair's to clipboard")); connect(copy_mail_address_to_clipboard_act_, &QAction::triggered, this, &MainWindow::slot_copy_mail_address_to_clipboard); - // TODO: find central place for shared actions, to avoid code-duplication with - // keymgmt.cpp + copy_key_default_uid_to_clipboard_act_ = + new QAction(_("Copy Default UID"), this); + copy_key_default_uid_to_clipboard_act_->setToolTip( + _("Copy selected Keypair's default UID to clipboard")); + connect(copy_key_default_uid_to_clipboard_act_, &QAction::triggered, this, + &MainWindow::slot_copy_default_uid_to_clipboard); + + copy_key_id_to_clipboard_act_ = new QAction(_("Copy Key ID"), this); + copy_key_id_to_clipboard_act_->setToolTip( + _("Copy selected Keypair's ID to clipboard")); + connect(copy_key_id_to_clipboard_act_, &QAction::triggered, this, + &MainWindow::slot_copy_key_id_to_clipboard); + show_key_details_act_ = new QAction(_("Show Key Details"), this); show_key_details_act_->setToolTip(_("Show Details for this Key")); connect(show_key_details_act_, &QAction::triggered, this, @@ -464,8 +508,8 @@ void MainWindow::create_menus() { help_menu_->addAction(start_wizard_act_); help_menu_->addSeparator(); help_menu_->addAction(check_update_act_); - help_menu_->addAction(translate_act_); help_menu_->addAction(gnupg_act_); + help_menu_->addAction(translate_act_); help_menu_->addAction(about_act_); } diff --git a/src/ui/thread/ProxyConnectionTestTask.cpp b/src/ui/thread/ProxyConnectionTestTask.cpp new file mode 100644 index 00000000..c7d623d7 --- /dev/null +++ b/src/ui/thread/ProxyConnectionTestTask.cpp @@ -0,0 +1,74 @@ +/** + * Copyright (C) 2021 Saturneric + * + * 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. + * + * The source code version of this software was modified and released + * by Saturneric<[email protected]><[email protected]> starting on May 12, 2021. + * + */ + +#include "ProxyConnectionTestTask.h" + +GpgFrontend::UI::ProxyConnectionTestTask::ProxyConnectionTestTask(QString url, + int timeout) + : Task("proxy_connection_test_task"), + url_(std::move(url)), + timeout_(timeout), + network_manager_(new QNetworkAccessManager(this)) {} + +void GpgFrontend::UI::ProxyConnectionTestTask::run() { + SetFinishAfterRun(false); + + auto* network_reply = network_manager_->get(QNetworkRequest{url_}); + auto* timer = new QTimer(this); + + connect(network_reply, &QNetworkReply::finished, this, + [this, network_reply]() { + SPDLOG_DEBUG("key server domain reply: {} received", + url_.toStdString()); + this->slot_process_network_reply(network_reply); + }); + + connect(timer, &QTimer::timeout, this, [this, network_reply]() { + SPDLOG_DEBUG("timeout for key server: {}", url_.toStdString()); + if (network_reply->isRunning()) { + network_reply->abort(); + this->slot_process_network_reply(network_reply); + } + }); + + timer->start(timeout_); +} + +void GpgFrontend::UI::ProxyConnectionTestTask::slot_process_network_reply( + QNetworkReply* reply) { + auto buffer = reply->readAll(); + SPDLOG_DEBUG("key server domain reply: {}, buffer size: {}", + url_.toStdString(), buffer.size()); + + if (reply->error() == QNetworkReply::NoError && !buffer.isEmpty()) { + result_ = "Reachable"; + } else { + result_ = "Not Reachable"; + } + + emit SignalProxyConnectionTestResult(result_); + emit SignalTaskRunnableEnd(0); +} diff --git a/src/ui/thread/ProxyConnectionTestThread.h b/src/ui/thread/ProxyConnectionTestTask.h index 70757e03..38e78ae4 100644 --- a/src/ui/thread/ProxyConnectionTestThread.h +++ b/src/ui/thread/ProxyConnectionTestTask.h @@ -39,7 +39,7 @@ namespace GpgFrontend::UI { * @brief * */ -class ProxyConnectionTestThread : public QThread { +class ProxyConnectionTestTask : public Thread::Task { Q_OBJECT public: /** @@ -49,9 +49,7 @@ class ProxyConnectionTestThread : public QThread { * @param timeout * @param parent */ - explicit ProxyConnectionTestThread(QString url, int timeout, - QWidget* parent = nullptr) - : QThread(parent), url_(std::move(url)), timeout_(timeout) {} + explicit ProxyConnectionTestTask(QString url, int timeout); signals: /** @@ -68,10 +66,14 @@ class ProxyConnectionTestThread : public QThread { */ void run() override; + private slots: + void slot_process_network_reply(QNetworkReply* reply); + private: - QString url_; ///< - QString result_; ///< - int timeout_ = 500; ///< + QString url_; ///< + QString result_; ///< + int timeout_ = 500; ///< + QNetworkAccessManager* network_manager_; ///< }; } // namespace GpgFrontend::UI diff --git a/src/ui/thread/ProxyConnectionTestThread.cpp b/src/ui/thread/ProxyConnectionTestThread.cpp deleted file mode 100644 index 8b113453..00000000 --- a/src/ui/thread/ProxyConnectionTestThread.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/** - * Copyright (C) 2021 Saturneric - * - * 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. - * - * The source code version of this software was modified and released - * by Saturneric<[email protected]><[email protected]> starting on May 12, 2021. - * - */ - -#include "ProxyConnectionTestThread.h" - -void GpgFrontend::UI::ProxyConnectionTestThread::run() { - QNetworkProxyQuery npq({QUrl(url_)}); - auto proxies_list = QNetworkProxyFactory::systemProxyForQuery(npq); - - if (proxies_list.isEmpty()) { - SPDLOG_DEBUG("no proxy applied"); - } else { - SPDLOG_DEBUG("proxies list hostname: {}", - proxies_list.front().hostName().toStdString()); - } - - SPDLOG_DEBUG("proxies list size: {}", proxies_list.size()); - - auto manager = std::make_unique<QNetworkAccessManager>(nullptr); - QNetworkRequest url_request; - url_request.setUrl(QUrl(url_)); - auto _reply = manager->get(url_request); - - while (_reply->isRunning()) QApplication::processEvents(); - auto _buffer = _reply->readAll(); - if (_reply->error() == QNetworkReply::NoError && !_buffer.isEmpty()) { - result_ = "Reachable"; - } else { - result_ = "Not Reachable"; - } - - _reply->deleteLater(); - - emit SignalProxyConnectionTestResult(result_); -} diff --git a/src/ui/widgets/TextEdit.cpp b/src/ui/widgets/TextEdit.cpp index 4947e179..d22c091a 100644 --- a/src/ui/widgets/TextEdit.cpp +++ b/src/ui/widgets/TextEdit.cpp @@ -603,6 +603,7 @@ void TextEdit::slot_save_status_to_cache_for_revovery() { text_page_data_modified_count_); if (this->text_page_data_modified_count_++ % 3 != 0) return; +#ifdef DEBUG int tab_count = tab_widget_->count(); SPDLOG_DEBUG("current tabs count {}", tab_count); @@ -635,6 +636,7 @@ void TextEdit::slot_save_status_to_cache_for_revovery() { tab_title, raw_text.size()); unsaved_pages.push_back({i, tab_title, raw_text}); } +#endif } } // namespace GpgFrontend::UI diff --git a/src/ui/widgets/VerifyKeyDetailBox.cpp b/src/ui/widgets/VerifyKeyDetailBox.cpp index c6c4982c..555414b4 100644 --- a/src/ui/widgets/VerifyKeyDetailBox.cpp +++ b/src/ui/widgets/VerifyKeyDetailBox.cpp @@ -28,6 +28,7 @@ #include "ui/widgets/VerifyKeyDetailBox.h" +#include "core/function/GlobalSettingStation.h" #include "core/function/gpg/GpgKeyGetter.h" namespace GpgFrontend::UI { @@ -40,8 +41,21 @@ VerifyKeyDetailBox::VerifyKeyDetailBox(const GpgSignature& signature, switch (gpg_err_code(signature.GetStatus())) { case GPG_ERR_NO_PUBKEY: { this->setTitle("A Error Signature"); - auto* importButton = new QPushButton(_("Import from keyserver")); - connect(importButton, &QPushButton::clicked, this, + + // get settings + auto& settings = GlobalSettingStation::GetInstance().GetUISettings(); + // read settings + bool forbid_all_gnupg_connection = false; + try { + forbid_all_gnupg_connection = + settings.lookup("network.forbid_all_gnupg_connection"); + } catch (...) { + SPDLOG_ERROR("setting operation error: forbid_all_gnupg_connection"); + } + + auto* import_button = new QPushButton(_("Import from keyserver")); + import_button->setDisabled(forbid_all_gnupg_connection); + connect(import_button, &QPushButton::clicked, this, &VerifyKeyDetailBox::slot_import_form_key_server); this->setTitle(QString(_("Key not present with id 0x")) + fpr_.c_str()); @@ -52,7 +66,7 @@ VerifyKeyDetailBox::VerifyKeyDetailBox(const GpgSignature& signature, // grid->addWidget(new QLabel(_("Fingerprint:")), 1, 0); grid->addWidget(new QLabel(_("Key not present in key list")), 0, 1); // grid->addWidget(new QLabel(signature->fpr), 1, 1); - grid->addWidget(importButton, 2, 0, 2, 1); + grid->addWidget(import_button, 2, 0, 2, 1); vbox->addLayout(grid); break; |