Skip to content

Commit

Permalink
fix: according to issues and test, apply some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
saturneric committed Aug 5, 2024
2 parents 8e99ff1 + 52be475 commit 795a81b
Show file tree
Hide file tree
Showing 27 changed files with 4,806 additions and 735 deletions.
9 changes: 0 additions & 9 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,6 @@ jobs:
sudo make install
cd ${{github.workspace}}
- name: Build mimalloc (Linux)
run: |
git clone --depth 1 --branch v2.1.7 https://github.com/microsoft/mimalloc.git ${{github.workspace}}/third_party/mimalloc
cd ${{github.workspace}}/third_party/mimalloc
mkdir build && cd build
cmake -G Ninja -DMI_SECURE=ON ..
ninja
sudo ninja install
- name: Build googletest (Linux)
run: |
git clone --depth 1 --branch v1.15.0 https://github.com/google/googletest.git ${{github.workspace}}/third_party/googletest
Expand Down
20 changes: 0 additions & 20 deletions .github/workflows/release-qt5.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,26 +138,6 @@ jobs:
cd ${{github.workspace}}
if: matrix.os == 'ubuntu-20.04'

- name: Build mimalloc (Linux)
run: |
git clone --depth 1 --branch v2.1.7 https://github.com/microsoft/mimalloc.git ${{github.workspace}}/third_party/mimalloc
cd ${{github.workspace}}/third_party/mimalloc
mkdir build && cd build
cmake -G Ninja -DMI_SECURE=ON ..
ninja
sudo ninja install
if: matrix.os == 'ubuntu-20.04'

- name: Build mimalloc (Windows)
shell: msys2 {0}
run: |
git clone --depth 1 --branch v2.1.7 https://github.com/microsoft/mimalloc.git ${{github.workspace}}/third_party/mimalloc
cd ${{github.workspace}}/third_party/mimalloc
mkdir build && cd build
cmake -G Ninja -DMI_SECURE=ON -DCMAKE_INSTALL_PREFIX=$MSYSTEM_PREFIX .. && ninja
ninja install
if: matrix.os == 'windows-2019'

- name: Build googletest (Linux)
run: |
git clone --depth 1 --branch v1.15.0 https://github.com/google/googletest.git ${{github.workspace}}/third_party/googletest
Expand Down
20 changes: 0 additions & 20 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,26 +164,6 @@ jobs:
make install
if: matrix.os == 'windows-2019'

- name: Build mimalloc (Linux)
run: |
git clone --depth 1 --branch v2.1.7 https://github.com/microsoft/mimalloc.git ${{github.workspace}}/third_party/mimalloc
cd ${{github.workspace}}/third_party/mimalloc
mkdir build && cd build
cmake -G Ninja -DMI_SECURE=ON ..
ninja
sudo ninja install
if: matrix.os == 'ubuntu-20.04'

- name: Build mimalloc (Windows)
shell: msys2 {0}
run: |
git clone --depth 1 --branch v2.1.7 https://github.com/microsoft/mimalloc.git ${{github.workspace}}/third_party/mimalloc
cd ${{github.workspace}}/third_party/mimalloc
mkdir build && cd build
cmake -G Ninja -DMI_SECURE=ON -DCMAKE_INSTALL_PREFIX=$MSYSTEM_PREFIX .. && ninja
ninja install
if: matrix.os == 'windows-2019'

- name: Build googletest (Linux)
run: |
git clone --depth 1 --branch v1.15.0 https://github.com/google/googletest.git ${{github.workspace}}/third_party/googletest
Expand Down
1 change: 1 addition & 0 deletions gpgfrontend.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
<file alias="stairs.png">resource/lfs/icons/stairs.png</file>
<file alias="detail.png">resource/lfs/icons/detail.png</file>
<file alias="filter.png">resource/lfs/icons/filter.png</file>
<file alias="setting.png">resource/lfs/icons/setting.png</file>
</qresource>
<qresource prefix="/test/key">
<file alias="pv1.key">resource/lfs/test/data/pv1.key</file>
Expand Down
Binary file added resource/lfs/icons/setting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,668 changes: 2,366 additions & 302 deletions resource/lfs/locale/ts/GpgFrontend.de_DE.ts

Large diffs are not rendered by default.

2,666 changes: 2,365 additions & 301 deletions resource/lfs/locale/ts/GpgFrontend.zh_CN.ts

Large diffs are not rendered by default.

13 changes: 0 additions & 13 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ endif()

find_package(OpenSSL REQUIRED)

# mimalloc
if(NOT APPLE)
find_package(mimalloc REQUIRED)
endif()

# Set Build Information
configure_file(${CMAKE_SOURCE_DIR}/src/GpgFrontend.h.in ${CMAKE_SOURCE_DIR}/src/GpgFrontend.h @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/src/GpgFrontendBuildInfo.h.in ${CMAKE_SOURCE_DIR}/src/GpgFrontendBuildInfo.h @ONLY)
Expand Down Expand Up @@ -283,14 +278,6 @@ if(BUILD_APPLICATION AND MINGW)
file(GLOB _libDllPath "${MSYS64_BIN_PATH}/libgpgfrontend_*.dll")
list(APPEND ALL_RUNTIME_DEP_PATH_LIST ${_libDllPath})

unset(_libDllPath)
file(GLOB _libDllPath "${MSYS64_BIN_PATH}/libmimalloc*.dll")
list(APPEND ALL_RUNTIME_DEP_PATH_LIST ${_libDllPath})

unset(_libDllPath)
file(GLOB _libDllPath "${MSYS64_BIN_PATH}/mimalloc*.dll")
list(APPEND ALL_RUNTIME_DEP_PATH_LIST ${_libDllPath})

unset(_libDllPath)
file(GLOB _libDllPath "${MSYS64_BIN_PATH}/libarchive*.dll")
list(APPEND ALL_RUNTIME_DEP_PATH_LIST ${_libDllPath})
Expand Down
5 changes: 0 additions & 5 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ generate_export_header(gpgfrontend_core EXPORT_FILE_NAME "${_export_file}")
# compile definitions
target_compile_definitions(gpgfrontend_core PRIVATE GF_CORE_PRIVATE)

# mimalloc (except apple macos)
if(NOT APPLE)
target_link_libraries(gpgfrontend_core PUBLIC mimalloc)
endif()

# qt-aes
target_sources(gpgfrontend_core PRIVATE
${CMAKE_SOURCE_DIR}/third_party/qt-aes/qaesencryption.cpp)
Expand Down
14 changes: 7 additions & 7 deletions src/core/GpgCoreInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,6 @@ void InitGpgFrontendCore(CoreInitArgs args) {
auto custom_key_database_path =
settings.value("gnupg/custom_key_database_path", QString{}).toString();

auto custom_gnupg_install_path =
settings.value("gnupg/custom_gnupg_install_path", QString{}).toString();

auto use_pinentry_as_password_input_dialog =
settings
.value("gnupg/use_pinentry_as_password_input_dialog",
Expand All @@ -327,10 +324,14 @@ void InitGpgFrontendCore(CoreInitArgs args) {
!custom_key_database_path.isEmpty()) {
if (VerifyKeyDatabasePath(QFileInfo(custom_key_database_path))) {
key_database_fs_path =
QFileInfo(custom_gnupg_install_path).absoluteFilePath();
QFileInfo(custom_key_database_path).absoluteFilePath();
LOG_D() << "use custom gpg key database: " << key_database_fs_path
<< "raw:" << custom_key_database_path;

} else {
LOG_W() << "custom gpg key database path is not suitable: "
<< key_database_fs_path;
<< key_database_fs_path
<< "raw:" << custom_key_database_path;
}
} else {

Expand All @@ -354,8 +355,7 @@ void InitGpgFrontendCore(CoreInitArgs args) {

// set custom gnupg path
if (!gnupg_install_fs_path.isEmpty()) {
args.custom_gpgconf = true;
args.custom_gpgconf_path = gnupg_install_fs_path;
args.gpgconf_path = gnupg_install_fs_path;
}

args.offline_mode = forbid_all_gnupg_connection;
Expand Down
30 changes: 5 additions & 25 deletions src/core/function/SecureMemoryAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,42 +28,22 @@

#include "SecureMemoryAllocator.h"

namespace GpgFrontend {
#include <cstdlib>

#if defined(__APPLE__) && defined(__MACH__)
namespace GpgFrontend {

auto SecureMemoryAllocator::Allocate(std::size_t size) -> void* {
auto* addr = malloc(size);
auto* addr = std::malloc(size);
if (addr == nullptr) FLOG_F("malloc failed!");
return addr;
}

auto SecureMemoryAllocator::Reallocate(void* ptr, std::size_t size) -> void* {
auto* addr = realloc(ptr, size);
auto* addr = std::realloc(ptr, size);
if (addr == nullptr) FLOG_F("realloc failed!");
return addr;
}

void SecureMemoryAllocator::Deallocate(void* p) { free(p); }

#else

#include <mimalloc.h>

auto SecureMemoryAllocator::Allocate(std::size_t size) -> void* {
auto* addr = mi_malloc(size);
if (addr == nullptr) FLOG_F("malloc failed!");
return addr;
}

auto SecureMemoryAllocator::Reallocate(void* ptr, std::size_t size) -> void* {
auto* addr = mi_realloc(ptr, size);
if (addr == nullptr) FLOG_F("realloc memory failed!");
return addr;
}

void SecureMemoryAllocator::Deallocate(void* p) { mi_free(p); }

#endif
void SecureMemoryAllocator::Deallocate(void* p) { std::free(p); }

} // namespace GpgFrontend
10 changes: 5 additions & 5 deletions src/core/function/gpg/GpgContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,10 @@ class GpgContext::Impl {
const GpgContextInitArgs &args) -> bool {
assert(ctx != nullptr);

if (args.custom_gpgconf && !args.custom_gpgconf_path.isEmpty()) {
LOG_D() << "set custom gpgconf path: " << args.custom_gpgconf_path;
auto err =
gpgme_ctx_set_engine_info(ctx, GPGME_PROTOCOL_GPGCONF,
args.custom_gpgconf_path.toUtf8(), nullptr);
if (!args.gpgconf_path.isEmpty()) {
LOG_D() << "set custom gpgconf path: " << args.gpgconf_path;
auto err = gpgme_ctx_set_engine_info(ctx, GPGME_PROTOCOL_GPGCONF,
args.gpgconf_path.toUtf8(), nullptr);

if (CheckGpgError(err) != GPG_ERR_NO_ERROR) {
LOG_W() << "set gpg context engine info error: "
Expand Down Expand Up @@ -284,6 +283,7 @@ class GpgContext::Impl {

// set custom gpg key db path
if (!args_.db_path.isEmpty()) {
LOG_D() << "set context database path to" << args_.db_path;
Module::UpsertRTValue("core", "gpgme.ctx.database_path", args_.db_path);
}

Expand Down
3 changes: 1 addition & 2 deletions src/core/function/gpg/GpgContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ struct GpgContextInitArgs {
bool offline_mode = false; ///<
bool auto_import_missing_key = false; ///<

bool custom_gpgconf = false; ///<
QString custom_gpgconf_path; ///<
QString gpgconf_path; ///<

bool use_pinentry = false; ///<
};
Expand Down
3 changes: 2 additions & 1 deletion src/core/thread/Task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ class Task::Impl {
}
};

Task::Task(QString name) : p_(new Impl(this, name)) {}
Task::Task(QString name)
: p_(SecureCreateUniqueObject<Task::Impl>(this, name)) {}

Task::Task(TaskRunnable runnable, QString name, DataObjectPtr data_object)
: p_(SecureCreateUniqueObject<Impl>(this, runnable, name, data_object)) {}
Expand Down
7 changes: 3 additions & 4 deletions src/ui/GpgFrontendUIInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ QList<QByteArray> loaded_qm_datum;
extern void InitUITranslations();

void WaitEnvCheckingProcess() {
FLOG_D("need to waiting for env checking process");
FLOG_D("need to wait for env checking process");

// create and show loading window before starting the main window
auto* waiting_dialog = new QProgressDialog();
Expand Down Expand Up @@ -86,8 +86,7 @@ void WaitEnvCheckingProcess() {

auto env_state =
Module::RetrieveRTValueTypedOrDefault<>("core", "env.state.all", 0);
FLOG_D("ui is ready to waiting for env initialized, env_state: %d",
env_state);
FLOG_D("ui is ready to wait for env initialized, env_state: %d", env_state);

// check twice to avoid some unlucky sitations
if (env_state == 1) {
Expand Down Expand Up @@ -200,7 +199,7 @@ void InitGpgFrontendUI(QApplication* /*app*/) {
void WaitingAllInitializationFinished() {
if (Module::RetrieveRTValueTypedOrDefault<>("core", "env.state.all", 0) ==
0) {
LOG_D() << "ui init is done, but cor doesn't, going to waiting for core...";
LOG_D() << "ui init is done, but core doesn't, going to wait for core...";
WaitEnvCheckingProcess();
}
LOG_D() << "application fully initialized...";
Expand Down
2 changes: 1 addition & 1 deletion src/ui/UserInterfaceUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ void CommonUtils::RemoveKeyFromFavourite(const GpgKey &key) {
*
*/
void CommonUtils::ImportKeyFromKeyServer(const KeyIdArgsList &key_ids) {
KeyServerSO key_server(SettingsObject("general_settings_state"));
KeyServerSO key_server(SettingsObject("key_server"));
auto target_keyserver = key_server.GetTargetServer();

auto *task = new KeyServerImportTask(target_keyserver, key_ids);
Expand Down
12 changes: 12 additions & 0 deletions src/ui/dialog/controller/GnuPGControllerDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,18 @@ GnuPGControllerDialog::GnuPGControllerDialog(QWidget* parent)
this->slot_set_restart_needed(kDeepRestartCode);
});

connect(ui_->keyDatabaseUseCustomCheckBox, &QCheckBox::stateChanged, this,
[=](int) {
// announce the restart
this->slot_set_restart_needed(kDeepRestartCode);
});

connect(ui_->useCustomGnuPGInstallPathCheckBox, &QCheckBox::stateChanged,
this, [=](int) {
// announce the restart
this->slot_set_restart_needed(kDeepRestartCode);
});

#if defined(__APPLE__) && defined(__MACH__)
// macOS style settings
ui_->buttonBox->setDisabled(true);
Expand Down
12 changes: 8 additions & 4 deletions src/ui/dialog/import_export/KeyServerImportDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,15 @@ auto KeyServerImportDialog::create_combo_box() -> QComboBox* {
combo_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);

try {
KeyServerSO key_server(SettingsObject("general_settings_state"));
KeyServerSO key_server(SettingsObject("key_server"));
const auto& key_server_list = key_server.server_list;
for (const auto& key_server : key_server_list) {
combo_box->addItem(key_server);
}
combo_box->setCurrentText(key_server.GetTargetServer());
auto target_key_server = key_server.GetTargetServer();
LOG_D() << "set combo box to key server: " << target_key_server;

combo_box->setCurrentText(target_key_server);
} catch (...) {
FLOG_W("setting operation error server_list default_server");
}
Expand Down Expand Up @@ -207,7 +210,7 @@ void KeyServerImportDialog::slot_search() {
}

void KeyServerImportDialog::slot_search_finished(
QNetworkReply::NetworkError error, QByteArray buffer) {
QNetworkReply::NetworkError error, QString err_string, QByteArray buffer) {
keys_table_->clearContents();
keys_table_->setRowCount(0);

Expand All @@ -226,6 +229,7 @@ void KeyServerImportDialog::slot_search_finished(
break;
default:
set_message(tr("Connection Error"), true);
QMessageBox::critical(this, tr("Connection Error"), err_string);
}
return;
}
Expand Down Expand Up @@ -380,7 +384,7 @@ void KeyServerImportDialog::SlotImport(const KeyIdArgsListPtr& keys) {
target_keyserver = key_server_combo_box_->currentText();
}
if (target_keyserver.isEmpty()) {
KeyServerSO key_server(SettingsObject("general_settings_state"));
KeyServerSO key_server(SettingsObject("key_server"));
target_keyserver = key_server.GetTargetServer();
}
std::vector<QString> key_ids;
Expand Down
2 changes: 1 addition & 1 deletion src/ui/dialog/import_export/KeyServerImportDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class KeyServerImportDialog : public GeneralDialog {
*
*/
void slot_search_finished(QNetworkReply::NetworkError reply,
QByteArray buffer);
QString err_string, QByteArray buffer);

/**
* @brief
Expand Down
11 changes: 6 additions & 5 deletions src/ui/dialog/import_export/KeyUploadDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,12 @@ void KeyUploadDialog::SlotUpload() {

void KeyUploadDialog::slot_upload_key_to_server(
const GpgFrontend::GFBuffer& keys_data) {
KeyServerSO key_server(SettingsObject("general_settings_state"));
auto target_keyserver = key_server.GetTargetServer();
KeyServerSO key_server(SettingsObject("key_server"));
auto target_key_server = key_server.GetTargetServer();

QUrl req_url(target_keyserver + "/pks/add");
auto* qnam = new QNetworkAccessManager(this);
LOG_D() << "upload public key using key server" << target_key_server;
QUrl req_url(target_key_server + "/pks/add");
auto* q_nam = new QNetworkAccessManager(this);

// Building Post Data
QByteArray post_data;
Expand All @@ -124,7 +125,7 @@ void KeyUploadDialog::slot_upload_key_to_server(
post_data.append("keytext").append("=").append(data);

// Send Post Data
QNetworkReply* reply = qnam->post(request, post_data);
QNetworkReply* reply = q_nam->post(request, post_data);
connect(reply, &QNetworkReply::finished, this,
&KeyUploadDialog::slot_upload_finished);

Expand Down
Loading

0 comments on commit 795a81b

Please sign in to comment.