diff options
Diffstat (limited to '')
102 files changed, 1660 insertions, 1519 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f4db662..c6ad717a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ project(GpgFrontend VERSION 1.3.1 LANGUAGES CXX) message(STATUS "GPGFrontend Build Configuration Started CMAKE Version ${CMAKE_VERSION}") # C++ -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON) @@ -26,6 +26,18 @@ else() message(STATUS "Set CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE}") endif() +if(BUILD_CONFIG) + if(${BUILD_CONFIG} STREQUAL "test") + message(STATUS "Switch TEST_BUILD") + set(TEST_BUILD 1) + set(AppName GpgFrontendTest) + endif() +else() + message(STATUS "Switch Default FULL_APPLICATION_BUILD") + set(FULL_APPLICATION_BUILD 1) + set(AppName GpgFrontend) +endif() + if(EXECUTABLE_OUTPUT_PATH) message(STATUS "PreCheck EXECUTABLE_OUTPUT_PATH ${EXECUTABLE_OUTPUT_PATH}") else() @@ -69,10 +81,8 @@ if(GIT_FOUND) ) endif() - set(BUILD_VERSION ${PROJECT_VERSION}_${CMAKE_SYSTEM}_${CMAKE_SYSTEM_PROCESSOR}_${CMAKE_BUILD_TYPE}) set(GIT_VERSION ${GIT_BRANCH_NAME}_${GIT_COMMIT_HASH}) -set(AppName GpgFrontend) string(TIMESTAMP BUILD_TIMESTAMP "%Y-%m-%d %H:%M:%S") message(STATUS "Build Timestamp ${BUILD_TIMESTAMP}") @@ -143,7 +153,34 @@ message(STATUS "OS_PLATFORM ${OS_PLATFORM}") find_package(Qt5 COMPONENTS Core Test Widgets PrintSupport Network LinguistTools REQUIRED) +if(FULL_APPLICATION_BUILD) + message(STATUS "Build Full Application") + set(QT_MOC_CONFIG 1) + set(GPG_CORE 1) + set(UI_CORE 1) + set(SMTP_SUPPORT 1) + set(SERVER_SUPPORT 1) + set(ADVANCE_SUPPORT 1) + set(APPLICATION_BUILD 1) + set(BASIC_ENV_CONFIG 1) + set(MULTI_LANG_SUPPORT 1) +elseif(TEST_BUILD) + message(STATUS "Build Test Cases") + + if(MODULES) + else() + message(STATUS "Build Default Modules") + set(QT_MOC_CONFIG 1) + set(GPG_CORE 1) + endif() + +endif() + add_subdirectory(src) +if(TEST_BUILD) + add_subdirectory(test) +endif() + diff --git a/include/GpgFrontend.h.in b/include/GpgFrontend.h.in index 6460967c..78d3e44f 100644 --- a/include/GpgFrontend.h.in +++ b/include/GpgFrontend.h.in @@ -35,6 +35,8 @@ #include <cerrno> #include <utility> #include <list> +#include <span> +#include <mutex> /** * QT Headers diff --git a/include/MainWindow.h b/include/MainWindow.h index 176a8914..34a3130a 100644 --- a/include/MainWindow.h +++ b/include/MainWindow.h @@ -402,7 +402,7 @@ private: KeyList *mKeyList; InfoBoardWidget *infoBoard; - GpgME::GpgContext *mCtx; + GpgFrontend::GpgContext *mCtx; KeyMgmt *keyMgmt; KeyServerImportDialog *importDialog; /**< TODO */ diff --git a/include/advance/UnknownSignersChecker.h b/include/advance/UnknownSignersChecker.h index 8f644de6..56085265 100644 --- a/include/advance/UnknownSignersChecker.h +++ b/include/advance/UnknownSignersChecker.h @@ -31,7 +31,7 @@ class UnknownSignersChecker : public QObject { Q_OBJECT public: - UnknownSignersChecker(GpgME::GpgContext *ctx, gpgme_verify_result_t result); + UnknownSignersChecker(GpgFrontend::GpgContext *ctx, gpgme_verify_result_t result); void start(); @@ -39,7 +39,7 @@ private: QString appPath; QSettings settings; - GpgME::GpgContext *mCtx; + GpgFrontend::GpgContext *mCtx; gpgme_verify_result_t mResult; QVector<QString> unknownFprs; diff --git a/include/gpg/GpgContext.h b/include/gpg/GpgContext.h index 75949f25..7b335daa 100644 --- a/include/gpg/GpgContext.h +++ b/include/gpg/GpgContext.h @@ -29,10 +29,11 @@ #include "GpgConstants.h" #include "GpgGenKeyInfo.h" -#include "GpgKey.h" +#include "GpgModel.h" #include "GpgInfo.h" +#include "GpgFunctionObject.h" -using GpgKeyList = std::list<GpgKey>; +using GpgKeyList = std::list<GpgFrontend::GpgKey>; class GpgImportedKey { public: @@ -62,19 +63,22 @@ public: GpgImportedKeyList importedKeys; }; -namespace GpgME { +namespace GpgFrontend { + + static gpgme_error_t check_gpg_error(gpgme_error_t err); + + static gpgme_error_t check_gpg_error(gpgme_error_t gpgmeError, const std::string &comment); /** * Custom Encapsulation of GpgME APIs */ - class GpgContext : public QObject { - Q_OBJECT + class GpgContext : public SingletonFunctionObject<GpgContext> { public: GpgContext(); - ~GpgContext() override; + ~GpgContext() override = default; [[nodiscard]] bool isGood() const; @@ -92,45 +96,9 @@ namespace GpgME { void deleteKeys(QStringList *uidList); - gpg_error_t encrypt(QVector<GpgKey> &keys, const QByteArray &inBuffer, QByteArray *outBuffer, - gpgme_encrypt_result_t *result); - - gpgme_error_t encryptSign(QVector<GpgKey> &keys, QVector<GpgKey> &signers, const QByteArray &inBuffer, - QByteArray *outBuffer, gpgme_encrypt_result_t *encr_result, - gpgme_sign_result_t *sign_result); - - gpgme_error_t decrypt(const QByteArray &inBuffer, QByteArray *outBuffer, gpgme_decrypt_result_t *result); - - gpgme_error_t - decryptVerify(const QByteArray &inBuffer, QByteArray *outBuffer, gpgme_decrypt_result_t *decrypt_result, - gpgme_verify_result_t *verify_result); - void clearPasswordCache(); - bool exportSecretKey(const GpgKey &key, QByteArray *outBuffer); - - void getSigners(QVector<GpgKey> &signer, gpgme_ctx_t ctx); - - static void setSigners(const QVector<GpgKey> &keys, gpgme_ctx_t ctx); - - bool signKey(const GpgKey &target, const QVector<GpgKey> &keys, const QString &uid, - const QDateTime *expires); - - bool revSign(const GpgKey &key, const GpgKeySignature &signature); - - gpgme_error_t verify(QByteArray *inBuffer, QByteArray *sigBuffer, gpgme_verify_result_t *result); - - gpg_error_t - sign(const QVector<GpgKey> &keys, const QByteArray &inBuffer, QByteArray *outBuffer, - gpgme_sig_mode_t mode, gpgme_sign_result_t *result = nullptr, bool default_ctx = true); - - bool addUID(const GpgKey &key, const GpgUID &uid); - - bool revUID(const GpgKey &key, const GpgUID &uid); - - bool setPrimaryUID(const GpgKey &key, const GpgUID &uid); - - bool setExpire(const GpgKey &key, const GpgSubKey *subkey, QDateTime *expires); + bool exportSecretKey(const GpgKey &key, QByteArray *outBuffer) const; void generateRevokeCert(const GpgKey &key, const QString &outputFileName); @@ -151,12 +119,6 @@ namespace GpgME { */ static void preventNoDataErr(QByteArray *in); - GpgKey getKeyByFpr(const QString &fpr); - - GpgKey getKeyById(const QString &id); - - static QString gpgErrString(gpgme_error_t err); - static QString getGpgmeVersion(); /** @@ -171,6 +133,8 @@ namespace GpgME { static QString beautifyFingerprint(QString fingerprint); + operator gpgme_ctx_t() const { return _ctx_ref.get(); } + signals: void signalKeyDBChanged(); @@ -189,7 +153,9 @@ namespace GpgME { GpgInfo info; - gpgme_ctx_t mCtx{}; + using CtxRefHandler = std::unique_ptr<struct gpgme_context, std::function<void(gpgme_ctx_t)>>; + CtxRefHandler _ctx_ref = nullptr; + gpgme_data_t in{}; gpgme_error_t err; bool debug; @@ -199,18 +165,10 @@ namespace GpgME { QSettings settings; GpgKeyList mKeyList; - QMap<QString, GpgKey *> mKeyMap; - - gpgme_ctx_t create_ctx(); - - static gpgme_error_t readToBuffer(gpgme_data_t dataIn, QByteArray *outBuffer); + std::map<QString, GpgKey> mKeyMap; void fetch_keys(); - static void checkErr(gpgme_error_t gpgmeError); - - static void checkErr(gpgme_error_t gpgmeError, const QString &comment); - static gpgme_error_t passphraseCb(void *hook, const char *uid_hint, const char *passphrase_info, int last_was_bad, int fd); diff --git a/include/gpg/GpgFileOpera.h b/include/gpg/GpgFileOpera.h index 9b5e118c..e7ca0c8d 100644 --- a/include/gpg/GpgFileOpera.h +++ b/include/gpg/GpgFileOpera.h @@ -30,20 +30,20 @@ class GpgFileOpera { public: - static gpgme_error_t encryptFile(GpgME::GpgContext *ctx, QVector<GpgKey> &keys, const QString &mPath, + static gpgme_error_t encryptFile(GpgFrontend::GpgContext *ctx, QVector<GpgKey> &keys, const QString &mPath, gpgme_encrypt_result_t *result); - static gpgme_error_t decryptFile(GpgME::GpgContext *ctx, const QString &mPath, gpgme_decrypt_result_t *result); + static gpgme_error_t decryptFile(GpgFrontend::GpgContext *ctx, const QString &mPath, gpgme_decrypt_result_t *result); - static gpgme_error_t signFile(GpgME::GpgContext *ctx, QVector<GpgKey> &keys, const QString &mPath, + static gpgme_error_t signFile(GpgFrontend::GpgContext *ctx, QVector<GpgKey> &keys, const QString &mPath, gpgme_sign_result_t *result); - static gpgme_error_t verifyFile(GpgME::GpgContext *ctx, const QString &mPath, gpgme_verify_result_t *result); + static gpgme_error_t verifyFile(GpgFrontend::GpgContext *ctx, const QString &mPath, gpgme_verify_result_t *result); static gpg_error_t - encryptSignFile(GpgME::GpgContext *ctx, QVector<GpgKey> &keys, const QString &mPath, gpgme_encrypt_result_t *encr_res, gpgme_sign_result_t *sign_res); + encryptSignFile(GpgFrontend::GpgContext *ctx, QVector<GpgKey> &keys, const QString &mPath, gpgme_encrypt_result_t *encr_res, gpgme_sign_result_t *sign_res); - static gpg_error_t decryptVerifyFile(GpgME::GpgContext *ctx, const QString &mPath, gpgme_decrypt_result_t *decr_res, gpgme_verify_result_t *verify_res); + static gpg_error_t decryptVerifyFile(GpgFrontend::GpgContext *ctx, const QString &mPath, gpgme_decrypt_result_t *decr_res, gpgme_verify_result_t *verify_res); }; diff --git a/include/gpg/GpgFunctionObject.h b/include/gpg/GpgFunctionObject.h new file mode 100644 index 00000000..22280706 --- /dev/null +++ b/include/gpg/GpgFunctionObject.h @@ -0,0 +1,70 @@ +/** + * 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. + * + * Foobar 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 Foobar. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from gpg4usb-team. + * Their source code version also complies with GNU General Public License. + * + * The source code version of this software was modified and released + * by Saturneric<[email protected]> starting on May 12, 2021. + * + */ + +#ifndef GPGFRONTEND_ZH_CN_TS_FUNCTIONOBJECT_H +#define GPGFRONTEND_ZH_CN_TS_FUNCTIONOBJECT_H + +#include "GpgFrontend.h" + +namespace GpgFrontend { + template<typename T> + class SingletonFunctionObject { + public: + + static T &getInstance() { + std::lock_guard<std::mutex> guard(_instance_mutex); + if(_instance == nullptr) _instance = std::make_unique<T>(); + return *_instance; + } + + SingletonFunctionObject(T&&) = delete; + + SingletonFunctionObject(const T&) = delete; + + void operator= (const T&) = delete; + + protected: + + SingletonFunctionObject() = default; + + virtual ~SingletonFunctionObject() = default; + + private: + + static std::mutex _instance_mutex; + static std::unique_ptr<T> _instance; + }; + + template<typename T> + std::mutex SingletonFunctionObject<T>::_instance_mutex; + + template<typename T> + std::unique_ptr<T> SingletonFunctionObject<T>::_instance = nullptr; + +} + + + + +#endif //GPGFRONTEND_ZH_CN_TS_FUNCTIONOBJECT_H diff --git a/include/gpg/GpgKey.h b/include/gpg/GpgKey.h deleted file mode 100644 index 9bf33111..00000000 --- a/include/gpg/GpgKey.h +++ /dev/null @@ -1,87 +0,0 @@ -/** - * 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. - * - * Foobar 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 Foobar. If not, see <https://www.gnu.org/licenses/>. - * - * The initial version of the source code is inherited from gpg4usb-team. - * Their source code version also complies with GNU General Public License. - * - * The source code version of this software was modified and released - * by Saturneric<[email protected]> starting on May 12, 2021. - * - */ - -#ifndef GPGFRONTEND_GPGKEY_H -#define GPGFRONTEND_GPGKEY_H - -#include "GpgUID.h" -#include "GpgSubKey.h" - -class GpgKey { -public: - - QString id; - QString name; - QString email; - QString comment; - QString fpr; - QString protocol; - QString owner_trust; - QString pubkey_algo; - QDateTime last_update; - QDateTime expires; - QDateTime create_time; - - unsigned int length{}; - - bool can_encrypt{}; - bool can_sign{}; - bool can_certify{}; - bool can_authenticate{}; - - - bool is_private_key{}; - bool expired{}; - bool revoked{}; - bool disabled{}; - - bool has_master_key{}; - - bool good = false; - - QVector<GpgSubKey> subKeys; - - QVector<GpgUID> uids; - - gpgme_key_t key_refer = nullptr; - - explicit GpgKey(gpgme_key_t key = nullptr); - - GpgKey(const GpgKey &k); - - GpgKey(GpgKey &&k) noexcept; - - GpgKey& operator=(const GpgKey &k); - - GpgKey& operator=(GpgKey &&k) noexcept; - - ~GpgKey(); - - void parse(gpgme_key_t key); - - void swapKeyRefer(gpgme_key_t key); -}; - - -#endif //GPGFRONTEND_GPGKEY_H diff --git a/include/gpg/GpgSubKey.h b/include/gpg/GpgModel.h index f2da9e9e..c0cb7ec3 100644 --- a/include/gpg/GpgSubKey.h +++ b/include/gpg/GpgModel.h @@ -21,44 +21,26 @@ * by Saturneric<[email protected]> starting on May 12, 2021. * */ -#ifndef GPGFRONTEND_GPGSUBKEY_H -#define GPGFRONTEND_GPGSUBKEY_H -#include "GpgFrontend.h" +#ifndef GPGFRONTEND_ZH_CN_TS_GPGMODEL_H +#define GPGFRONTEND_ZH_CN_TS_GPGMODEL_H -struct GpgSubKey { +#include "gpg/model/GpgKey.h" +#include "gpg/model/GpgSubKey.h" +#include "gpg/model/GpgKeySignature.h" +#include "gpg/model/GpgUID.h" - QString id; - QString fpr; +namespace GpgFrontend { - QString pubkey_algo; + using KeyIdArgsList = std::span<std::string>; - unsigned int length; + using KeyFprArgsList = std::span<std::string>; - bool can_encrypt{}; - bool can_sign{}; - bool can_certify{}; - bool can_authenticate{}; + using KeyArgsList = std::span<GpgKey>; + using KeyPtr = std::unique_ptr<GpgKey>; - bool is_private_key{}; - bool expired{}; - bool revoked{}; - bool disabled{}; - bool secret{}; - bool is_cardkey{}; + using KeyPtrArgsList = std::initializer_list<KeyPtr>; +} - QDateTime timestamp; - QDateTime expires; - - explicit GpgSubKey(gpgme_subkey_t key = nullptr); - - GpgSubKey(GpgSubKey &&) noexcept = default; - GpgSubKey(const GpgSubKey &) = default; - GpgSubKey& operator=(GpgSubKey &&) noexcept = default; - GpgSubKey& operator=(const GpgSubKey &) = default; - -}; - - -#endif //GPGFRONTEND_GPGSUBKEY_H +#endif //GPGFRONTEND_ZH_CN_TS_GPGMODEL_H diff --git a/include/gpg/function/BasicOperator.h b/include/gpg/function/BasicOperator.h new file mode 100644 index 00000000..8291b72a --- /dev/null +++ b/include/gpg/function/BasicOperator.h @@ -0,0 +1,81 @@ +/** + * 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. + * + * Foobar 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 Foobar. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from gpg4usb-team. + * Their source code version also complies with GNU General Public License. + * + * The source code version of this software was modified and released + * by Saturneric<[email protected]> starting on May 12, 2021. + * + */ + +#ifndef GPGFRONTEND_ZH_CN_TS_BASICOPERATOR_H +#define GPGFRONTEND_ZH_CN_TS_BASICOPERATOR_H + +#include "GpgFrontend.h" +#include "gpg/GpgModel.h" +#include "gpg/GpgContext.h" +#include "gpg/GpgFunctionObject.h" + +namespace GpgFrontend { + + using BypeArrayPtr = std::unique_ptr<QByteArray>; + using BypeArrayRef = QByteArray &; + + using GpgEncrResult = std::unique_ptr<struct _gpgme_op_encrypt_result, std::function<void( + gpgme_encrypt_result_t)>>; + using GpgDecrResult = std::unique_ptr<struct _gpgme_op_decrypt_result, std::function<void( + gpgme_decrypt_result_t)>>; + using GpgSignResult = std::unique_ptr<struct _gpgme_op_sign_result, std::function<void( + gpgme_sign_result_t)>>; + using GpgVerifyResult = std::unique_ptr<struct _gpgme_op_verify_result, std::function<void( + gpgme_verify_result_t)>>; + + class BasicOperator : public SingletonFunctionObject<BasicOperator> { + public: + + gpg_error_t encrypt(std::vector<GpgKey> &keys, BypeArrayRef in_buffer, BypeArrayPtr &out_buffer, + GpgEncrResult &result); + + gpgme_error_t encryptSign(std::vector<GpgKey> &keys, std::vector<GpgKey> &signers, BypeArrayRef in_buffer, + BypeArrayPtr &out_buffer, GpgEncrResult &encr_result, + GpgSignResult &sign_result); + + gpgme_error_t decrypt(BypeArrayRef in_buffer, BypeArrayPtr &out_buffer, GpgDecrResult &result); + + gpgme_error_t + decryptVerify(BypeArrayRef in_buffer, BypeArrayPtr &out_buffer, GpgDecrResult &decrypt_result, + GpgVerifyResult &verify_result); + + gpgme_error_t verify(BypeArrayRef in_buffer, BypeArrayRef sig_buffer, GpgVerifyResult &result) const; + + gpg_error_t + sign(KeyFprArgsList key_fprs, BypeArrayRef in_buffer, BypeArrayPtr &out_buffer, gpgme_sig_mode_t mode, + GpgSignResult &result); + + void setSigners(KeyArgsList keys); + + std::unique_ptr<std::vector<GpgKey>> getSigners(); + + private: + + GpgContext &ctx = GpgContext::getInstance(); + + }; +} + + +#endif //GPGFRONTEND_ZH_CN_TS_BASICOPERATOR_H diff --git a/include/gpg/GpgUID.h b/include/gpg/function/GpgKeyGetter.h index 6fb09446..87307f1b 100644 --- a/include/gpg/GpgUID.h +++ b/include/gpg/function/GpgKeyGetter.h @@ -22,39 +22,34 @@ * */ -#ifndef GPGFRONTEND_GPGUID_H -#define GPGFRONTEND_GPGUID_H - -#include <utility> +#ifndef GPGFRONTEND_ZH_CN_TS_GPGKEYGETTER_H +#define GPGFRONTEND_ZH_CN_TS_GPGKEYGETTER_H #include "GpgFrontend.h" -#include "GpgKeySignature.h" +#include "gpg/GpgModel.h" +#include "gpg/GpgContext.h" +#include "gpg/GpgFunctionObject.h" -struct GpgUID { +namespace GpgFrontend { - QString name{}; + class GpgKeyGetter : public SingletonFunctionObject<GpgKeyGetter>{ - QString email{}; + public: - QString comment{}; + GpgKey &&getKey(const std::string &fpr); - QString uid{}; + GpgKey &&getPubkey(const std::string &fpr); - bool revoked{}; + GpgKeyGetter() = default; - bool invalid{}; + private: - QVector<GpgKeySignature> signatures; + GpgContext &ctx = GpgContext::getInstance(); - GpgUID() = default; + }; +} - explicit GpgUID(gpgme_user_id_t user_id); - GpgUID(GpgUID &&) noexcept = default; - GpgUID(const GpgUID &) = default; - GpgUID& operator=(GpgUID &&) noexcept = default; - GpgUID& operator=(const GpgUID &) = default; -}; -#endif //GPGFRONTEND_GPGUID_H
\ No newline at end of file +#endif //GPGFRONTEND_ZH_CN_TS_GPGKEYGETTER_H diff --git a/include/gpg/function/GpgKeyManager.h b/include/gpg/function/GpgKeyManager.h new file mode 100644 index 00000000..0c11e1dc --- /dev/null +++ b/include/gpg/function/GpgKeyManager.h @@ -0,0 +1,62 @@ +/** + * 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. + * + * Foobar 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 Foobar. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from gpg4usb-team. + * Their source code version also complies with GNU General Public License. + * + * The source code version of this software was modified and released + * by Saturneric<[email protected]> starting on May 12, 2021. + * + */ + + +#ifndef GPGFRONTEND_ZH_CN_TS_GPGKEYMANAGER_H +#define GPGFRONTEND_ZH_CN_TS_GPGKEYMANAGER_H + +#include "GpgFrontend.h" +#include "gpg/GpgModel.h" +#include "gpg/GpgContext.h" +#include "gpg/GpgFunctionObject.h" + +namespace GpgFrontend { + + class GpgKeyManager : public SingletonFunctionObject<GpgKeyManager> { + public: + + /** + * Sign a key pair(actually a certain uid) + * @param target target key pair + * @param uid target + * @param expires expire date and time of the signature + * @return if successful + */ + bool signKey(const GpgKey &target, KeyArgsList &keys, const QString &uid, + std::unique_ptr<QDateTime> &expires); + + bool revSign(const GpgKey &key, const GpgKeySignature &signature); + + bool setExpire(const GpgKey &key, std::unique_ptr<GpgSubKey> &subkey, std::unique_ptr<QDateTime> &expires); + + private: + + GpgContext &ctx = GpgContext::getInstance(); + + }; + +} + + +#endif //GPGFRONTEND_ZH_CN_TS_GPGKEYMANAGER_H diff --git a/include/gpg/function/UidOperator.h b/include/gpg/function/UidOperator.h new file mode 100644 index 00000000..352f210e --- /dev/null +++ b/include/gpg/function/UidOperator.h @@ -0,0 +1,71 @@ +/** + * 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. + * + * Foobar 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 Foobar. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from gpg4usb-team. + * Their source code version also complies with GNU General Public License. + * + * The source code version of this software was modified and released + * by Saturneric<[email protected]> starting on May 12, 2021. + * + */ + +#ifndef GPGFRONTEND_ZH_CN_TS_UIDOPERATOR_H +#define GPGFRONTEND_ZH_CN_TS_UIDOPERATOR_H + +#include "GpgFrontend.h" +#include "gpg/GpgModel.h" +#include "gpg/GpgContext.h" + +namespace GpgFrontend { + + class UidOperator { + public: + + /** + * create a new uid in certain key pair + * @param key target key pair + * @param uid uid args + * @return if successful + */ + bool addUID(const GpgKey &key, const GpgUID &uid); + + /** + * Revoke(Delete) UID from certain key pair + * @param key target key pair + * @param uid target uid + * @return if successful + */ + bool revUID(const GpgKey &key, const GpgUID &uid); + + + /** + * Set one of a uid of a key pair as primary + * @param key target key pair + * @param uid target uid + * @return if successful + */ + bool setPrimaryUID(const GpgKey &key, const GpgUID &uid); + + private: + + GpgContext &ctx = GpgContext::getInstance(); + + }; + +} + + +#endif //GPGFRONTEND_ZH_CN_TS_UIDOPERATOR_H diff --git a/include/gpg/model/GpgKey.h b/include/gpg/model/GpgKey.h new file mode 100644 index 00000000..bc38c6c6 --- /dev/null +++ b/include/gpg/model/GpgKey.h @@ -0,0 +1,127 @@ +/** + * 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. + * + * Foobar 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 Foobar. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from gpg4usb-team. + * Their source code version also complies with GNU General Public License. + * + * The source code version of this software was modified and released + * by Saturneric<[email protected]> starting on May 12, 2021. + * + */ + +#ifndef GPGFRONTEND_GPGKEY_H +#define GPGFRONTEND_GPGKEY_H + +#include "GpgUID.h" +#include "GpgSubKey.h" + +namespace GpgFrontend { + + class GpgKey { + public: + + [[nodiscard]] bool good() const { return _key_ref == nullptr; } + + [[nodiscard]] std::string id() const { return _key_ref->subkeys->keyid; } + + [[nodiscard]] std::string name() const { return _key_ref->uids->name; }; + + [[nodiscard]] std::string email() const { return _key_ref->uids->email; } + + [[nodiscard]] std::string comment() const { return _key_ref->uids->comment; } + + [[nodiscard]] std::string fpr() const { return _key_ref->fpr; } + + [[nodiscard]] std::string protocol() const { return gpgme_get_protocol_name(_key_ref->protocol); } + + [[nodiscard]] std::string owner_trust() const { + switch (_key_ref->owner_trust) { + case GPGME_VALIDITY_UNKNOWN: + return "Unknown"; + case GPGME_VALIDITY_UNDEFINED: + return "Undefined"; + case GPGME_VALIDITY_NEVER: + return "Never"; + case GPGME_VALIDITY_MARGINAL: + return "Marginal"; + case GPGME_VALIDITY_FULL: + return "FULL"; + case GPGME_VALIDITY_ULTIMATE: + return "Ultimate"; + } + } + + [[nodiscard]] std::string pubkey_algo() const { return gpgme_pubkey_algo_name(_key_ref->subkeys->pubkey_algo); } + + [[nodiscard]] QDateTime last_update() const { return QDateTime::fromTime_t(_key_ref->last_update); } + + [[nodiscard]] QDateTime expires() const { return QDateTime::fromTime_t(_key_ref->subkeys->expires); }; + + [[nodiscard]] QDateTime create_time() const { return QDateTime::fromTime_t(_key_ref->subkeys->timestamp); }; + + [[nodiscard]] unsigned int length() const { return _key_ref->subkeys->length; } + + + [[nodiscard]] bool can_encrypt() const { return _key_ref->can_encrypt; } + + [[nodiscard]] bool can_sign() const { return _key_ref->can_sign; } + + [[nodiscard]] bool canSignActual() const; + + [[nodiscard]] bool can_certify() const { return _key_ref->can_certify; } + + [[nodiscard]] bool can_authenticate() const { return _key_ref->can_authenticate; } + + + [[nodiscard]] bool is_private_key() const { return _key_ref->secret; } + + [[nodiscard]] bool expired() const { return _key_ref->expired; } + + [[nodiscard]] bool revoked() const { return _key_ref->revoked; } + + [[nodiscard]] bool disabled() const { return _key_ref->disabled; } + + [[nodiscard]] bool has_master_key() const { return _key_ref->subkeys->secret; } + + [[nodiscard]] std::unique_ptr<std::vector<GpgSubKey>> subKeys() const; + + [[nodiscard]] std::unique_ptr<std::vector<GpgUID>> uids() const; + + explicit GpgKey() = default; + + explicit GpgKey(gpgme_key_t &&key); + + GpgKey(const gpgme_key_t &key) = delete; + + GpgKey(GpgKey &&k) noexcept; + + GpgKey &operator=(GpgKey &&k) noexcept; + + GpgKey &operator=(const gpgme_key_t &key) = delete; + + explicit operator gpgme_key_t() const { return _key_ref.get(); } + + private: + + using KeyRefHandler = std::unique_ptr<struct _gpgme_key, std::function<void(gpgme_key_t)>>; + + KeyRefHandler _key_ref; + }; + +} + + +#endif //GPGFRONTEND_GPGKEY_H diff --git a/include/gpg/model/GpgKeySignature.h b/include/gpg/model/GpgKeySignature.h new file mode 100644 index 00000000..c35a7161 --- /dev/null +++ b/include/gpg/model/GpgKeySignature.h @@ -0,0 +1,75 @@ +/** + * 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. + * + * Foobar 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 Foobar. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from gpg4usb-team. + * Their source code version also complies with GNU General Public License. + * + * The source code version of this software was modified and released + * by Saturneric<[email protected]> starting on May 12, 2021. + * + */ + +#ifndef GPGFRONTEND_GPGKEYSIGNATURE_H +#define GPGFRONTEND_GPGKEYSIGNATURE_H + +#include "GpgFrontend.h" + +namespace GpgFrontend { + + class GpgKeySignature { + public: + + [[nodiscard]] bool revoked() const { return _signature_ref->revoked; } + [[nodiscard]] bool expired() const { return _signature_ref->expired; } + [[nodiscard]] bool invalid() const { return _signature_ref->invalid; } + [[nodiscard]] bool exportable() const { return _signature_ref->exportable; } + + [[nodiscard]] gpgme_error_t status() const { return _signature_ref->status; } + + [[nodiscard]] std::string keyid() const { return _signature_ref->keyid; } + [[nodiscard]] std::string pubkey_algo() const { return gpgme_pubkey_algo_name(_signature_ref->pubkey_algo); } + + [[nodiscard]] QDateTime create_time() const { return QDateTime::fromTime_t(_signature_ref->timestamp); } + [[nodiscard]] QDateTime expire_time() const { return QDateTime::fromTime_t(_signature_ref->expires); } + + [[nodiscard]] std::string uid() const { return _signature_ref->uid; } + [[nodiscard]] std::string name() const { return _signature_ref->name; } + [[nodiscard]] std::string email() const { return _signature_ref->email; } + [[nodiscard]] std::string comment() const { return _signature_ref->comment; } + + GpgKeySignature() = default; + + explicit GpgKeySignature(gpgme_key_sig_t sig); + + GpgKeySignature(GpgKeySignature &&) noexcept = default; + + GpgKeySignature(const GpgKeySignature &) = delete; + + GpgKeySignature &operator=(GpgKeySignature &&) noexcept = default; + + GpgKeySignature &operator=(const GpgKeySignature &) = delete; + + private: + + using KeySignatrueRefHandler = std::unique_ptr<struct _gpgme_key_sig, std::function<void(gpgme_key_sig_t)>>; + + KeySignatrueRefHandler _signature_ref = nullptr; + }; + +} + + +#endif //GPGFRONTEND_GPGKEYSIGNATURE_H diff --git a/include/gpg/model/GpgSubKey.h b/include/gpg/model/GpgSubKey.h new file mode 100644 index 00000000..7142a11f --- /dev/null +++ b/include/gpg/model/GpgSubKey.h @@ -0,0 +1,94 @@ +/** + * 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. + * + * Foobar 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 Foobar. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from gpg4usb-team. + * Their source code version also complies with GNU General Public License. + * + * The source code version of this software was modified and released + * by Saturneric<[email protected]> starting on May 12, 2021. + * + */ +#ifndef GPGFRONTEND_GPGSUBKEY_H +#define GPGFRONTEND_GPGSUBKEY_H + +#include "GpgFrontend.h" + +namespace GpgFrontend { + + class GpgSubKey { + public: + + [[nodiscard]] QString id() const { return _subkey_ref->keyid; } + + [[nodiscard]] QString fpr() const { return _subkey_ref->fpr; } + + [[nodiscard]] QString pubkey_algo() const { return gpgme_pubkey_algo_name(_subkey_ref->pubkey_algo); } + + [[nodiscard]] unsigned int length() const { return _subkey_ref->length; } + + + [[nodiscard]] bool can_encrypt() const { return _subkey_ref->can_encrypt; } + + [[nodiscard]] bool can_sign() const { return _subkey_ref->can_sign; } + + [[nodiscard]] bool can_certify() const { return _subkey_ref->can_certify; } + + [[nodiscard]] bool can_authenticate() const { return _subkey_ref->can_authenticate; } + + + [[nodiscard]] bool is_private_key() const { return _subkey_ref->secret; } + + [[nodiscard]] bool expired() const { return _subkey_ref->expired; } + + [[nodiscard]] bool revoked() const { return _subkey_ref->revoked; } + + [[nodiscard]] bool disabled() const { return _subkey_ref->disabled; } + + [[nodiscard]] bool secret() const { return _subkey_ref->secret; } + + [[nodiscard]] bool is_cardkey() const { return _subkey_ref->is_cardkey; } + + [[nodiscard]] QDateTime timestamp() const { return QDateTime::fromTime_t(_subkey_ref->timestamp); } + + [[nodiscard]] QDateTime expires() const { return QDateTime::fromTime_t(_subkey_ref->expires); } + + GpgSubKey() = default; + + explicit GpgSubKey(gpgme_subkey_t subkey); + + GpgSubKey(GpgSubKey &&o) noexcept { swap(_subkey_ref, o._subkey_ref); } + + GpgSubKey(const GpgSubKey &) = delete; + + GpgSubKey &operator=(GpgSubKey &&o) noexcept { + swap(_subkey_ref, o._subkey_ref); + return *this; + }; + + GpgSubKey &operator=(const GpgSubKey &) = delete; + + private: + + using SubkeyRefHandler = std::unique_ptr<struct _gpgme_subkey, std::function<void(gpgme_subkey_t)>>; + + SubkeyRefHandler _subkey_ref = nullptr; + + }; + +} + + +#endif //GPGFRONTEND_GPGSUBKEY_H diff --git a/include/gpg/model/GpgUID.h b/include/gpg/model/GpgUID.h new file mode 100644 index 00000000..78fe3b05 --- /dev/null +++ b/include/gpg/model/GpgUID.h @@ -0,0 +1,87 @@ +/** + * 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. + * + * Foobar 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 Foobar. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from gpg4usb-team. + * Their source code version also complies with GNU General Public License. + * + * The source code version of this software was modified and released + * by Saturneric<[email protected]> starting on May 12, 2021. + * + */ + +#ifndef GPGFRONTEND_GPGUID_H +#define GPGFRONTEND_GPGUID_H + +#include <utility> + +#include "GpgFrontend.h" +#include "GpgKeySignature.h" + +namespace GpgFrontend { + + class GpgUID { + public: + + [[nodiscard]] QString name() const { return _uid_ref->name; } + + [[nodiscard]] QString email() const { return _uid_ref->email; } + + [[nodiscard]] QString comment() const { return _uid_ref->comment; } + + [[nodiscard]] QString uid() const { return _uid_ref->uid; } + + [[nodiscard]] QString hash() const { return _uid_ref->uidhash; } + + [[nodiscard]] bool revoked() const { return _uid_ref->revoked; } + + [[nodiscard]] bool invalid() const { return _uid_ref->invalid; } + + [[nodiscard]] std::unique_ptr<QVector<GpgKeySignature>> signatures() const { + auto sigs = std::make_unique<QVector<GpgKeySignature>>(); + auto sig_next = _uid_ref->signatures; + while (sig_next != nullptr) { + sigs->push_back(GpgKeySignature(sig_next)); + sig_next = sig_next->next; + } + return sigs; + } + + GpgUID() = default; + + explicit GpgUID(gpgme_user_id_t uid); + + GpgUID(GpgUID &&o) noexcept {swap(_uid_ref, o._uid_ref);} + + GpgUID(const GpgUID &) = delete; + + GpgUID& operator=(GpgUID &&o) noexcept { + swap(_uid_ref, o._uid_ref); + return *this; + } + + GpgUID& operator=(const GpgUID &) = delete; + + private: + + using UidRefHandler = std::unique_ptr<struct _gpgme_user_id, std::function<void(gpgme_user_id_t)>>; + + UidRefHandler _uid_ref = nullptr; + + }; + +} + +#endif //GPGFRONTEND_GPGUID_H
\ No newline at end of file diff --git a/include/gpg/result_analyse/DecryptResultAnalyse.h b/include/gpg/result_analyse/DecryptResultAnalyse.h index b1d0c7b4..e7ddd389 100644 --- a/include/gpg/result_analyse/DecryptResultAnalyse.h +++ b/include/gpg/result_analyse/DecryptResultAnalyse.h @@ -31,11 +31,11 @@ class DecryptResultAnalyse : public ResultAnalyse { Q_OBJECT public: - explicit DecryptResultAnalyse(GpgME::GpgContext *ctx, gpgme_error_t error, gpgme_decrypt_result_t result); + explicit DecryptResultAnalyse(GpgFrontend::GpgContext *ctx, gpgme_error_t error, gpgme_decrypt_result_t result); private: - GpgME::GpgContext *mCtx; + GpgFrontend::GpgContext *mCtx; bool printReci(QTextStream &stream, gpgme_recipient_t reci); }; diff --git a/include/gpg/result_analyse/SignResultAnalyse.h b/include/gpg/result_analyse/SignResultAnalyse.h index ebb15dfb..fdff305d 100644 --- a/include/gpg/result_analyse/SignResultAnalyse.h +++ b/include/gpg/result_analyse/SignResultAnalyse.h @@ -34,7 +34,7 @@ class SignResultAnalyse : public ResultAnalyse { Q_OBJECT public: - explicit SignResultAnalyse(GpgME::GpgContext *ctx, gpgme_error_t error, gpgme_sign_result_t result); + explicit SignResultAnalyse(GpgFrontend::GpgContext *ctx, gpgme_error_t error, gpgme_sign_result_t result); private: diff --git a/include/gpg/result_analyse/VerifyResultAnalyse.h b/include/gpg/result_analyse/VerifyResultAnalyse.h index c009741a..b934ccfe 100644 --- a/include/gpg/result_analyse/VerifyResultAnalyse.h +++ b/include/gpg/result_analyse/VerifyResultAnalyse.h @@ -26,18 +26,18 @@ #define GPGFRONTEND_VERIFYRESULTANALYSE_H #include "gpg/GpgContext.h" -#include "gpg/GpgKeySignature.h" +#include "gpg/model/GpgKeySignature.h" #include "ResultAnalyse.h" class VerifyResultAnalyse : public ResultAnalyse{ public: - explicit VerifyResultAnalyse(GpgME::GpgContext *ctx, gpgme_error_t error, gpgme_verify_result_t result); + explicit VerifyResultAnalyse(GpgFrontend::GpgContext *ctx, gpgme_error_t error, gpgme_verify_result_t result); private: - GpgME::GpgContext *mCtx; + GpgFrontend::GpgContext *mCtx; bool printSigner(QTextStream &stream, gpgme_signature_t sign); diff --git a/include/server/ComUtils.h b/include/server/ComUtils.h index a4cf543f..1f71f2e6 100644 --- a/include/server/ComUtils.h +++ b/include/server/ComUtils.h @@ -29,51 +29,55 @@ #include "gpg/GpgContext.h" #include "rapidjson/document.h" -class ComUtils : public QWidget { -Q_OBJECT -public: +namespace GpgFrontend { - enum ServiceType { GetServiceToken, ShortenCryptText, GetFullCryptText, UploadPubkey, GetPubkey }; + class ComUtils : public QWidget { + Q_OBJECT + public: - explicit ComUtils(QWidget *parent) : QWidget(parent), appPath(qApp->applicationDirPath()), - settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini", - QSettings::IniFormat) { + enum ServiceType { GetServiceToken, ShortenCryptText, GetFullCryptText, UploadPubkey, GetPubkey }; - } + explicit ComUtils(QWidget *parent) : QWidget(parent), appPath(qApp->applicationDirPath()), + settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini", + QSettings::IniFormat) { - [[nodiscard]] QString getUrl(ServiceType type) const; + } - bool checkServerReply(const QByteArray &reply); + [[nodiscard]] QString getUrl(ServiceType type) const; - [[nodiscard]] QString getDataValueStr(const QString &key) const; + bool checkServerReply(const QByteArray &reply); - [[nodiscard]] bool checkDataValueStr(const QString &key) const; + [[nodiscard]] QString getDataValueStr(const QString &key) const; - [[nodiscard]] const rapidjson::Value &getDataValue(const QString &key) const; + [[nodiscard]] bool checkDataValueStr(const QString &key) const; - [[nodiscard]] bool checkDataValue(const QString &key) const; + [[nodiscard]] const rapidjson::Value &getDataValue(const QString &key) const; - [[nodiscard]] bool checkServiceTokenFormat(const QString& serviceToken) const; + [[nodiscard]] bool checkDataValue(const QString &key) const; - static QByteArray getSignStringBase64(GpgME::GpgContext *ctx, const QString &str, const GpgKey& key); + [[nodiscard]] bool checkServiceTokenFormat(const QString& serviceToken) const; - [[nodiscard]] bool good() const { return is_good; } + static QByteArray getSignStringBase64(GpgFrontend::GpgContext *ctx, const QString &str, const GpgKey& key); - QNetworkAccessManager &getNetworkManager() {return networkMgr;} + [[nodiscard]] bool good() const { return is_good; } - void clear(); + QNetworkAccessManager &getNetworkManager() {return networkMgr;} -private: + void clear(); - QString appPath; - QSettings settings; - rapidjson::Document replyDoc; - rapidjson::Value dataVal; - QNetworkAccessManager networkMgr; - QRegularExpression re_uuid{R"(\b[0-9a-f]{8}\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\b[0-9a-f]{12}\b)"}; + private: - bool is_good = false; -}; + QString appPath; + QSettings settings; + rapidjson::Document replyDoc; + rapidjson::Value dataVal; + QNetworkAccessManager networkMgr; + QRegularExpression re_uuid{R"(\b[0-9a-f]{8}\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\b[0-9a-f]{12}\b)"}; + + bool is_good = false; + }; + +} #endif //GPGFRONTEND_ZH_CN_TS_COMUTILS_H diff --git a/include/server/api/PubkeyGetter.h b/include/server/api/PubkeyGetter.h index 9d3bdb60..216b1ef2 100644 --- a/include/server/api/PubkeyGetter.h +++ b/include/server/api/PubkeyGetter.h @@ -37,11 +37,11 @@ class ComUtils; class PubkeyGetter : public BaseAPI { public: - PubkeyGetter(GpgME::GpgContext *ctx, const QVector<QString> &fprs); + PubkeyGetter(GpgFrontend::GpgContext *ctx, const QVector<QString> &fprs); private: - GpgME::GpgContext *mCtx; + GpgFrontend::GpgContext *mCtx; const QVector<QString> &mFprs; diff --git a/include/server/api/PubkeyUploader.h b/include/server/api/PubkeyUploader.h index 7521cdd3..61096d46 100644 --- a/include/server/api/PubkeyUploader.h +++ b/include/server/api/PubkeyUploader.h @@ -37,13 +37,13 @@ class PubkeyUploader : public BaseAPI { public: - PubkeyUploader(GpgME::GpgContext *ctx, const QVector<GpgKey> &keys); + PubkeyUploader(GpgFrontend::GpgContext *ctx, const QVector<GpgKey> &keys); private: const QVector<GpgKey> &mKeys; - GpgME::GpgContext *mCtx; + GpgFrontend::GpgContext *mCtx; protected: diff --git a/include/ui/FileEncryptionDialog.h b/include/ui/FileEncryptionDialog.h index be9ddd22..da1d48e4 100755 --- a/include/ui/FileEncryptionDialog.h +++ b/include/ui/FileEncryptionDialog.h @@ -55,7 +55,7 @@ public: * @param keyList * @param parent */ - FileEncryptionDialog(GpgME::GpgContext *ctx, QStringList keyList, DialogAction action, QWidget *parent = nullptr); + FileEncryptionDialog(GpgFrontend::GpgContext *ctx, QStringList keyList, DialogAction action, QWidget *parent = nullptr); public slots: @@ -108,7 +108,7 @@ private: DialogAction mAction; QLabel *statusLabel; protected: - GpgME::GpgContext *mCtx; + GpgFrontend::GpgContext *mCtx; KeyList *mKeyList; }; diff --git a/include/ui/KeyImportDetailDialog.h b/include/ui/KeyImportDetailDialog.h index 216cdcd0..243eead3 100644 --- a/include/ui/KeyImportDetailDialog.h +++ b/include/ui/KeyImportDetailDialog.h @@ -32,7 +32,7 @@ class KeyImportDetailDialog : public QDialog Q_OBJECT public: - KeyImportDetailDialog(GpgME::GpgContext *ctx, GpgImportInformation result, bool automatic, QWidget *parent = 0); + KeyImportDetailDialog(GpgFrontend::GpgContext *ctx, GpgImportInformation result, bool automatic, QWidget *parent = 0); private: void createGeneralInfoBox(); @@ -41,7 +41,7 @@ private: static QString getStatusString(int keyStatus); QTableWidget *keysTable{}; - GpgME::GpgContext *mCtx; + GpgFrontend::GpgContext *mCtx; QGroupBox *generalInfoBox{}; QGroupBox *keyInfoBox{}; QDialogButtonBox *buttonBox{}; diff --git a/include/ui/KeyMgmt.h b/include/ui/KeyMgmt.h index fa352149..d96d6aba 100755 --- a/include/ui/KeyMgmt.h +++ b/include/ui/KeyMgmt.h @@ -36,7 +36,7 @@ class KeyMgmt : public QMainWindow { Q_OBJECT public: - explicit KeyMgmt(GpgME::GpgContext *ctx, QWidget *parent = nullptr); + explicit KeyMgmt(GpgFrontend::GpgContext *ctx, QWidget *parent = nullptr); QAction *importKeyFromClipboardAct{}; QAction *importKeyFromFileAct{}; @@ -86,7 +86,7 @@ private: QSettings settings; KeyList *mKeyList; - GpgME::GpgContext *mCtx; + GpgFrontend::GpgContext *mCtx; QMenu *fileMenu{}; QMenu *keyMenu{}; QMenu *generateKeyMenu{}; diff --git a/include/ui/KeyServerImportDialog.h b/include/ui/KeyServerImportDialog.h index 6fd45fc5..46227481 100644 --- a/include/ui/KeyServerImportDialog.h +++ b/include/ui/KeyServerImportDialog.h @@ -34,10 +34,10 @@ class KeyServerImportDialog : public QDialog { Q_OBJECT public: - KeyServerImportDialog(GpgME::GpgContext *ctx, KeyList *keyList, bool automatic, + KeyServerImportDialog(GpgFrontend::GpgContext *ctx, KeyList *keyList, bool automatic, QWidget *parent); - KeyServerImportDialog(GpgME::GpgContext *ctx, QWidget *parent); + KeyServerImportDialog(GpgFrontend::GpgContext *ctx, QWidget *parent); void slotImport(const QStringList& keyIds); @@ -73,7 +73,7 @@ private: QString appPath; QSettings settings; - GpgME::GpgContext *mCtx; + GpgFrontend::GpgContext *mCtx; KeyList *mKeyList{}; QLineEdit *searchLineEdit{}; QComboBox *keyServerComboBox{}; diff --git a/include/ui/KeyUploadDialog.h b/include/ui/KeyUploadDialog.h index b41ced6b..e6c3b836 100644 --- a/include/ui/KeyUploadDialog.h +++ b/include/ui/KeyUploadDialog.h @@ -31,7 +31,7 @@ class KeyUploadDialog : public QDialog { Q_OBJECT public: - KeyUploadDialog(GpgME::GpgContext *ctx, const QVector<GpgKey> &keys, QWidget *parent = nullptr); + KeyUploadDialog(GpgFrontend::GpgContext *ctx, const QVector<GpgKey> &keys, QWidget *parent = nullptr); public slots: @@ -45,7 +45,7 @@ private slots: private: - GpgME::GpgContext *mCtx; + GpgFrontend::GpgContext *mCtx; const QVector<GpgKey> &mKeys; QString appPath; QSettings settings; diff --git a/include/ui/SettingsDialog.h b/include/ui/SettingsDialog.h index 72f80917..6e102053 100755 --- a/include/ui/SettingsDialog.h +++ b/include/ui/SettingsDialog.h @@ -31,7 +31,7 @@ class GeneralTab : public QWidget { Q_OBJECT public: - explicit GeneralTab(GpgME::GpgContext *ctx, QWidget *parent = nullptr); + explicit GeneralTab(GpgFrontend::GpgContext *ctx, QWidget *parent = nullptr); void setSettings(); @@ -54,7 +54,7 @@ private: QVector<QString> keyIdsList; QString serviceToken; KeyList *mKeyList; - GpgME::GpgContext *mCtx; + GpgFrontend::GpgContext *mCtx; private slots: @@ -227,7 +227,7 @@ class SettingsDialog : public QDialog { Q_OBJECT public: - explicit SettingsDialog(GpgME::GpgContext *ctx, QWidget *parent = nullptr); + explicit SettingsDialog(GpgFrontend::GpgContext *ctx, QWidget *parent = nullptr); GeneralTab *generalTab; SendMailTab *sendMailTab; @@ -249,7 +249,7 @@ signals: private: QTabWidget *tabWidget; QDialogButtonBox *buttonBox; - GpgME::GpgContext *mCtx; /** The current gpg context */ + GpgFrontend::GpgContext *mCtx; /** The current gpg context */ bool restartNeeded{}; bool getRestartNeeded() const; diff --git a/include/ui/VerifyDetailsDialog.h b/include/ui/VerifyDetailsDialog.h index ece2f1e7..a66667c0 100644 --- a/include/ui/VerifyDetailsDialog.h +++ b/include/ui/VerifyDetailsDialog.h @@ -31,7 +31,7 @@ class VerifyDetailsDialog : public QDialog { Q_OBJECT public: - explicit VerifyDetailsDialog(QWidget *parent, GpgME::GpgContext *ctx, KeyList *keyList, gpg_error_t error, + explicit VerifyDetailsDialog(QWidget *parent, GpgFrontend::GpgContext *ctx, KeyList *keyList, gpg_error_t error, gpgme_verify_result_t result); private slots: @@ -39,7 +39,7 @@ private slots: void slotRefresh(); private: - GpgME::GpgContext *mCtx; + GpgFrontend::GpgContext *mCtx; KeyList *mKeyList; QHBoxLayout *mainLayout; QWidget *mVbox{}; diff --git a/include/ui/Wizard.h b/include/ui/Wizard.h index 79c7e321..e38bc560 100644 --- a/include/ui/Wizard.h +++ b/include/ui/Wizard.h @@ -40,10 +40,10 @@ public: Page_Conclusion }; - Wizard(GpgME::GpgContext *ctx, KeyMgmt *keyMgmt, QWidget *parent = nullptr); + Wizard(GpgFrontend::GpgContext *ctx, KeyMgmt *keyMgmt, QWidget *parent = nullptr); private: - GpgME::GpgContext *mCtx; + GpgFrontend::GpgContext *mCtx; KeyMgmt *mKeyMgmt; QString appPath; QSettings settings; @@ -96,7 +96,7 @@ class KeyGenPage : public QWizardPage { Q_OBJECT public: - explicit KeyGenPage(GpgME::GpgContext *ctx, QWidget *parent = nullptr); + explicit KeyGenPage(GpgFrontend::GpgContext *ctx, QWidget *parent = nullptr); [[nodiscard]] int nextId() const override; @@ -105,7 +105,7 @@ private slots: void slotGenerateKeyDialog(); private: - GpgME::GpgContext *mCtx; + GpgFrontend::GpgContext *mCtx; }; class ConclusionPage : public QWizardPage { diff --git a/include/ui/keygen/KeygenDialog.h b/include/ui/keygen/KeygenDialog.h index 4a37590a..84c734f1 100644 --- a/include/ui/keygen/KeygenDialog.h +++ b/include/ui/keygen/KeygenDialog.h @@ -40,7 +40,7 @@ public: * @param key The key to show details of * @param parent The parent of this widget */ - explicit KeyGenDialog(GpgME::GpgContext *ctx, QWidget *parent = nullptr); + explicit KeyGenDialog(GpgFrontend::GpgContext *ctx, QWidget *parent = nullptr); private: @@ -51,7 +51,7 @@ private: QRegularExpression re_email{ R"((?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\]))"}; - GpgME::GpgContext *mCtx; /** The current gpg context */ + GpgFrontend::GpgContext *mCtx; /** The current gpg context */ QStringList errorMessages; /** List of errors occuring when checking entries of lineedits */ GenKeyInfo genKeyInfo{}; diff --git a/include/ui/keygen/SubkeyGenerateDialog.h b/include/ui/keygen/SubkeyGenerateDialog.h index a1cfcf55..bbc99a9f 100644 --- a/include/ui/keygen/SubkeyGenerateDialog.h +++ b/include/ui/keygen/SubkeyGenerateDialog.h @@ -32,11 +32,11 @@ Q_OBJECT public: - explicit SubkeyGenerateDialog(GpgME::GpgContext *ctx, const GpgKey &key, QWidget *parent = nullptr); + explicit SubkeyGenerateDialog(GpgFrontend::GpgContext *ctx, const GpgKey &key, QWidget *parent = nullptr); private: - GpgME::GpgContext *mCtx; /** The current gpg context */ + GpgFrontend::GpgContext *mCtx; /** The current gpg context */ const GpgKey &mKey; GenKeyInfo genKeyInfo{}; diff --git a/include/ui/keypair_details/KeyDetailsDialog.h b/include/ui/keypair_details/KeyDetailsDialog.h index 94fb1223..4d2cde88 100644 --- a/include/ui/keypair_details/KeyDetailsDialog.h +++ b/include/ui/keypair_details/KeyDetailsDialog.h @@ -35,7 +35,7 @@ Q_OBJECT public: - KeyDetailsDialog(GpgME::GpgContext *ctx, const GpgKey& key, QWidget *parent = nullptr); + KeyDetailsDialog(GpgFrontend::GpgContext *ctx, const GpgKey& key, QWidget *parent = nullptr); private: diff --git a/include/ui/keypair_details/KeyNewUIDDialog.h b/include/ui/keypair_details/KeyNewUIDDialog.h index fd8be03b..c8b42661 100644 --- a/include/ui/keypair_details/KeyNewUIDDialog.h +++ b/include/ui/keypair_details/KeyNewUIDDialog.h @@ -34,7 +34,7 @@ Q_OBJECT public: - KeyNewUIDDialog(GpgME::GpgContext *ctx, const GpgKey &key ,QWidget *parent = nullptr); + KeyNewUIDDialog(GpgFrontend::GpgContext *ctx, const GpgKey &key ,QWidget *parent = nullptr); private slots: @@ -43,7 +43,7 @@ private slots: private: - GpgME::GpgContext *mCtx; + GpgFrontend::GpgContext *mCtx; const GpgKey &mKey; QLineEdit *name{}; diff --git a/include/ui/keypair_details/KeyPairDetailTab.h b/include/ui/keypair_details/KeyPairDetailTab.h index bb364718..0ea50788 100644 --- a/include/ui/keypair_details/KeyPairDetailTab.h +++ b/include/ui/keypair_details/KeyPairDetailTab.h @@ -70,7 +70,7 @@ private: QString *keyid; /** The id of the key the details should be shown for */ - GpgME::GpgContext *mCtx; /** The current gpg-context */ + GpgFrontend::GpgContext *mCtx; /** The current gpg-context */ const GpgKey &mKey; QGroupBox *ownerBox; /** Groupbox containing owner information */ @@ -94,7 +94,7 @@ private: QMenu *keyServerOperaMenu; public: - explicit KeyPairDetailTab(GpgME::GpgContext *ctx, const GpgKey &mKey, QWidget *parent = nullptr); + explicit KeyPairDetailTab(GpgFrontend::GpgContext *ctx, const GpgKey &mKey, QWidget *parent = nullptr); }; diff --git a/include/ui/keypair_details/KeyPairSubkeyTab.h b/include/ui/keypair_details/KeyPairSubkeyTab.h index 41bb0648..ae8b0893 100644 --- a/include/ui/keypair_details/KeyPairSubkeyTab.h +++ b/include/ui/keypair_details/KeyPairSubkeyTab.h @@ -36,7 +36,7 @@ Q_OBJECT public: - KeyPairSubkeyTab(GpgME::GpgContext *ctx, const GpgKey &key, QWidget *parent); + KeyPairSubkeyTab(GpgFrontend::GpgContext *ctx, const GpgKey &key, QWidget *parent); private: @@ -46,7 +46,7 @@ private: const GpgSubKey *getSelectedSubkey(); - GpgME::GpgContext *mCtx; + GpgFrontend::GpgContext *mCtx; const GpgKey &mKey; QTableWidget *subkeyList; QVector<const GpgSubKey *> buffered_subkeys; diff --git a/include/ui/keypair_details/KeyPairUIDTab.h b/include/ui/keypair_details/KeyPairUIDTab.h index 6042ec29..3056687d 100644 --- a/include/ui/keypair_details/KeyPairUIDTab.h +++ b/include/ui/keypair_details/KeyPairUIDTab.h @@ -36,7 +36,7 @@ Q_OBJECT public: - KeyPairUIDTab(GpgME::GpgContext *ctx, const GpgKey &key, QWidget *parent); + KeyPairUIDTab(GpgFrontend::GpgContext *ctx, const GpgKey &key, QWidget *parent); private: @@ -56,7 +56,7 @@ private: bool getSignSelected(GpgKeySignature &signature); - GpgME::GpgContext *mCtx; + GpgFrontend::GpgContext *mCtx; const GpgKey &mKey; QTableWidget *uidList{}; QTableWidget *sigList{}; diff --git a/include/ui/keypair_details/KeySetExpireDateDialog.h b/include/ui/keypair_details/KeySetExpireDateDialog.h index 118bc5ed..11f2a560 100644 --- a/include/ui/keypair_details/KeySetExpireDateDialog.h +++ b/include/ui/keypair_details/KeySetExpireDateDialog.h @@ -27,16 +27,16 @@ #include "GpgFrontend.h" #include "gpg/GpgContext.h" -#include "gpg/GpgKey.h" -#include "gpg/GpgSubKey.h" +#include "gpg/model/GpgKey.h" +#include "gpg/model/GpgSubKey.h" class KeySetExpireDateDialog : public QDialog { Q_OBJECT public: - explicit KeySetExpireDateDialog(GpgME::GpgContext *ctx, const GpgKey &key, const GpgSubKey *subkey, QWidget *parent = nullptr); + explicit KeySetExpireDateDialog(GpgFrontend::GpgContext *ctx, const GpgKey &key, const GpgSubKey *subkey, QWidget *parent = nullptr); private: - GpgME::GpgContext *mCtx; + GpgFrontend::GpgContext *mCtx; const GpgKey &mKey; const GpgSubKey *mSubkey; diff --git a/include/ui/keypair_details/KeyUIDSignDialog.h b/include/ui/keypair_details/KeyUIDSignDialog.h index 88549e95..fcbb4fbd 100644 --- a/include/ui/keypair_details/KeyUIDSignDialog.h +++ b/include/ui/keypair_details/KeyUIDSignDialog.h @@ -35,11 +35,11 @@ class KeyUIDSignDialog : public QDialog { public: - explicit KeyUIDSignDialog(GpgME::GpgContext *ctx, const GpgKey &key, const QVector<GpgUID> &uid, QWidget *parent = nullptr); + explicit KeyUIDSignDialog(GpgFrontend::GpgContext *ctx, const GpgKey &key, const QVector<GpgUID> &uid, QWidget *parent = nullptr); private: - GpgME::GpgContext *mCtx; + GpgFrontend::GpgContext *mCtx; KeyList *mKeyList; diff --git a/include/ui/widgets/InfoBoardWidget.h b/include/ui/widgets/InfoBoardWidget.h index 334ef55a..82c38f65 100644 --- a/include/ui/widgets/InfoBoardWidget.h +++ b/include/ui/widgets/InfoBoardWidget.h @@ -52,7 +52,7 @@ public: * @param ctx The GPGme-Context * @param parent The parent widget */ - explicit InfoBoardWidget(QWidget *parent, GpgME::GpgContext *ctx, KeyList *keyList); + explicit InfoBoardWidget(QWidget *parent, GpgFrontend::GpgContext *ctx, KeyList *keyList); void associateTextEdit(QTextEdit *edit); @@ -102,7 +102,7 @@ private: QMenu *detailMenu; /** Menu for te Button in verfiyNotification */ QAction *importFromKeyserverAct; /** Action for importing keys from keyserver which are notin keylist */ QTextEdit *infoBoard; - GpgME::GpgContext *mCtx; /** GpgME Context */ + GpgFrontend::GpgContext *mCtx; /** GpgME Context */ KeyList *mKeyList; /** Table holding the keys */ QTextEdit *mTextPage{ nullptr }; /** TextEdit associated to the notification */ diff --git a/include/ui/widgets/KeyList.h b/include/ui/widgets/KeyList.h index 231255b6..c1a26931 100644 --- a/include/ui/widgets/KeyList.h +++ b/include/ui/widgets/KeyList.h @@ -58,7 +58,7 @@ Q_OBJECT public: - explicit KeyList(GpgME::GpgContext *ctx, + explicit KeyList(GpgFrontend::GpgContext *ctx, KeyListRow::KeyType selectType = KeyListRow::SECRET_OR_PUBLIC_KEY, KeyListColumn::InfoType infoType = KeyListColumn::ALL, QWidget *parent = nullptr); @@ -106,7 +106,7 @@ private: QString appPath; QSettings settings; - GpgME::GpgContext *mCtx; + GpgFrontend::GpgContext *mCtx; QTableWidget *mKeyList; QMenu *popupMenu; QNetworkAccessManager *qnam{}; diff --git a/include/ui/widgets/SignersPicker.h b/include/ui/widgets/SignersPicker.h index afa95a05..4c9c9f2d 100644 --- a/include/ui/widgets/SignersPicker.h +++ b/include/ui/widgets/SignersPicker.h @@ -35,12 +35,12 @@ Q_OBJECT public: - explicit SignersPicker(GpgME::GpgContext *ctx, QWidget *parent = nullptr); + explicit SignersPicker(GpgFrontend::GpgContext *ctx, QWidget *parent = nullptr); void getCheckedSigners(QVector<GpgKey> &keys); private: - GpgME::GpgContext *mCtx; + GpgFrontend::GpgContext *mCtx; KeyList *mKeyList; }; diff --git a/include/ui/widgets/VerifyKeyDetailBox.h b/include/ui/widgets/VerifyKeyDetailBox.h index 66f01a8e..3c9a6cfe 100644 --- a/include/ui/widgets/VerifyKeyDetailBox.h +++ b/include/ui/widgets/VerifyKeyDetailBox.h @@ -31,7 +31,7 @@ class VerifyKeyDetailBox : public QGroupBox { Q_OBJECT public: - explicit VerifyKeyDetailBox(QWidget *parent, GpgME::GpgContext *ctx, KeyList *mKeyList, + explicit VerifyKeyDetailBox(QWidget *parent, GpgFrontend::GpgContext *ctx, KeyList *mKeyList, gpgme_signature_t signature); private slots: @@ -39,7 +39,7 @@ private slots: void slotImportFormKeyserver(); private: - GpgME::GpgContext *mCtx; + GpgFrontend::GpgContext *mCtx; KeyList *mKeyList; static QString beautifyFingerprint(QString fingerprint); diff --git a/resource/ts/gpgfrontend_en_us.ts b/resource/ts/gpgfrontend_en_us.ts index 77d5e02b..90ef1f34 100644 --- a/resource/ts/gpgfrontend_en_us.ts +++ b/resource/ts/gpgfrontend_en_us.ts @@ -580,7 +580,7 @@ </message> </context> <context> - <name>GpgME::GpgContext</name> + <name>GpgFrontend::GpgContext</name> <message> <location filename="../../src/gpg/gpg_context/GpgContext.cpp" line="182"/> <source>Wrong password</source> diff --git a/resource/ts/gpgfrontend_es.ts b/resource/ts/gpgfrontend_es.ts index 872d7d96..69d01e42 100644 --- a/resource/ts/gpgfrontend_es.ts +++ b/resource/ts/gpgfrontend_es.ts @@ -580,7 +580,7 @@ </message> </context> <context> - <name>GpgME::GpgContext</name> + <name>GpgFrontend::GpgContext</name> <message> <location filename="../../src/gpg/gpg_context/GpgContext.cpp" line="182"/> <source>Wrong password</source> diff --git a/resource/ts/gpgfrontend_fr.ts b/resource/ts/gpgfrontend_fr.ts index 3b711b97..9e50849a 100644 --- a/resource/ts/gpgfrontend_fr.ts +++ b/resource/ts/gpgfrontend_fr.ts @@ -580,7 +580,7 @@ </message> </context> <context> - <name>GpgME::GpgContext</name> + <name>GpgFrontend::GpgContext</name> <message> <location filename="../../src/gpg/gpg_context/GpgContext.cpp" line="182"/> <source>Wrong password</source> diff --git a/resource/ts/gpgfrontend_ru.ts b/resource/ts/gpgfrontend_ru.ts index f2eb5f87..6327a140 100644 --- a/resource/ts/gpgfrontend_ru.ts +++ b/resource/ts/gpgfrontend_ru.ts @@ -580,7 +580,7 @@ </message> </context> <context> - <name>GpgME::GpgContext</name> + <name>GpgFrontend::GpgContext</name> <message> <location filename="../../src/gpg/gpg_context/GpgContext.cpp" line="182"/> <source>Wrong password</source> diff --git a/resource/ts/gpgfrontend_zh_cn.ts b/resource/ts/gpgfrontend_zh_cn.ts index 79311e81..ee2090b4 100644 --- a/resource/ts/gpgfrontend_zh_cn.ts +++ b/resource/ts/gpgfrontend_zh_cn.ts @@ -580,7 +580,7 @@ </message> </context> <context> - <name>GpgME::GpgContext</name> + <name>GpgFrontend::GpgContext</name> <message> <location filename="../../src/gpg/gpg_context/GpgContext.cpp" line="182"/> <source>Wrong password</source> diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 200f5beb..555e5b39 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,146 +1,187 @@ -add_subdirectory(gpg) -add_subdirectory(ui) -add_subdirectory(smtp) -add_subdirectory(server) -add_subdirectory(advance) +if(QT_MOC_CONFIG) + file(GLOB_RECURSE GPGFRONTEND_HEADER_FILES RELACTIVE ${CMAKE_SOURCE_DIR}/include/*.h) + qt5_wrap_cpp(QT5_MOCS ${GPGFRONTEND_HEADER_FILES} TARGET ${AppName}) +endif() + +if(GPG_CORE) + message(STATUS "Build Gpg Core") + add_subdirectory(gpg) +endif() -aux_source_directory(. BASE_SOURCE) +if(UI_CORE) + message(STATUS "Build UI Core") + add_subdirectory(ui) +endif() -set(APP_ICON_RESOURCE_WINDOWS "${CMAKE_SOURCE_DIR}/gpgfrontend.rc") -set_property(SOURCE gpgfrontend.rc APPEND PROPERTY OBJECT_DEPENDS ${CMAKE_SOURCE_DIR}/gpgfrontend.ico) +if(SMTP_SUPPORT) + message(STATUS "Build SMTP Support") + add_subdirectory(smtp) +endif() +if(SERVER_SUPPORT) + message(STATUS "Build Server Support") + add_subdirectory(server) +endif() -file(GLOB_RECURSE GPGFRONTEND_HEADER_FILES RELACTIVE ${CMAKE_SOURCE_DIR}/include/*.h) -qt5_wrap_cpp(QT5_MOCS ${GPGFRONTEND_HEADER_FILES} TARGET ${AppName}) +if(ADVANCE_SUPPORT) + message(STATUS "Build Advance Support") + add_subdirectory(advance) +endif() -# Set Binary Output Path -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/release) -message(STATUS "CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}") +if(APPLICATION_BUILD) + aux_source_directory(. BASE_SOURCE) + set(APP_ICON_RESOURCE_WINDOWS "${CMAKE_SOURCE_DIR}/gpgfrontend.rc") + set_property(SOURCE gpgfrontend.rc APPEND PROPERTY OBJECT_DEPENDS ${CMAKE_SOURCE_DIR}/gpgfrontend.ico) -# Set Resource Output Path -if(${CMAKE_BUILD_TYPE} STREQUAL "Release") - if(APPLE) - set(RESOURCE_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Resources) - elseif(LINUX) - file(COPY ${CMAKE_SOURCE_DIR}/resource/gpgfrontend DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN) - set(RESOURCE_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/gpgfrontend/usr/share) + # Set Binary Output Path + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/release) + message(STATUS "CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}") +endif() + + +if(APPLICATION_BUILD) + # Set Resource Output Path + if(${CMAKE_BUILD_TYPE} STREQUAL "Release") + if(APPLE) + set(RESOURCE_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Resources) + elseif(LINUX) + file(COPY ${CMAKE_SOURCE_DIR}/resource/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}) + endif() else() set(RESOURCE_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) endif() -else() - set(RESOURCE_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) + message(STATUS "RESOURCE_OUTPUT_DIRECTORY ${RESOURCE_OUTPUT_DIRECTORY}") endif() -message(STATUS "RESOURCE_OUTPUT_DIRECTORY ${RESOURCE_OUTPUT_DIRECTORY}") # Get ALL SOURCE FILES file(GLOB_RECURSE ALL_SOURCE_FILES RELACTIVE ${CMAKE_SOURCE_DIR}/src/*.cpp) -# Set Translation Files -set(QT_TS_FILES - gpgfrontend_en_us.ts gpgfrontend_zh_cn.ts - gpgfrontend_fr.ts gpgfrontend_ru.ts gpgfrontend_es.ts) -list(TRANSFORM QT_TS_FILES PREPEND ${CMAKE_SOURCE_DIR}/resource/ts/) -message(STATUS "QT_TS_FILES ${QT_TS_FILES}") -set(QT_QM_FILES_OUTPUT_DIR ${RESOURCE_OUTPUT_DIRECTORY}/ts) -set_source_files_properties(${QT_TS_FILES} PROPERTIES OUTPUT_LOCATION ${QT_QM_FILES_OUTPUT_DIR}) -QT5_create_translation(QON_QM_FILES ${CMAKE_SOURCE_DIR} ${QT_TS_FILES}) -message(STATUS "QON_QM_FILES ${QON_QM_FILES}") -add_custom_target(translations DEPENDS ${QON_QM_FILES}) - -# Set Build Information -configure_file(${CMAKE_SOURCE_DIR}/include/GpgFrontend.h.in ${CMAKE_SOURCE_DIR}/include/GpgFrontend.h @ONLY) -configure_file(${CMAKE_SOURCE_DIR}/include/GpgFrontendBuildInfo.h.in ${CMAKE_SOURCE_DIR}/include/GpgFrontendBuildInfo.h @ONLY) - -# 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/conf DESTINATION ${RESOURCE_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN) - -if(${CMAKE_BUILD_TYPE} STREQUAL "Release") - if(APPLE) - file(COPY ${CMAKE_SOURCE_DIR}/gpgfrontend.icns DESTINATION ${RESOURCE_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN) - # Refresh App Bundle - file(REMOVE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${AppName}.app) - elseif(LINUX) - file(REMOVE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/gpgfrontend/usr/bin/${AppName}) - endif() +if(MULTI_LANG_SUPPORT) + # Set Translation Files + set(QT_TS_FILES + gpgfrontend_en_us.ts gpgfrontend_zh_cn.ts + gpgfrontend_fr.ts gpgfrontend_ru.ts gpgfrontend_es.ts) + list(TRANSFORM QT_TS_FILES PREPEND ${CMAKE_SOURCE_DIR}/resource/ts/) + message(STATUS "QT_TS_FILES ${QT_TS_FILES}") + set(QT_QM_FILES_OUTPUT_DIR ${RESOURCE_OUTPUT_DIRECTORY}/ts) + set_source_files_properties(${QT_TS_FILES} PROPERTIES OUTPUT_LOCATION ${QT_QM_FILES_OUTPUT_DIR}) + QT5_create_translation(QON_QM_FILES ${CMAKE_SOURCE_DIR} ${QT_TS_FILES}) + message(STATUS "QON_QM_FILES ${QON_QM_FILES}") + add_custom_target(translations DEPENDS ${QON_QM_FILES}) endif() -# Copy Utils Files -if(MINGW) - message(STATUS "Copying Dependent DLL For Windows Runtime Env") - file(COPY ${CMAKE_SOURCE_DIR}/resource/utils/lib/ DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN) - file(COPY ${CMAKE_SOURCE_DIR}/resource/utils/gpgme/ DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN) - file(COPY ${CMAKE_SOURCE_DIR}/resource/utils/bearer DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN) - file(COPY ${CMAKE_SOURCE_DIR}/resource/utils/iconengines DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN) - file(COPY ${CMAKE_SOURCE_DIR}/resource/utils/imageformats DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN) - file(COPY ${CMAKE_SOURCE_DIR}/resource/utils/printsupport DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN) - file(COPY ${CMAKE_SOURCE_DIR}/resource/utils/platforms DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN) - file(COPY ${CMAKE_SOURCE_DIR}/resource/utils/openssl/ DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN) +if(BASIC_ENV_CONFIG) + # Set Build Information + configure_file(${CMAKE_SOURCE_DIR}/include/GpgFrontend.h.in ${CMAKE_SOURCE_DIR}/include/GpgFrontend.h @ONLY) + configure_file(${CMAKE_SOURCE_DIR}/include/GpgFrontendBuildInfo.h.in ${CMAKE_SOURCE_DIR}/include/GpgFrontendBuildInfo.h @ONLY) endif() -set(RESOURCE_FILES ${CMAKE_SOURCE_DIR}/gpgfrontend.qrc ${APP_ICON_RESOURCE_WINDOWS} ${QON_QM_FILES}) -add_custom_target(resources ALL DEPENDS ${RESOURCE_FILES}) -add_dependencies(resources translations) +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/conf DESTINATION ${RESOURCE_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN) +endif() + +if(APPLICATION_BUILD) + if(${CMAKE_BUILD_TYPE} STREQUAL "Release") + if(APPLE) + file(COPY ${CMAKE_SOURCE_DIR}/gpgfrontend.icns DESTINATION ${RESOURCE_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN) + # Refresh App Bundle + file(REMOVE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${AppName}.app) + elseif(LINUX) + file(REMOVE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/gpgfrontend/usr/bin/${AppName}) + endif() + endif() +endif() -if(${CMAKE_BUILD_TYPE} STREQUAL "Release") +if(APPLICATION_BUILD) + # Copy Utils Files if(MINGW) - add_executable(${AppName} WIN32 ${BASE_SOURCE} ${RESOURCE_FILES} ${QT5_MOCS}) - elseif(APPLE) - add_executable(${AppName} MACOSX_BUNDLE ${ICON_RESOURCE} ${BASE_SOURCE} ${RESOURCE_FILES} ${QT5_MOCS}) - set_target_properties(${AppName} PROPERTIES - BUNDLE True - MACOSX_BUNDLE_GUI_IDENTIFIER pub.gpgfrontend.gpgfrontend - MACOSX_BUNDLE_BUNDLE_NAME ${AppName} - MACOSX_BUNDLE_LONG_VERSION_STRING ${BUILD_VERSION} - MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION} - MACOSX_BUNDLE_BUNDLE_VERSION ${BUILD_VERSION} - MACOSX_BUNDLE_ICON_FILE "gpgfrontend.icns") - add_custom_command(TARGET ${AppName} POST_BUILD - COMMAND /bin/rm -rf ./${AppName}.app/Contents/Resources - WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} - COMMENT "Deleting Resources in App Bundle") - add_custom_command(TARGET ${AppName} POST_BUILD - COMMAND /bin/mv -n ./Resources ./${AppName}.app/Contents/ - WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} - COMMENT "Copying Resources into App Bundle Resource") - elseif(LINUX) - add_executable(${AppName} ${BASE_SOURCE} ${RESOURCE_FILES} ${QT5_MOCS}) - add_custom_command(TARGET ${AppName} POST_BUILD - COMMAND /bin/mkdir ./gpgfrontend/usr/bin && /bin/mv -f ./${AppName} ./gpgfrontend/usr/bin/ - WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} - COMMENT "Copying Binary into App Image") - add_custom_command(TARGET ${AppName} POST_BUILD - COMMAND /bin/mkdir ./gpgfrontend/usr/lib + message(STATUS "Copying Dependent DLL For Windows Runtime Env") + file(COPY ${CMAKE_SOURCE_DIR}/resource/utils/lib/ DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN) + file(COPY ${CMAKE_SOURCE_DIR}/resource/utils/gpgme/ DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN) + file(COPY ${CMAKE_SOURCE_DIR}/resource/utils/bearer DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN) + file(COPY ${CMAKE_SOURCE_DIR}/resource/utils/iconengines DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN) + file(COPY ${CMAKE_SOURCE_DIR}/resource/utils/imageformats DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN) + file(COPY ${CMAKE_SOURCE_DIR}/resource/utils/printsupport DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN) + file(COPY ${CMAKE_SOURCE_DIR}/resource/utils/platforms DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN) + file(COPY ${CMAKE_SOURCE_DIR}/resource/utils/openssl/ DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN) + endif() +endif() + +if(APPLICATION_BUILD) + set(RESOURCE_FILES ${CMAKE_SOURCE_DIR}/gpgfrontend.qrc ${APP_ICON_RESOURCE_WINDOWS} ${QON_QM_FILES}) + add_custom_target(resources ALL DEPENDS ${RESOURCE_FILES}) + if(MULTI_LANG_SUPPORT) + add_dependencies(resources translations) + endif() +endif() + +if(APPLICATION_BUILD) + if(${CMAKE_BUILD_TYPE} STREQUAL "Release") + if(MINGW) + add_executable(${AppName} WIN32 ${BASE_SOURCE} ${RESOURCE_FILES} ${QT5_MOCS}) + elseif(APPLE) + add_executable(${AppName} MACOSX_BUNDLE ${ICON_RESOURCE} ${BASE_SOURCE} ${RESOURCE_FILES} ${QT5_MOCS}) + set_target_properties(${AppName} PROPERTIES + BUNDLE True + MACOSX_BUNDLE_GUI_IDENTIFIER pub.gpgfrontend.gpgfrontend + MACOSX_BUNDLE_BUNDLE_NAME ${AppName} + MACOSX_BUNDLE_LONG_VERSION_STRING ${BUILD_VERSION} + MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION} + MACOSX_BUNDLE_BUNDLE_VERSION ${BUILD_VERSION} + MACOSX_BUNDLE_ICON_FILE "gpgfrontend.icns") + add_custom_command(TARGET ${AppName} POST_BUILD + COMMAND /bin/rm -rf ./${AppName}.app/Contents/Resources WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} - COMMENT "Complement to build the required architecture") + COMMENT "Deleting Resources in App Bundle") + add_custom_command(TARGET ${AppName} POST_BUILD + COMMAND /bin/mv -n ./Resources ./${AppName}.app/Contents/ + WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} + COMMENT "Copying Resources into App Bundle Resource") + elseif(LINUX) + add_executable(${AppName} ${BASE_SOURCE} ${RESOURCE_FILES} ${QT5_MOCS}) + add_custom_command(TARGET ${AppName} POST_BUILD + COMMAND /bin/mkdir ./gpgfrontend/usr/bin && /bin/mv -f ./${AppName} ./gpgfrontend/usr/bin/ + WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} + COMMENT "Copying Binary into App Image") + add_custom_command(TARGET ${AppName} POST_BUILD + COMMAND /bin/mkdir ./gpgfrontend/usr/lib + WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} + COMMENT "Complement to build the required architecture") + else() + add_executable(${AppName} ${BASE_SOURCE} ${RESOURCE_FILES} ${QT5_MOCS}) + endif() else() add_executable(${AppName} ${BASE_SOURCE} ${RESOURCE_FILES} ${QT5_MOCS}) endif() -else() - add_executable(${AppName} ${BASE_SOURCE} ${RESOURCE_FILES} ${QT5_MOCS}) -endif() - -set(GPGFRONTEND_LIBS smtp gpgfrontend-ui advance server gpg) -set(QT_DEPENDENCY_LIBS Qt5::Network Qt5::PrintSupport Qt5::Widgets Qt5::Test Qt5::Core) - -IF (MINGW) - message(STATUS "Link Application Static Library For MINGW") - target_link_libraries(${AppName} - ${GPGFRONTEND_LIBS} - ${QT_DEPENDENCY_LIBS} - crypto ssl) -elseif(APPLE) - message(STATUS "Link Application Static Library For macOS") - target_link_libraries(${AppName} - ${GPGFRONTEND_LIBS} - ${QT_DEPENDENCY_LIBS} - crypto ssl) -else() - message(STATUS "Link Application Static Library For UNIX") - target_link_libraries(${AppName} - ${GPGFRONTEND_LIBS} - ${QT_DEPENDENCY_LIBS} - crypto ssl pthread) +endif() + +if(APPLICATION_BUILD) + set(GPGFRONTEND_LIBS smtp gpgfrontend-ui advance server gpg_core) + set(QT_DEPENDENCY_LIBS Qt5::Network Qt5::PrintSupport Qt5::Widgets Qt5::Test Qt5::Core) + IF (MINGW) + message(STATUS "Link Application Static Library For MINGW") + target_link_libraries(${AppName} + ${GPGFRONTEND_LIBS} + ${QT_DEPENDENCY_LIBS} + crypto ssl) + elseif(APPLE) + message(STATUS "Link Application Static Library For macOS") + target_link_libraries(${AppName} + ${GPGFRONTEND_LIBS} + ${QT_DEPENDENCY_LIBS} + crypto ssl) + else() + message(STATUS "Link Application Static Library For UNIX") + target_link_libraries(${AppName} + ${GPGFRONTEND_LIBS} + ${QT_DEPENDENCY_LIBS} + crypto ssl pthread) + endif() endif() diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 73f55672..d2c306ef 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -35,7 +35,7 @@ MainWindow::MainWindow() auto waitingDialog = new WaitingDialog(tr("Loading Gnupg"), this); // Init Gnupg - auto ctx_thread = QThread::create([&]() { mCtx = new GpgME::GpgContext(); }); + auto ctx_thread = QThread::create([&]() { mCtx = new GpgFrontend::GpgContext(); }); ctx_thread->start(); while (ctx_thread->isRunning()) QApplication::processEvents(); diff --git a/src/advance/UnknownSignersChecker.cpp b/src/advance/UnknownSignersChecker.cpp index 1b087b5c..73516beb 100644 --- a/src/advance/UnknownSignersChecker.cpp +++ b/src/advance/UnknownSignersChecker.cpp @@ -25,7 +25,7 @@ #include "advance/UnknownSignersChecker.h" -UnknownSignersChecker::UnknownSignersChecker(GpgME::GpgContext *ctx, gpgme_verify_result_t result) : +UnknownSignersChecker::UnknownSignersChecker(GpgFrontend::GpgContext *ctx, gpgme_verify_result_t result) : appPath(qApp->applicationDirPath()), settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini"), mCtx(ctx), mResult(result) { @@ -72,7 +72,7 @@ void UnknownSignersChecker::start() { void UnknownSignersChecker::check_signer(gpgme_signature_t sign) { - auto key = mCtx->getKeyByFpr(sign->fpr); + auto key = mCtx->getKeyRefByFpr(sign->fpr); if (!key.good) { qDebug() << "Find Unknown FingerPrint " << sign->fpr; unknownFprs.append(sign->fpr); diff --git a/src/gpg/CMakeLists.txt b/src/gpg/CMakeLists.txt index 2bcacade..2eabceaf 100644 --- a/src/gpg/CMakeLists.txt +++ b/src/gpg/CMakeLists.txt @@ -1,8 +1,9 @@ aux_source_directory(./result_analyse GPG_SOURCE) aux_source_directory(./gpg_context GPG_SOURCE) +aux_source_directory(./function GPG_SOURCE) aux_source_directory(. GPG_SOURCE) -add_library(gpg STATIC ${GPG_SOURCE}) +add_library(gpg_core STATIC ${GPG_SOURCE}) set(UTILS_DIR ${CMAKE_SOURCE_DIR}/utils) @@ -10,19 +11,18 @@ set(GPGME_LIB_DIR ${UTILS_DIR}/gpgme/lib) if (MINGW) message(STATUS "Link GPG Static Library For MINGW") - target_link_libraries(gpg + target_link_libraries(gpg_core gpgme gpg-error assuan Qt5::Network Qt5::PrintSupport Qt5::Widgets Qt5::Test Qt5::Core wsock32) elseif(APPLE) message(STATUS "Link GPG Static Library For macOS") - target_link_libraries(gpg + target_link_libraries(gpg_core /usr/local/lib/libgpgme.a /usr/local/lib/libgpg-error.a /usr/local/lib/libassuan.a Qt5::Network Qt5::PrintSupport Qt5::Widgets Qt5::Test Qt5::Core) else() - message(STATUS "Link GPG Static Library For Unix") - target_link_libraries(gpg + target_link_libraries(gpg_core /usr/local/lib/libgpgme.a /usr/local/lib/libgpg-error.a /usr/local/lib/libassuan.a Qt5::Network Qt5::PrintSupport Qt5::Widgets Qt5::Test Qt5::Core) endif() diff --git a/src/gpg/GpgFileOpera.cpp b/src/gpg/GpgFileOpera.cpp index af50c79a..727bfb6f 100644 --- a/src/gpg/GpgFileOpera.cpp +++ b/src/gpg/GpgFileOpera.cpp @@ -23,7 +23,7 @@ */ #include "gpg/GpgFileOpera.h" -gpgme_error_t GpgFileOpera::encryptFile(GpgME::GpgContext *ctx, QVector<GpgKey> &keys, const QString &mPath, +gpgme_error_t GpgFileOpera::encryptFile(GpgFrontend::GpgContext *ctx, QVector<GpgKey> &keys, const QString &mPath, gpgme_encrypt_result_t *result) { QFileInfo fileInfo(mPath); @@ -55,7 +55,7 @@ gpgme_error_t GpgFileOpera::encryptFile(GpgME::GpgContext *ctx, QVector<GpgKey> return error; } -gpgme_error_t GpgFileOpera::decryptFile(GpgME::GpgContext *ctx, const QString &mPath, gpgme_decrypt_result_t *result) { +gpgme_error_t GpgFileOpera::decryptFile(GpgFrontend::GpgContext *ctx, const QString &mPath, gpgme_decrypt_result_t *result) { QFileInfo fileInfo(mPath); @@ -96,7 +96,7 @@ gpgme_error_t GpgFileOpera::decryptFile(GpgME::GpgContext *ctx, const QString &m return error; } -gpgme_error_t GpgFileOpera::signFile(GpgME::GpgContext *ctx, QVector<GpgKey> &keys, const QString &mPath, +gpgme_error_t GpgFileOpera::signFile(GpgFrontend::GpgContext *ctx, QVector<GpgKey> &keys, const QString &mPath, gpgme_sign_result_t *result) { QFileInfo fileInfo(mPath); @@ -130,7 +130,7 @@ gpgme_error_t GpgFileOpera::signFile(GpgME::GpgContext *ctx, QVector<GpgKey> &ke return error; } -gpgme_error_t GpgFileOpera::verifyFile(GpgME::GpgContext *ctx, const QString &mPath, gpgme_verify_result_t *result) { +gpgme_error_t GpgFileOpera::verifyFile(GpgFrontend::GpgContext *ctx, const QString &mPath, gpgme_verify_result_t *result) { qDebug() << "Verify File Path" << mPath; @@ -165,7 +165,7 @@ gpgme_error_t GpgFileOpera::verifyFile(GpgME::GpgContext *ctx, const QString &mP } } -gpg_error_t GpgFileOpera::encryptSignFile(GpgME::GpgContext *ctx, QVector<GpgKey> &keys, const QString &mPath, +gpg_error_t GpgFileOpera::encryptSignFile(GpgFrontend::GpgContext *ctx, QVector<GpgKey> &keys, const QString &mPath, gpgme_encrypt_result_t *encr_res, gpgme_sign_result_t *sign_res) { @@ -205,7 +205,7 @@ gpg_error_t GpgFileOpera::encryptSignFile(GpgME::GpgContext *ctx, QVector<GpgKey return error; } -gpg_error_t GpgFileOpera::decryptVerifyFile(GpgME::GpgContext *ctx, const QString &mPath, gpgme_decrypt_result_t *decr_res, +gpg_error_t GpgFileOpera::decryptVerifyFile(GpgFrontend::GpgContext *ctx, const QString &mPath, gpgme_decrypt_result_t *decr_res, gpgme_verify_result_t *verify_res) { qDebug() << "Decrypt Verify File Path" << mPath; diff --git a/src/gpg/GpgKey.cpp b/src/gpg/GpgKey.cpp index cd62fc5d..47cc32f1 100644 --- a/src/gpg/GpgKey.cpp +++ b/src/gpg/GpgKey.cpp @@ -22,253 +22,44 @@ * */ -#include "gpg/GpgKey.h" +#include "gpg/model/GpgKey.h" -void GpgKey::parse(gpgme_key_t key) { - - if(key == nullptr) return; - - good = true; - key_refer = key; - gpgme_key_ref(key_refer); - - is_private_key = key->secret; - fpr = key->fpr; - protocol = key->protocol; - expired = (key->expired != 0u); - revoked = (key->revoked != 0u); - - disabled = key->disabled; - - can_authenticate = key->can_authenticate; - can_certify = key->can_certify; - can_encrypt = key->can_encrypt; - can_sign = key->can_sign; - - last_update = QDateTime(QDateTime::fromTime_t(key->last_update)); - - switch (key->owner_trust) { - case GPGME_VALIDITY_UNKNOWN: - owner_trust = "Unknown"; - break; - case GPGME_VALIDITY_UNDEFINED: - owner_trust = "Undefined"; - break; - case GPGME_VALIDITY_NEVER: - owner_trust = "Never"; - break; - case GPGME_VALIDITY_MARGINAL: - owner_trust = "Marginal"; - break; - case GPGME_VALIDITY_FULL: - owner_trust = "FULL"; - break; - case GPGME_VALIDITY_ULTIMATE: - owner_trust = "Ultimate"; - break; - } - - uids.clear(); - auto uid = key->uids; - - while (uid != nullptr) { - uids.push_back(GpgUID(uid)); - uid = uid->next; - } - - if (!uids.isEmpty()) { - name = uids.first().name; - email = uids.first().email; - comment = uids.first().comment; - } - - subKeys.clear(); - auto next = key->subkeys; - - while (next != nullptr) { - subKeys.push_back(GpgSubKey(next)); - next = next->next; - } - - if (!subKeys.isEmpty()) { - id = subKeys.first().id; - expires = subKeys.first().expires; - pubkey_algo = subKeys.first().pubkey_algo; - create_time = subKeys.first().timestamp; - length = subKeys.first().length; - has_master_key = subKeys.first().secret; - } else { - id = ""; - } - -} - -GpgKey::GpgKey(GpgKey &&k) noexcept { - - id = std::move(k.id); - name = std::move(k.name); - email = std::move(k.email); - comment = std::move(k.comment); - fpr = std::move(k.fpr); - protocol = std::move(k.protocol); - owner_trust = std::move(k.owner_trust); - pubkey_algo = std::move(k.pubkey_algo); - last_update = std::move(k.last_update); - expires = std::move(k.expires); - create_time = std::move(k.create_time); - - length = k.length; - k.length = 0; - - can_encrypt = k.can_encrypt; - can_sign = k.can_sign; - can_certify = k.can_certify; - can_authenticate = k.can_authenticate; - - - is_private_key = k.is_private_key; - expired = k.expired; - revoked = k.revoked; - disabled = k.disabled; - k.has_master_key = k.has_master_key; - - good = k.good; - k.good = false; - - subKeys = std::move(k.subKeys); - uids = std::move(k.uids); - - key_refer = k.key_refer; - k.key_refer = nullptr; - -} - -GpgKey &GpgKey::operator=(const GpgKey &k) { - - id = k.id; - name = k.name; - email = k.email; - comment = k.comment; - fpr = k.fpr; - protocol = k.protocol; - owner_trust = k.owner_trust; - pubkey_algo = k.pubkey_algo; - last_update = k.last_update; - expires = k.expires; - create_time = k.create_time; - - length = k.length; - - can_encrypt = k.can_encrypt; - can_sign = k.can_sign; - can_certify = k.can_certify; - can_authenticate = k.can_authenticate; - - is_private_key = k.is_private_key; - expired = k.expired; - revoked = k.revoked; - disabled = k.disabled; - - has_master_key = k.has_master_key; - - good = k.good; - - subKeys = k.subKeys; - uids = k.uids; - - key_refer = k.key_refer; - gpgme_key_ref(key_refer); - - return *this; -} - -GpgKey::GpgKey(const GpgKey &k) : - id(k.id), name(k.name), email(k.email), comment(k.comment), - fpr(k.fpr), protocol(k.protocol), owner_trust(k.owner_trust), - pubkey_algo(k.pubkey_algo), last_update(k.last_update), - expires(k.expires), create_time(k.create_time){ - - length = k.length; - - can_encrypt = k.can_encrypt; - can_sign = k.can_sign; - can_certify = k.can_certify; - can_authenticate = k.can_authenticate; - - is_private_key = k.is_private_key; - expired = k.expired; - revoked = k.revoked; - disabled = k.disabled; - - has_master_key = k.has_master_key; - - good = k.good; - - subKeys = k.subKeys; - uids = k.uids; - - key_refer = k.key_refer; - gpgme_key_ref(key_refer); +GpgFrontend::GpgKey::GpgKey(gpgme_key_t &&key) : _key_ref(key, [&](gpgme_key_t key) { gpgme_key_release(key); }) {} +GpgFrontend::GpgKey::GpgKey(GpgKey &&k) noexcept { + swap(_key_ref, k._key_ref); } -GpgKey &GpgKey::operator=(GpgKey &&k) noexcept { - - id = std::move(k.id); - name = std::move(k.name); - email = std::move(k.email); - comment = std::move(k.comment); - fpr = std::move(k.fpr); - protocol = std::move(k.protocol); - owner_trust = std::move(k.owner_trust); - pubkey_algo = std::move(k.pubkey_algo); - last_update = std::move(k.last_update); - expires = std::move(k.expires); - create_time = std::move(k.create_time); - - length = k.length; - k.length = 0; - - can_encrypt = k.can_encrypt; - can_sign = k.can_sign; - can_certify = k.can_certify; - can_authenticate = k.can_authenticate; - - - is_private_key = k.is_private_key; - expired = k.expired; - revoked = k.revoked; - disabled = k.disabled; - - has_master_key = k.has_master_key; - - good = k.good; - k.good = false; - - subKeys = std::move(k.subKeys); - uids = std::move(k.uids); - - key_refer = k.key_refer; - k.key_refer = nullptr; - +GpgFrontend::GpgKey &GpgFrontend::GpgKey::operator=(GpgKey &&k) noexcept { + swap(_key_ref, k._key_ref); return *this; } -GpgKey::~GpgKey() { - if(key_refer != nullptr && good) { - gpgme_key_unref(key_refer); +std::unique_ptr<std::vector<GpgFrontend::GpgSubKey>> GpgFrontend::GpgKey::subKeys() const { + auto p_keys = std::make_unique<std::vector<GpgSubKey>>(); + auto next = _key_ref->subkeys; + while (next != nullptr) { + p_keys->push_back(std::move(GpgSubKey(next))); + next = next->next; } + return p_keys; } -GpgKey::GpgKey(gpgme_key_t key) { - parse(key); +std::unique_ptr<std::vector<GpgFrontend::GpgUID>> GpgFrontend::GpgKey::uids() const { + auto p_uids = std::make_unique<std::vector<GpgUID>>(); + auto uid_next = _key_ref->uids; + while (uid_next != nullptr) { + p_uids->push_back(std::move(GpgUID(uid_next))); + uid_next = uid_next->next; + } + return p_uids; } -void GpgKey::swapKeyRefer(gpgme_key_t key) { - - if(key == nullptr) return; - - gpgme_key_unref(key_refer); - key_refer = nullptr; - parse(key); +bool GpgFrontend::GpgKey::canSignActual() const { + auto subkeys = subKeys(); + if (std::any_of(subkeys->begin(), subkeys->end(), [](const GpgSubKey &subkey) -> bool { + return subkey.secret() && subkey.can_sign() && !subkey.disabled() && !subkey.revoked() && !subkey.expired(); + })) + return true; + else return false; } diff --git a/src/gpg/GpgKeySignature.cpp b/src/gpg/GpgKeySignature.cpp index 142d1550..d7e7c53e 100644 --- a/src/gpg/GpgKeySignature.cpp +++ b/src/gpg/GpgKeySignature.cpp @@ -22,13 +22,7 @@ * */ -#include "gpg/GpgKeySignature.h" +#include "gpg/model/GpgKeySignature.h" -GpgKeySignature::GpgKeySignature(gpgme_key_sig_t key_sig) : - revoked(key_sig->revoked), expired(key_sig->expired), invalid(key_sig->invalid), - exportable(key_sig->exportable), status(key_sig->status), - keyid(key_sig->keyid), pubkey_algo(gpgme_pubkey_algo_name(key_sig->pubkey_algo)), - uid(key_sig->uid), name(key_sig->name), email(key_sig->email), comment(key_sig->comment), - create_time(QDateTime::fromTime_t(key_sig->timestamp)), expire_time(QDateTime::fromTime_t(key_sig->expires)){ - -} +GpgFrontend::GpgKeySignature::GpgKeySignature(gpgme_key_sig_t sig) : _signature_ref(sig, + [&](gpgme_key_sig_t signature) {}) {} diff --git a/src/gpg/GpgSubKey.cpp b/src/gpg/GpgSubKey.cpp index 4adda132..87476d56 100644 --- a/src/gpg/GpgSubKey.cpp +++ b/src/gpg/GpgSubKey.cpp @@ -21,31 +21,6 @@ * by Saturneric<[email protected]> starting on May 12, 2021. * */ -#include "gpg/GpgSubKey.h" +#include "gpg/model/GpgSubKey.h" -GpgSubKey::GpgSubKey(gpgme_subkey_t key) { - - if (key == nullptr) return; - - id = key->keyid; - pubkey_algo = gpgme_pubkey_algo_name(key->pubkey_algo); - fpr = key->fpr; - - expired = key->expired; - revoked = key->revoked; - secret = key->secret; - - disabled = key->disabled; - - length = key->length; - - can_authenticate = key->can_authenticate; - can_certify = key->can_certify; - can_encrypt = key->can_encrypt; - can_sign = key->can_sign; - is_cardkey = key->is_cardkey; - is_private_key = key->secret; - - timestamp = QDateTime::fromTime_t(key->timestamp); - expires = QDateTime::fromTime_t(key->expires); -} +GpgFrontend::GpgSubKey::GpgSubKey(gpgme_subkey_t subkey) : _subkey_ref(subkey, [&](gpgme_subkey_t subkey) {}) {} diff --git a/src/gpg/GpgUID.cpp b/src/gpg/GpgUID.cpp index 0dc6abfd..ae58daf1 100644 --- a/src/gpg/GpgUID.cpp +++ b/src/gpg/GpgUID.cpp @@ -22,17 +22,6 @@ * */ -#include "gpg/GpgUID.h" +#include "gpg/model/GpgUID.h" -GpgUID::GpgUID(gpgme_user_id_t user_id) : - uid(user_id->uid), name(user_id->name), email(user_id->email), comment(user_id->comment), - revoked(user_id->revoked), invalid(user_id->invalid) { - - auto sig = user_id->signatures; - - while (sig != nullptr) { - signatures.push_back(GpgKeySignature(sig)); - sig = sig->next; - } - -}
\ No newline at end of file +GpgFrontend::GpgUID::GpgUID(gpgme_user_id_t uid) : _uid_ref(uid, [&](gpgme_user_id_t uid) {}) {}
\ No newline at end of file diff --git a/src/gpg/function/BasicOperator.cpp b/src/gpg/function/BasicOperator.cpp new file mode 100644 index 00000000..f81e9f71 --- /dev/null +++ b/src/gpg/function/BasicOperator.cpp @@ -0,0 +1,254 @@ +/** + * 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. + * + * Foobar 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 Foobar. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from gpg4usb-team. + * Their source code version also complies with GNU General Public License. + * + * The source code version of this software was modified and released + * by Saturneric<[email protected]> starting on May 12, 2021. + * + */ + +#include "gpg/function/BasicOperator.h" +#include "gpg/function/GpgKeyGetter.h" + +/** + * Read gpgme-Data to QByteArray + * mainly from http://basket.kde.org/ (kgpgme.cpp) + */ +#define BUF_SIZE (32 * 1024) + +gpgme_error_t read_2_buffer(gpgme_data_t data_in, GpgFrontend::BypeArrayPtr &out_buffer) { + gpgme_off_t ret = gpgme_data_seek(data_in, 0, SEEK_SET); + gpgme_error_t err = gpg_error(GPG_ERR_NO_ERROR); + + if (ret) { + err = gpgme_err_code_from_errno(errno); + GpgFrontend::check_gpg_error(err, "failed data_seek data_in read_2_buffer"); + } else { + char buf[BUF_SIZE + 2]; + + while ((ret = gpgme_data_read(data_in, buf, BUF_SIZE)) > 0) { + const size_t size = out_buffer->size(); + out_buffer->resize(static_cast<int>(size + ret)); + memcpy(out_buffer->data() + size, buf, ret); + } + if (ret < 0) { + err = gpgme_err_code_from_errno(errno); + GpgFrontend::check_gpg_error(err, "failed data_read data_in read_2_buffer"); + } + } + return err; +} + +gpg_error_t GpgFrontend::BasicOperator::encrypt(std::vector<GpgKey> &keys, GpgFrontend::BypeArrayRef in_buffer, + GpgFrontend::BypeArrayPtr &out_buffer, + GpgFrontend::GpgEncrResult &result) { + + gpgme_data_t data_in = nullptr, data_out = nullptr; + out_buffer->resize(0); + + // gpgme_encrypt_result_t e_result; + gpgme_key_t recipients[keys.size() + 1]; + + int index = 0; + for (const auto &key : keys) recipients[index++] = gpgme_key_t(key); + + // Last entry data_in array has to be nullptr + recipients[keys.size()] = nullptr; + + gpgme_error_t err; + + // If the last parameter isnt 0, a private copy of data is made + check_gpg_error(gpgme_data_new_from_mem(&data_in, in_buffer.data(), in_buffer.size(), 1)); + check_gpg_error(gpgme_data_new(&data_out)); + err = check_gpg_error(gpgme_op_encrypt(ctx, recipients, GPGME_ENCRYPT_ALWAYS_TRUST, data_in, data_out)); + check_gpg_error(read_2_buffer(data_out, out_buffer)); + + if (data_in) gpgme_data_release(data_in); + if (data_out) gpgme_data_release(data_out); + + result = GpgEncrResult(gpgme_op_encrypt_result(ctx), [&](gpgme_encrypt_result_t res) { gpgme_result_unref(res); }); + return err; +} + +gpgme_error_t GpgFrontend::BasicOperator::decrypt(BypeArrayRef in_buffer, GpgFrontend::BypeArrayPtr &out_buffer, + GpgFrontend::GpgDecrResult &result) { + gpgme_data_t data_in = nullptr, data_out = nullptr; + out_buffer->resize(0); + + gpgme_error_t err; + + check_gpg_error(gpgme_data_new_from_mem(&data_in, in_buffer.data(), in_buffer.size(), 1)); + check_gpg_error(gpgme_data_new(&data_out)); + err = check_gpg_error(gpgme_op_decrypt(ctx, data_in, data_out)); + check_gpg_error(read_2_buffer(data_out, out_buffer)); + + if (data_in) gpgme_data_release(data_in); + if (data_out) gpgme_data_release(data_out); + + result = GpgDecrResult(gpgme_op_decrypt_result(ctx), [&](gpgme_decrypt_result_t res) { gpgme_result_unref(res); }); + + return err; +} + +gpgme_error_t GpgFrontend::BasicOperator::verify(QByteArray &in_buffer, QByteArray &sig_buffer, + GpgFrontend::GpgVerifyResult &result) const { + gpgme_data_t data_in; + gpgme_error_t err; + gpgme_verify_result_t m_result; + + check_gpg_error(gpgme_data_new_from_mem(&data_in, in_buffer.data(), in_buffer.size(), 1)); + + if (sig_buffer != nullptr) { + gpgme_data_t sig_data; + check_gpg_error(gpgme_data_new_from_mem(&sig_data, sig_buffer.data(), sig_buffer.size(), 1)); + err = check_gpg_error(gpgme_op_verify(ctx, sig_data, data_in, nullptr)); + } else + err = check_gpg_error(gpgme_op_verify(ctx, data_in, nullptr, data_in)); + + result = GpgVerifyResult(gpgme_op_verify_result(ctx), [&](gpgme_verify_result_t res) { gpgme_result_unref(res); }); + + return err; +} + +gpg_error_t +GpgFrontend::BasicOperator::sign(KeyFprArgsList key_fprs, BypeArrayRef in_buffer, BypeArrayPtr &out_buffer, + gpgme_sig_mode_t mode, GpgSignResult &result) { + gpgme_error_t err; + gpgme_data_t data_in, data_out; + + out_buffer->resize(0); + + std::vector<GpgKey> keys; + auto &key_getter = GpgKeyGetter::getInstance(); + + for (const auto &key_fpr : key_fprs) + keys.push_back(key_getter.getKey(key_fpr)); + + // Set Singers of this opera + setSigners(keys); + + check_gpg_error(gpgme_data_new_from_mem(&data_in, in_buffer.data(), in_buffer.size(), 1)); + check_gpg_error(gpgme_data_new(&data_out)); + + /** + `GPGME_SIG_MODE_NORMAL' + A normal signature is made, the output includes the plaintext + and the signature. + + `GPGME_SIG_MODE_DETACH' + A detached signature is made. + + `GPGME_SIG_MODE_CLEAR' + A clear text signature is made. The ASCII armor and text + mode settings of the context are ignored. + */ + + err = check_gpg_error(gpgme_op_sign(ctx, data_in, data_out, mode)); + check_gpg_error(read_2_buffer(data_out, out_buffer)); + + gpgme_data_release(data_in); + gpgme_data_release(data_out); + + result = GpgSignResult(gpgme_op_sign_result(ctx), [&](gpgme_sign_result_t res) { gpgme_result_unref(res); }); + + return err; +} + +gpgme_error_t +GpgFrontend::BasicOperator::decryptVerify(const BypeArrayRef in_buffer, BypeArrayPtr &out_buffer, + GpgDecrResult &decrypt_result, GpgVerifyResult &verify_result) { + gpgme_error_t err; + gpgme_data_t data_in, data_out; + out_buffer->resize(0); + + check_gpg_error(gpgme_data_new_from_mem(&data_in, in_buffer.data(), in_buffer.size(), 1)); + check_gpg_error(gpgme_data_new(&data_out)); + err = check_gpg_error(gpgme_op_decrypt_verify(ctx, data_in, data_out)); + + check_gpg_error(read_2_buffer(data_out, out_buffer)); + + if (data_in) gpgme_data_release(data_in); + if (data_out) gpgme_data_release(data_out); + + decrypt_result = GpgDecrResult(gpgme_op_decrypt_result(ctx), + [&](gpgme_decrypt_result_t res) { gpgme_result_unref(res); }); + verify_result = GpgVerifyResult(gpgme_op_verify_result(ctx), + [&](gpgme_verify_result_t res) { gpgme_result_unref(res); }); + + + return err; +} + +gpgme_error_t GpgFrontend::BasicOperator::encryptSign(std::vector<GpgKey> &keys, std::vector<GpgKey> &signers, + BypeArrayRef in_buffer, + BypeArrayPtr &out_buffer, GpgEncrResult &encr_result, + GpgSignResult &sign_result) { + gpgme_error_t err; + gpgme_data_t data_in, data_out; + out_buffer->resize(0); + + setSigners(signers); + + //gpgme_encrypt_result_t e_result; + gpgme_key_t recipients[keys.size() + 1]; + + // set key for user + int index = 0; + for (const auto &key : keys) recipients[index++] = gpgme_key_t(key); + + // Last entry dataIn array has to be nullptr + recipients[keys.size()] = nullptr; + + // If the last parameter isnt 0, a private copy of data is made + check_gpg_error(gpgme_data_new_from_mem(&data_in, in_buffer.data(), in_buffer.size(), 1)); + check_gpg_error(gpgme_data_new(&data_out)); + err = check_gpg_error(gpgme_op_encrypt_sign(ctx, recipients, GPGME_ENCRYPT_ALWAYS_TRUST, data_in, data_out)); + + check_gpg_error(read_2_buffer(data_out, out_buffer)); + + if (data_in) gpgme_data_release(data_in); + if (data_out) gpgme_data_release(data_out); + + encr_result = GpgEncrResult(gpgme_op_encrypt_result(ctx), + [&](gpgme_encrypt_result_t res) { gpgme_result_unref(res); }); + sign_result = GpgSignResult(gpgme_op_sign_result(ctx), [&](gpgme_sign_result_t res) { gpgme_result_unref(res); }); + + return err; +} + +void GpgFrontend::BasicOperator::setSigners(KeyArgsList keys) { + gpgme_signers_clear(ctx); + for (const GpgKey &key : keys) { + if (key.canSignActual()) { + auto gpgmeError = gpgme_signers_add(ctx, gpgme_key_t(key)); + check_gpg_error(gpgmeError); + } + } + if (keys.size() != gpgme_signers_count(ctx)) + qDebug() << "No All Signers Added"; +} + +std::unique_ptr<std::vector<GpgFrontend::GpgKey>> GpgFrontend::BasicOperator::getSigners() { + auto count = gpgme_signers_count(ctx); + auto signers = std::make_unique<std::vector<GpgKey>>(); + for (auto i = 0; i < count; i++) { + auto key = GpgKey(gpgme_signers_enum(ctx, i)); + signers->push_back(std::move(GpgKey(std::move(key)))); + } + return signers; +} diff --git a/include/gpg/GpgKeySignature.h b/src/gpg/function/GpgKeyGetter.cpp index 0dd2f893..e4572290 100644 --- a/include/gpg/GpgKeySignature.h +++ b/src/gpg/function/GpgKeyGetter.cpp @@ -22,46 +22,17 @@ * */ -#ifndef GPGFRONTEND_GPGKEYSIGNATURE_H -#define GPGFRONTEND_GPGKEYSIGNATURE_H +#include "gpg/function/GpgKeyGetter.h" -#include "GpgFrontend.h" -struct GpgKeySignature { +GpgFrontend::GpgKey &&GpgFrontend::GpgKeyGetter::getKey(const std::string &fpr) { + gpgme_key_t _p_key; + gpgme_get_key(ctx, fpr.c_str(), &_p_key, 1); + return std::move(GpgKey(std::move(_p_key))); +} - bool revoked{}; - bool expired{}; - bool invalid{}; - bool exportable{}; - - gpgme_error_t status{}; - - QString keyid; - QString pubkey_algo; - - QDateTime create_time; - QDateTime expire_time; - - QString uid; - QString name; - QString email; - QString comment; - - gpgme_sigsum_t summary; - - GpgKeySignature() = default; - - explicit GpgKeySignature(gpgme_key_sig_t key_sig); - - GpgKeySignature(GpgKeySignature &&) noexcept = default; - - GpgKeySignature(const GpgKeySignature &) = default; - - GpgKeySignature &operator=(GpgKeySignature &&) noexcept = default; - - GpgKeySignature &operator=(const GpgKeySignature &) = default; - -}; - - -#endif //GPGFRONTEND_GPGKEYSIGNATURE_H +GpgFrontend::GpgKey &&GpgFrontend::GpgKeyGetter::getPubkey(const std::string &fpr) { + gpgme_key_t _p_key; + gpgme_get_key(ctx, fpr.c_str(), &_p_key, 0); + return std::move(GpgKey(std::move(_p_key))); +} diff --git a/src/gpg/function/GpgKeyManager.cpp b/src/gpg/function/GpgKeyManager.cpp new file mode 100644 index 00000000..b27163c8 --- /dev/null +++ b/src/gpg/function/GpgKeyManager.cpp @@ -0,0 +1,76 @@ +/** + * 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. + * + * Foobar 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 Foobar. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from gpg4usb-team. + * Their source code version also complies with GNU General Public License. + * + * The source code version of this software was modified and released + * by Saturneric<[email protected]> starting on May 12, 2021. + * + */ + + +#include "gpg/function/GpgKeyManager.h" +#include "gpg/function/GpgKeyGetter.h" +#include "gpg/function/BasicOperator.h" + +bool GpgFrontend::GpgKeyManager::signKey(const GpgFrontend::GpgKey &target, GpgFrontend::KeyArgsList &keys, + const QString &uid, std::unique_ptr<QDateTime> &expires) { + BasicOperator::getInstance().setSigners(keys); + + unsigned int flags = 0; + + unsigned int expires_time_t = 0; + if (expires == nullptr) flags |= GPGME_KEYSIGN_NOEXPIRE; + else expires_time_t = QDateTime::currentDateTime().secsTo(*expires); + + auto err = + check_gpg_error( + gpgme_op_keysign(ctx, gpgme_key_t(target), uid.toUtf8().constData(), expires_time_t, flags)); + + if (gpg_err_code(err) == GPG_ERR_NO_ERROR) return true; + else return false; +} + +bool +GpgFrontend::GpgKeyManager::revSign(const GpgFrontend::GpgKey &key, const GpgFrontend::GpgKeySignature &signature) { + + auto &key_getter = GpgKeyGetter::getInstance(); + auto signing_key = key_getter.getKey(signature.keyid()); + + auto err = check_gpg_error(gpgme_op_revsig(ctx, gpgme_key_t(key), gpgme_key_t(signing_key), + signature.uid().data(), 0)); + if (gpg_err_code(err) == GPG_ERR_NO_ERROR) return true; + else return false; + +} + +bool GpgFrontend::GpgKeyManager::setExpire(const GpgFrontend::GpgKey &key, std::unique_ptr<GpgSubKey> &subkey, + std::unique_ptr<QDateTime> &expires) { + unsigned long expires_time = 0; + if (expires != nullptr) { + qDebug() << "Expire Datetime" << expires->toString(); + expires_time = QDateTime::currentDateTime().secsTo(*expires); + } + + const char *sub_fprs = nullptr; + + if (subkey != nullptr) sub_fprs = subkey->fpr().toUtf8().constData(); + + auto err = check_gpg_error(gpgme_op_setexpire(ctx, gpgme_key_t(key), expires_time, sub_fprs, 0)); + if (gpg_err_code(err) == GPG_ERR_NO_ERROR) return true; + else return false; +} diff --git a/src/gpg/function/UidOperator.cpp b/src/gpg/function/UidOperator.cpp new file mode 100644 index 00000000..91fe70fe --- /dev/null +++ b/src/gpg/function/UidOperator.cpp @@ -0,0 +1,45 @@ +/** + * 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. + * + * Foobar 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 Foobar. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from gpg4usb-team. + * Their source code version also complies with GNU General Public License. + * + * The source code version of this software was modified and released + * by Saturneric<[email protected]> starting on May 12, 2021. + * + */ + +#include "gpg/function/UidOperator.h" + +bool GpgFrontend::UidOperator::addUID(const GpgFrontend::GpgKey &key, const GpgFrontend::GpgUID &uid) { + QString userid = QString("%1 (%3) <%2>").arg(uid.name(), uid.email(), uid.comment()); + auto err = gpgme_op_adduid(ctx, gpgme_key_t(key), userid.toUtf8().constData(), 0); + if (gpgme_err_code(err) == GPG_ERR_NO_ERROR) return true; + else return false; +} + +bool GpgFrontend::UidOperator::revUID(const GpgFrontend::GpgKey &key, const GpgFrontend::GpgUID &uid) { + auto err = check_gpg_error(gpgme_op_revuid(ctx, gpgme_key_t(key), uid.uid().toUtf8().constData(), 0)); + if (gpgme_err_code(err) == GPG_ERR_NO_ERROR) return true; + else return false; +} + +bool GpgFrontend::UidOperator::setPrimaryUID(const GpgFrontend::GpgKey &key, const GpgFrontend::GpgUID &uid) { + auto err = check_gpg_error(gpgme_op_set_uid_flag(ctx, gpgme_key_t(key), + uid.uid().toUtf8().constData(), "primary", nullptr)); + if (gpgme_err_code(err) == GPG_ERR_NO_ERROR) return true; + else return false; +} diff --git a/src/gpg/gpg_context/GpgContext.cpp b/src/gpg/gpg_context/GpgContext.cpp index 14b54b32..6887191b 100644 --- a/src/gpg/gpg_context/GpgContext.cpp +++ b/src/gpg/gpg_context/GpgContext.cpp @@ -36,36 +36,23 @@ #define INT2VOIDP(i) (void*)(uintptr_t)(i) -namespace GpgME { +namespace GpgFrontend { - /** Constructor + /** + * Constructor * Set up gpgme-context, set paths to app-run path */ GpgContext::GpgContext() { - /** The function `gpgme_check_version' must be called before any other - * function in the library, because it initializes the thread support - * subsystem in GPGME. (from the info page) */ - gpgme_check_version(nullptr); - - // the locale set here is used for the other setlocale calls which have nullptr - // -> nullptr means use default, which is configured here - setlocale(LC_ALL, settings.value("int/lang").toLocale().name().toUtf8().constData()); - - /** set locale, because tests do also */ - gpgme_set_locale(nullptr, LC_CTYPE, setlocale(LC_CTYPE, nullptr)); - //qDebug() << "Locale set to" << LC_CTYPE << " - " << setlocale(LC_CTYPE, nullptr); -#ifndef _WIN32 - gpgme_set_locale(nullptr, LC_MESSAGES, setlocale(LC_MESSAGES, nullptr)); -#endif - - err = gpgme_new(&mCtx); - checkErr(err); + gpgme_ctx_t _p_ctx; + err = gpgme_new(&_p_ctx); + check_gpg_error(err); + _ctx_ref = CtxRefHandler(_p_ctx, [&](gpgme_ctx_t ctx) { gpgme_release(ctx); }); gpgme_engine_info_t engineInfo; - engineInfo = gpgme_ctx_get_engine_info(mCtx); + engineInfo = gpgme_ctx_get_engine_info(*this); -// Check ENV before running + // Check ENV before running bool check_pass = false, find_openpgp = false, find_gpgconf = false, find_assuan = false, find_cms = false; while (engineInfo != nullptr) { qDebug() << gpgme_get_protocol_name(engineInfo->protocol) << engineInfo->file_name << engineInfo->protocol @@ -91,68 +78,30 @@ namespace GpgME { } else good = true; -/** Setting the output type must be done at the beginning */ -/** think this means ascii-armor --> ? */ - gpgme_set_armor(mCtx, 1); -/** passphrase-callback */ - gpgme_set_passphrase_cb(mCtx, passphraseCb, this); + /** Setting the output type must be done at the beginning */ + /** think this means ascii-armor --> ? */ + gpgme_set_armor(*this, 1); + /** passphrase-callback */ + gpgme_set_passphrase_cb(*this, passphraseCb, this); -/** check if app is called with -d from command line */ + /** check if app is called with -d from command line */ if (qApp->arguments().contains("-d")) { qDebug() << "gpgme_data_t debug on"; debug = true; - } else { - debug = false; - } + } else debug = false; connect(this, SIGNAL(signalKeyDBChanged()), this, SLOT(slotRefreshKeyList()), Qt::DirectConnection); connect(this, SIGNAL(signalKeyUpdated(QString)), this, SLOT(slotUpdateKeyList(QString)), Qt::DirectConnection); - slotRefreshKeyList(); - } - /** Destructor - * Release gpgme-context - */ - GpgContext::~GpgContext() { - if (mCtx) gpgme_release(mCtx); - mCtx = nullptr; + slotRefreshKeyList(); } bool GpgContext::isGood() const { return good; } - /** Read gpgme-Data to QByteArray - * mainly from http://basket.kde.org/ (kgpgme.cpp) - */ -#define BUF_SIZE (32 * 1024) - - gpgme_error_t GpgContext::readToBuffer(gpgme_data_t dataIn, QByteArray *outBuffer) { - gpgme_off_t ret; - gpgme_error_t gpgErrNoError = GPG_ERR_NO_ERROR; - - ret = gpgme_data_seek(dataIn, 0, SEEK_SET); - if (ret) { - gpgErrNoError = gpgme_err_code_from_errno(errno); - checkErr(gpgErrNoError, "failed dataseek dataIn readToBuffer"); - } else { - char buf[BUF_SIZE + 2]; - - while ((ret = gpgme_data_read(dataIn, buf, BUF_SIZE)) > 0) { - const size_t size = outBuffer->size(); - outBuffer->resize(static_cast<int>(size + ret)); - memcpy(outBuffer->data() + size, buf, ret); - } - if (ret < 0) { - gpgErrNoError = gpgme_err_code_from_errno(errno); - checkErr(gpgErrNoError, "failed data_read dataIn readToBuffer"); - } - } - return gpgErrNoError; - } - /** * The Passphrase window, if not provided by env-Var GPG_AGENT_INFO * originally copied from http://basket.kde.org/ (kgpgme.cpp), but modified @@ -229,24 +178,22 @@ namespace GpgME { } // error-handling - void GpgContext::checkErr(gpgme_error_t gpgmeError, const QString &comment) { + gpgme_error_t check_gpg_error(gpgme_error_t err, const QString &comment) { //if (gpgmeError != GPG_ERR_NO_ERROR && gpgmeError != GPG_ERR_CANCELED) { - if (gpgmeError != GPG_ERR_NO_ERROR) { - qDebug() << "[Error " << gpg_err_code(gpgmeError) - << "] Source: " << gpgme_strsource(gpgmeError) << " Description: " << gpgErrString(gpgmeError); + if (gpg_err_code(err) != GPG_ERR_NO_ERROR) { + qDebug() << "[Error " << gpg_err_code(err) + << "] Source: " << gpgme_strsource(err) << " Description: " << gpgme_strerror(err); } + return err; } - void GpgContext::checkErr(gpgme_error_t gpgmeError) { + gpgme_error_t check_gpg_error(gpgme_error_t err) { //if (gpgmeError != GPG_ERR_NO_ERROR && gpgmeError != GPG_ERR_CANCELED) { - if (gpg_err_code(gpgmeError) != GPG_ERR_NO_ERROR) { - qDebug() << "[Error " << gpg_err_code(gpgmeError) - << "] Source: " << gpgme_strsource(gpgmeError) << " Description: " << gpgErrString(gpgmeError); + if (gpg_err_code(err) != GPG_ERR_NO_ERROR) { + qDebug() << "[Error " << gpg_err_code(err) + << "] Source: " << gpgme_strsource(err) << " Description: " << gpgme_strerror(err); } - } - - QString GpgContext::gpgErrString(gpgme_error_t err) { - return QString::fromUtf8(gpgme_strerror(err)); + return err; } /** return type should be gpgme_error_t*/ @@ -329,82 +276,26 @@ namespace GpgME { return mKeyList; } - void GpgContext::getSigners(QVector<GpgKey> &signer, gpgme_ctx_t ctx) { - auto count = gpgme_signers_count(ctx); - signer.clear(); - for (auto i = 0; i < count; i++) { - auto key = gpgme_signers_enum(ctx, i); - auto it = mKeyMap.find(key->subkeys->keyid); - if (it == mKeyMap.end()) { - qDebug() << "Inconsistent state"; - signer.push_back(GpgKey(key)); - } else { - signer.push_back(*it.value()); - } - } - } - - void GpgContext::setSigners(const QVector<GpgKey> &keys, gpgme_ctx_t ctx) { - gpgme_signers_clear(ctx); - for (const auto &key : keys) { - if (checkIfKeyCanSign(key)) { - auto gpgmeError = gpgme_signers_add(ctx, key.key_refer); - checkErr(gpgmeError); - } - } - if (keys.length() != gpgme_signers_count(ctx)) { - qDebug() << "No All Keys Added"; - } - } - void GpgContext::slotUpdateKeyList(const QString &key_id) { auto it = mKeyMap.find(key_id); if (it != mKeyMap.end()) { - gpgme_key_t new_key_refer; - auto gpgmeErr = gpgme_get_key(mCtx, key_id.toUtf8().constData(), &new_key_refer, 0); + gpgme_key_t new_key_ref; + + auto gpgmeErr = gpgme_get_key(*this, key_id.toUtf8().constData(), &new_key_ref, 0); if (gpgme_err_code(gpgmeErr) == GPG_ERR_EOF) { - gpgmeErr = gpgme_get_key(mCtx, key_id.toUtf8().constData(), &new_key_refer, 1); + gpgmeErr = gpgme_get_key(*this, key_id.toUtf8().constData(), &new_key_ref, 1); - if (gpgme_err_code(gpgmeErr) == GPG_ERR_EOF) { + if (gpgme_err_code(gpgmeErr) == GPG_ERR_EOF) throw std::runtime_error("key_id not found in key database"); - } - } - if (new_key_refer != nullptr) { - it.value()->swapKeyRefer(new_key_refer); + if (new_key_ref != nullptr) { + it->second = std::move(GpgKey(std::move(new_key_ref))); emit signalKeyInfoChanged(); } } } - bool GpgContext::revSign(const GpgKey &key, const GpgKeySignature &signature) { - - auto signing_key = getKeyById(signature.keyid); - - auto gpgmeError = gpgme_op_revsig(mCtx, key.key_refer, - signing_key.key_refer, - signature.uid.toUtf8().constData(), 0); - if (gpg_err_code(gpgmeError) == GPG_ERR_NO_ERROR) { - emit signalKeyUpdated(key.id); - return true; - } else { - checkErr(gpgmeError); - return false; - } - } - - gpgme_ctx_t GpgME::GpgContext::create_ctx() { - gpgme_ctx_t ctx; - err = gpgme_new(&ctx); - checkErr(err); - - gpgme_set_armor(ctx, 1); - gpgme_set_passphrase_cb(ctx, passphraseCb, this); - return ctx; - } - - } diff --git a/src/gpg/gpg_context/GpgContextBasicOpera.cpp b/src/gpg/gpg_context/GpgContextBasicOpera.cpp deleted file mode 100644 index d9bf0bdb..00000000 --- a/src/gpg/gpg_context/GpgContextBasicOpera.cpp +++ /dev/null @@ -1,315 +0,0 @@ -/** - * 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. - * - * Foobar 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 Foobar. If not, see <https://www.gnu.org/licenses/>. - * - * The initial version of the source code is inherited from gpg4usb-team. - * Their source code version also complies with GNU General Public License. - * - * The source code version of this software was modified and released - * by Saturneric<[email protected]> starting on May 12, 2021. - * - */ - -#include "gpg/GpgContext.h" - -/** - * Encrypt data - * @param keys keys used - * @param inBuffer input byte array - * @param outBuffer output byte array - * @param result opera result - * @return error information - */ -gpg_error_t GpgME::GpgContext::encrypt(QVector<GpgKey> &keys, const QByteArray &inBuffer, QByteArray *outBuffer, - gpgme_encrypt_result_t *result) { - - gpgme_data_t dataIn = nullptr, dataOut = nullptr; - outBuffer->resize(0); - - // gpgme_encrypt_result_t e_result; - gpgme_key_t recipients[keys.count() + 1]; - - int index = 0; - for (const auto &key : keys) recipients[index++] = key.key_refer; - - // Last entry dataIn array has to be nullptr - recipients[keys.count()] = nullptr; - - // If the last parameter isnt 0, a private copy of data is made - if (mCtx) { - err = gpgme_data_new_from_mem(&dataIn, inBuffer.data(), inBuffer.size(), 1); - checkErr(err); - if (!err) { - err = gpgme_data_new(&dataOut); - checkErr(err); - if (!err) { - err = gpgme_op_encrypt(mCtx, recipients, GPGME_ENCRYPT_ALWAYS_TRUST, dataIn, dataOut); - checkErr(err); - if (!err) { - err = readToBuffer(dataOut, outBuffer); - checkErr(err); - } - } - } - } - if (dataIn) gpgme_data_release(dataIn); - if (dataOut) gpgme_data_release(dataOut); - - if (result != nullptr) *result = gpgme_op_encrypt_result(mCtx); - return err; -} - -/** - * Decrypt data - * @param keys keys used - * @param inBuffer input byte array - * @param outBuffer output byte array - * @param result opera result - * @return error information - */ -gpgme_error_t GpgME::GpgContext::decrypt(const QByteArray &inBuffer, QByteArray *outBuffer, - gpgme_decrypt_result_t *result) { - gpgme_data_t dataIn = nullptr, dataOut = nullptr; - gpgme_decrypt_result_t m_result = nullptr; - - outBuffer->resize(0); - if (mCtx != nullptr) { - err = gpgme_data_new_from_mem(&dataIn, inBuffer.data(), inBuffer.size(), 1); - if (gpgme_err_code(err) == GPG_ERR_NO_ERROR) { - err = gpgme_data_new(&dataOut); - if (gpgme_err_code(err) == GPG_ERR_NO_ERROR) { - err = gpgme_op_decrypt(mCtx, dataIn, dataOut); - m_result = gpgme_op_decrypt_result(mCtx); - if (gpgme_err_code(err) == GPG_ERR_NO_ERROR) err = readToBuffer(dataOut, outBuffer); - } - } - } - - if (!settings.value("general/rememberPassword").toBool()) clearPasswordCache(); - - if (dataIn) gpgme_data_release(dataIn); - if (dataOut) gpgme_data_release(dataOut); - - if (result != nullptr) *result = m_result; - - return err; -} - -/** - * Verify data - * @param keys keys used - * @param inBuffer input byte array - * @param sigBuffer signature byte array (detected by format) - * @param result opera result - * @return error information - */ -gpgme_error_t GpgME::GpgContext::verify(QByteArray *inBuffer, QByteArray *sigBuffer, gpgme_verify_result_t *result) { - - gpgme_data_t dataIn; - gpgme_error_t gpgmeError; - gpgme_verify_result_t m_result; - - gpgmeError = gpgme_data_new_from_mem(&dataIn, inBuffer->data(), inBuffer->size(), 1); - checkErr(gpgmeError); - - if (sigBuffer != nullptr) { - gpgme_data_t sigdata; - gpgmeError = gpgme_data_new_from_mem(&sigdata, sigBuffer->data(), sigBuffer->size(), 1); - checkErr(gpgmeError); - gpgmeError = gpgme_op_verify(mCtx, sigdata, dataIn, nullptr); - } else { - gpgmeError = gpgme_op_verify(mCtx, dataIn, nullptr, dataIn); - } - - checkErr(gpgmeError); - - m_result = gpgme_op_verify_result(mCtx); - - if (result != nullptr) { - *result = m_result; - } - - return gpgmeError; -} - -/** - * Sign data - * @param keys keys used - * @param inBuffer input byte array - * @param outBuffer output byte array - * @param mode sign mode - * @param result opera result - * @return - */ -gpg_error_t GpgME::GpgContext::sign(const QVector<GpgKey> &keys, const QByteArray &inBuffer, QByteArray *outBuffer, - gpgme_sig_mode_t mode, gpgme_sign_result_t *result, bool default_ctx) { - - gpgme_error_t gpgmeError; - gpgme_data_t dataIn, dataOut; - gpgme_sign_result_t m_result; - - auto _ctx = mCtx; - - if(!default_ctx) - _ctx = create_ctx(); - - if (keys.isEmpty()) { - QMessageBox::critical(nullptr, tr("Key Selection"), tr("No Private Key Selected")); - return false; - } - - // Set Singers of this opera - setSigners(keys, _ctx); - - gpgmeError = gpgme_data_new_from_mem(&dataIn, inBuffer.data(), inBuffer.size(), 1); - checkErr(gpgmeError); - gpgmeError = gpgme_data_new(&dataOut); - checkErr(gpgmeError); - - /** - `GPGME_SIG_MODE_NORMAL' - A normal signature is made, the output includes the plaintext - and the signature. - - `GPGME_SIG_MODE_DETACH' - A detached signature is made. - - `GPGME_SIG_MODE_CLEAR' - A clear text signature is made. The ASCII armor and text - mode settings of the context are ignored. - */ - - gpgmeError = gpgme_op_sign(_ctx, dataIn, dataOut, mode); - checkErr(gpgmeError); - - if (gpgmeError == GPG_ERR_CANCELED) return false; - - if (gpgmeError != GPG_ERR_NO_ERROR) { - QMessageBox::critical(nullptr, tr("Error in signing:"), QString::fromUtf8(gpgme_strerror(gpgmeError))); - return false; - } - - if(default_ctx) - m_result = gpgme_op_sign_result(_ctx); - else m_result = nullptr; - - if (result != nullptr) *result = m_result; - - if(!default_ctx) gpgme_release(_ctx); - - gpgmeError = readToBuffer(dataOut, outBuffer); - checkErr(gpgmeError); - - gpgme_data_release(dataIn); - gpgme_data_release(dataOut); - - // Of no use yet - if (!settings.value("general/rememberPassword").toBool()) clearPasswordCache(); - - return gpgmeError; -} - -/** - * Encrypt and sign data - * @param keys keys used - * @param inBuffer input byte array - * @param outBuffer output byte array - * @param encr_result encrypt opera result - * @param sign_result sign opera result - * @return - */ -gpgme_error_t -GpgME::GpgContext::encryptSign(QVector<GpgKey> &keys, QVector<GpgKey> &signers, const QByteArray &inBuffer, - QByteArray *outBuffer, gpgme_encrypt_result_t *encr_result, - gpgme_sign_result_t *sign_result) { - gpgme_data_t data_in = nullptr, data_out = nullptr; - outBuffer->resize(0); - - setSigners(signers, mCtx); - - //gpgme_encrypt_result_t e_result; - gpgme_key_t recipients[keys.count() + 1]; - - // set key for user - int index = 0; - for (const auto &key : keys) recipients[index++] = key.key_refer; - - // Last entry dataIn array has to be nullptr - recipients[keys.count()] = nullptr; - - // If the last parameter isnt 0, a private copy of data is made - if (mCtx != nullptr) { - err = gpgme_data_new_from_mem(&data_in, inBuffer.data(), inBuffer.size(), 1); - if (gpg_err_code(err) == GPG_ERR_NO_ERROR) { - err = gpgme_data_new(&data_out); - if (gpg_err_code(err) == GPG_ERR_NO_ERROR) { - err = gpgme_op_encrypt_sign(mCtx, recipients, GPGME_ENCRYPT_ALWAYS_TRUST, data_in, data_out); - if (encr_result != nullptr) - *encr_result = gpgme_op_encrypt_result(mCtx); - if (sign_result != nullptr) - *sign_result = gpgme_op_sign_result(mCtx); - if (gpg_err_code(err) == GPG_ERR_NO_ERROR) { - err = readToBuffer(data_out, outBuffer); - } - } - } - } - - if (gpgme_err_code(err) != GPG_ERR_NO_ERROR) checkErr(err); - - if (data_in) gpgme_data_release(data_in); - if (data_out) gpgme_data_release(data_out); - - return err; -} - -/** - * Decrypt and verify data - * @param inBuffer input byte array - * @param outBuffer output byte array - * @param decrypt_result decrypt opera result - * @param verify_result verify opera result - * @return error info - */ -gpgme_error_t GpgME::GpgContext::decryptVerify(const QByteArray &inBuffer, QByteArray *outBuffer, - gpgme_decrypt_result_t *decrypt_result, - gpgme_verify_result_t *verify_result) { - gpgme_data_t data_in = nullptr, data_out = nullptr; - - outBuffer->resize(0); - if (mCtx != nullptr) { - err = gpgme_data_new_from_mem(&data_in, inBuffer.data(), inBuffer.size(), 1); - if (gpgme_err_code(err) == GPG_ERR_NO_ERROR) { - err = gpgme_data_new(&data_out); - if (gpgme_err_code(err) == GPG_ERR_NO_ERROR) { - err = gpgme_op_decrypt_verify(mCtx, data_in, data_out); - if (decrypt_result != nullptr) - *decrypt_result = gpgme_op_decrypt_result(mCtx); - if (verify_result != nullptr) - *verify_result = gpgme_op_verify_result(mCtx); - if (gpgme_err_code(err) == GPG_ERR_NO_ERROR) { - err = readToBuffer(data_out, outBuffer); - } - } - } - } - - if (!settings.value("general/rememberPassword").toBool()) clearPasswordCache(); - - if (data_in) gpgme_data_release(data_in); - if (data_out) gpgme_data_release(data_out); - - return err; -} diff --git a/src/gpg/gpg_context/GpgContextKeyInfo.cpp b/src/gpg/gpg_context/GpgContextKeyInfo.cpp index f6942e4e..3fa6a23b 100644 --- a/src/gpg/gpg_context/GpgContextKeyInfo.cpp +++ b/src/gpg/gpg_context/GpgContextKeyInfo.cpp @@ -29,9 +29,10 @@ * @param key target key * @return if key sign */ -bool GpgME::GpgContext::checkIfKeyCanSign(const GpgKey &key) { - if (std::any_of(key.subKeys.begin(), key.subKeys.end(), [](const GpgSubKey &subkey) -> bool { - return subkey.secret && subkey.can_sign && !subkey.disabled && !subkey.revoked && !subkey.expired; +bool GpgFrontend::GpgContext::checkIfKeyCanSign(const GpgKey &key) { + auto subkeys = key.subKeys(); + if (std::any_of(subkeys->begin(), subkeys->end(), [](const GpgSubKey &subkey) -> bool { + return subkey.secret() && subkey.can_sign() && !subkey.disabled() && !subkey.revoked() && !subkey.expired(); })) return true; else return false; @@ -42,8 +43,8 @@ bool GpgME::GpgContext::checkIfKeyCanSign(const GpgKey &key) { * @param key target key * @return if key certify */ -bool GpgME::GpgContext::checkIfKeyCanCert(const GpgKey &key) { - return key.has_master_key && !key.expired && !key.revoked && !key.disabled; +bool GpgFrontend::GpgContext::checkIfKeyCanCert(const GpgKey &key) { + return key.has_master_key() && !key.expired() && !key.revoked() && !key.disabled(); } /** @@ -51,9 +52,10 @@ bool GpgME::GpgContext::checkIfKeyCanCert(const GpgKey &key) { * @param key target key * @return if key authenticate */ -bool GpgME::GpgContext::checkIfKeyCanAuth(const GpgKey &key) { - if (std::any_of(key.subKeys.begin(), key.subKeys.end(), [](const GpgSubKey &subkey) -> bool { - return subkey.secret && subkey.can_authenticate && !subkey.disabled && !subkey.revoked && !subkey.expired; +bool GpgFrontend::GpgContext::checkIfKeyCanAuth(const GpgKey &key) { + auto subkeys = key.subKeys(); + if (std::any_of(subkeys->begin(), subkeys->end(), [](const GpgSubKey &subkey) -> bool { + return subkey.secret() && subkey.can_authenticate() && !subkey.disabled() && !subkey.revoked() && !subkey.expired(); })) return true; else return false; @@ -64,47 +66,11 @@ bool GpgME::GpgContext::checkIfKeyCanAuth(const GpgKey &key) { * @param key target key * @return if key encrypt */ -bool GpgME::GpgContext::checkIfKeyCanEncr(const GpgKey &key) { - if (std::any_of(key.subKeys.begin(), key.subKeys.end(), [](const GpgSubKey &subkey) -> bool { - return subkey.can_encrypt && !subkey.disabled && !subkey.revoked && !subkey.expired; +bool GpgFrontend::GpgContext::checkIfKeyCanEncr(const GpgKey &key) { + auto subkeys = key.subKeys(); + if (std::any_of(subkeys->begin(), subkeys->end(), [](const GpgSubKey &subkey) -> bool { + return subkey.can_encrypt() && !subkey.disabled() && !subkey.revoked() && !subkey.expired(); })) return true; else return false; } - -/** - * Get target key - * @param fpr master key's fingerprint - * @return the key - */ -GpgKey GpgME::GpgContext::getKeyByFpr(const QString &fpr) { - for (const auto &key : mKeyList) { - if (key.fpr == fpr) return key; - else - for (auto &subkey : key.subKeys) { - if (subkey.fpr == fpr) return key; - } - } - return GpgKey(nullptr); -} - - -/** - * Get target key - * @param id master key's id - * @return the key - */ -GpgKey GpgME::GpgContext::getKeyById(const QString &id) { - - for (const auto &key : mKeyList) { - if (key.id == id) return key; - else { - auto sub_keys = key.subKeys; - for (const auto &subkey : sub_keys) { - if (subkey.id == id) return key; - } - } - } - - return GpgKey(nullptr); -} diff --git a/src/gpg/gpg_context/GpgContextKeyOpera.cpp b/src/gpg/gpg_context/GpgContextKeyOpera.cpp index a224231d..63b266ca 100644 --- a/src/gpg/gpg_context/GpgContextKeyOpera.cpp +++ b/src/gpg/gpg_context/GpgContextKeyOpera.cpp @@ -29,14 +29,14 @@ * @param inBuffer input byte array * @return Import information */ -GpgImportInformation GpgME::GpgContext::importKey(QByteArray inBuffer) { +GpgImportInformation GpgFrontend::GpgContext::importKey(QByteArray inBuffer) { auto *importInformation = new GpgImportInformation(); err = gpgme_data_new_from_mem(&in, inBuffer.data(), inBuffer.size(), 1); - checkErr(err); - err = gpgme_op_import(mCtx, in); + check_gpg_error(err); + err = gpgme_op_import(*this, in); gpgme_import_result_t result; - result = gpgme_op_import_result(mCtx); + result = gpgme_op_import_result(*this); if (result->unchanged) importInformation->unchanged = result->unchanged; if (result->considered) importInformation->considered = result->considered; @@ -61,7 +61,7 @@ GpgImportInformation GpgME::GpgContext::importKey(QByteArray inBuffer) { importInformation->importedKeys.emplace_back(key); status = status->next; } - checkErr(err); + check_gpg_error(err); emit signalKeyDBChanged(); gpgme_data_release(in); return *importInformation; @@ -72,7 +72,7 @@ GpgImportInformation GpgME::GpgContext::importKey(QByteArray inBuffer) { * @param params key generation args * @return error information */ -gpgme_error_t GpgME::GpgContext::generateKey(GenKeyInfo *params) { +gpgme_error_t GpgFrontend::GpgContext::generateKey(GenKeyInfo *params) { auto userid_utf8 = params->getUserid().toUtf8(); const char *userid = userid_utf8.constData(); @@ -88,10 +88,10 @@ gpgme_error_t GpgME::GpgContext::generateKey(GenKeyInfo *params) { if (params->isNonExpired()) flags |= GPGME_CREATE_NOEXPIRE; if (params->isNoPassPhrase()) flags |= GPGME_CREATE_NOPASSWD; - err = gpgme_op_createkey(mCtx, userid, algo, 0, expires, nullptr, flags); + err = gpgme_op_createkey(*this, userid, algo, 0, expires, nullptr, flags); if (gpgme_err_code(err) != GPG_ERR_NO_ERROR) { - checkErr(err); + check_gpg_error(err); return err; } else { emit signalKeyDBChanged(); @@ -105,7 +105,7 @@ gpgme_error_t GpgME::GpgContext::generateKey(GenKeyInfo *params) { * @param outBuffer output byte array * @return if success */ -bool GpgME::GpgContext::exportKeys(QStringList *uidList, QByteArray *outBuffer) { +bool GpgFrontend::GpgContext::exportKeys(QStringList *uidList, QByteArray *outBuffer) { gpgme_data_t dataOut = nullptr; outBuffer->resize(0); @@ -119,15 +119,15 @@ bool GpgME::GpgContext::exportKeys(QStringList *uidList, QByteArray *outBuffer) for (int i = 0; i < uidList->count(); i++) { err = gpgme_data_new(&dataOut); - checkErr(err); + check_gpg_error(err); err = gpgme_op_export(ctx, uidList->at(i).toUtf8().constData(), 0, dataOut); - checkErr(err); + check_gpg_error(err); - qDebug() << "exportKeys read_bytes" << gpgme_data_seek(dataOut, 0, SEEK_END); + qDebug() << "exportKeys read_bytes" << gpgme_data_seek(dataOut, 0, SEEK_END); err = readToBuffer(dataOut, outBuffer); - checkErr(err); + check_gpg_error(err); gpgme_data_release(dataOut); } @@ -139,7 +139,7 @@ bool GpgME::GpgContext::exportKeys(QStringList *uidList, QByteArray *outBuffer) /** * Get and store all key pairs info */ -void GpgME::GpgContext::fetch_keys() { +void GpgFrontend::GpgContext::fetch_keys() { gpgme_error_t gpgmeError; @@ -155,47 +155,47 @@ void GpgME::GpgContext::fetch_keys() { qDebug() << "Set Key Listing Mode"; - gpgmeError = gpgme_set_keylist_mode(mCtx, + gpgmeError = gpgme_set_keylist_mode(*this, GPGME_KEYLIST_MODE_LOCAL | GPGME_KEYLIST_MODE_WITH_SECRET | GPGME_KEYLIST_MODE_SIGS | GPGME_KEYLIST_MODE_SIG_NOTATIONS | GPGME_KEYLIST_MODE_WITH_TOFU); if (gpg_err_code(gpgmeError) != GPG_ERR_NO_ERROR) { - checkErr(gpgmeError); + check_gpg_error(gpgmeError); return; } qDebug() << "Operate KeyList Start"; - gpgmeError = gpgme_op_keylist_start(mCtx, nullptr, 0); + gpgmeError = gpgme_op_keylist_start(*this, nullptr, 0); if (gpg_err_code(gpgmeError) != GPG_ERR_NO_ERROR) { - checkErr(gpgmeError); + check_gpg_error(gpgmeError); return; } qDebug() << "Start Loop"; - while ((gpgmeError = gpgme_op_keylist_next(mCtx, &key)) == GPG_ERR_NO_ERROR) { + while ((gpgmeError = gpgme_op_keylist_next(*this, &key)) == GPG_ERR_NO_ERROR) { if (!key->subkeys) continue; qDebug() << "Append Key" << key->subkeys->keyid; - keys.emplace_back(key); - keys_map.insert(keys.back().id, &keys.back()); + keys.emplace_back(gpgme_key_t(key)); + keys_map.insert(keys.back().id(), &keys.back()); gpgme_key_unref(key); } if (gpg_err_code(gpgmeError) != GPG_ERR_EOF) { - checkErr(gpgmeError); + check_gpg_error(gpgmeError); return; } - gpgmeError = gpgme_op_keylist_end(mCtx); + gpgmeError = gpgme_op_keylist_end(*this); if (gpg_err_code(gpgmeError) != GPG_ERR_NO_ERROR) { - checkErr(gpgmeError); + check_gpg_error(gpgmeError); return; } @@ -208,34 +208,34 @@ void GpgME::GpgContext::fetch_keys() { * Delete keys * @param uidList key ids */ -void GpgME::GpgContext::deleteKeys(QStringList *uidList) { +void GpgFrontend::GpgContext::deleteKeys(QStringList *uidList) { gpgme_error_t error; gpgme_key_t key; for (const auto &tmp : *uidList) { - error = gpgme_op_keylist_start(mCtx, tmp.toUtf8().constData(), 0); + error = gpgme_op_keylist_start(*this, tmp.toUtf8().constData(), 0); if (error != GPG_ERR_NO_ERROR) { - checkErr(error); + check_gpg_error(error); continue; } - error = gpgme_op_keylist_next(mCtx, &key); + error = gpgme_op_keylist_next(*this, &key); if (error != GPG_ERR_NO_ERROR) { - checkErr(error); + check_gpg_error(error); continue; } - error = gpgme_op_keylist_end(mCtx); + error = gpgme_op_keylist_end(*this); if (error != GPG_ERR_NO_ERROR) { - checkErr(error); + check_gpg_error(error); continue; } - error = gpgme_op_delete(mCtx, key, 1); + error = gpgme_op_delete(*this, key, 1); if (error != GPG_ERR_NO_ERROR) { - checkErr(error); + check_gpg_error(error); continue; } @@ -249,7 +249,7 @@ void GpgME::GpgContext::deleteKeys(QStringList *uidList) { * @param outBuffer output byte array * @return if success */ -bool GpgME::GpgContext::exportKeys(const QVector<GpgKey> &keys, QByteArray &outBuffer) { +bool GpgFrontend::GpgContext::exportKeys(const QVector <GpgKey> &keys, QByteArray &outBuffer) { gpgme_data_t data_out = nullptr; outBuffer.resize(0); @@ -260,15 +260,15 @@ bool GpgME::GpgContext::exportKeys(const QVector<GpgKey> &keys, QByteArray &outB for (const auto &key : keys) { err = gpgme_data_new(&data_out); - checkErr(err); + check_gpg_error(err); - err = gpgme_op_export(mCtx, key.id.toUtf8().constData(), 0, data_out); - checkErr(err); + err = gpgme_op_export(*this, key.id().toUtf8().constData(), 0, data_out); + check_gpg_error(err); gpgme_data_seek(data_out, 0, SEEK_END); err = readToBuffer(data_out, &outBuffer); - checkErr(err); + check_gpg_error(err); gpgme_data_release(data_out); } @@ -282,24 +282,25 @@ bool GpgME::GpgContext::exportKeys(const QVector<GpgKey> &keys, QByteArray &outB * @param expires date and time * @return if successful */ -bool GpgME::GpgContext::setExpire(const GpgKey &key, const GpgSubKey *subkey, QDateTime *expires) { +bool GpgFrontend::GpgContext::setExpire(const GpgKey &key, std::unique_ptr <GpgSubKey> &subkey, + std::unique_ptr <QDateTime> &expires) { unsigned long expires_time = 0; if (expires != nullptr) { qDebug() << "Expire Datetime" << expires->toString(); expires_time = QDateTime::currentDateTime().secsTo(*expires); } - const char *subfprs = nullptr; + const char *sub_fprs = nullptr; - if (subkey != nullptr) subfprs = subkey->fpr.toUtf8().constData(); + if (subkey != nullptr) sub_fprs = subkey->fpr().toUtf8().constData(); - auto gpgmeError = gpgme_op_setexpire(mCtx, key.key_refer, - expires_time, subfprs, 0); + auto gpgmeError = gpgme_op_setexpire(*this, gpgme_key_t(key), + expires_time, sub_fprs, 0); if (gpgmeError == GPG_ERR_NO_ERROR) { - emit signalKeyUpdated(key.id); + emit signalKeyUpdated(key.id()); return true; } else { - checkErr(gpgmeError); + check_gpg_error(gpgmeError); return false; } } @@ -310,10 +311,10 @@ bool GpgME::GpgContext::setExpire(const GpgKey &key, const GpgSubKey *subkey, QD * @param outBuffer output byte array * @return if successful */ -bool GpgME::GpgContext::exportSecretKey(const GpgKey &key, QByteArray *outBuffer) { - qDebug() << "Export Secret Key" << key.id; +bool GpgFrontend::GpgContext::exportSecretKey(const GpgKey &key, QByteArray *outBuffer) const { + qDebug() << "Export Secret Key" << key.id(); gpgme_key_t target_key[2] = { - key.key_refer, + gpgme_key_t(key), nullptr }; @@ -321,10 +322,10 @@ bool GpgME::GpgContext::exportSecretKey(const GpgKey &key, QByteArray *outBuffer gpgme_data_new(&dataOut); // export private key to outBuffer - gpgme_error_t error = gpgme_op_export_keys(mCtx, target_key, GPGME_EXPORT_MODE_SECRET, dataOut); + gpgme_error_t error = gpgme_op_export_keys(*this, target_key, GPGME_EXPORT_MODE_SECRET, dataOut); if (gpgme_err_code(error) != GPG_ERR_NO_ERROR) { - checkErr(error); + check_gpg_error(error); gpgme_data_release(dataOut); return false; } @@ -335,42 +336,12 @@ bool GpgME::GpgContext::exportSecretKey(const GpgKey &key, QByteArray *outBuffer } /** - * Sign a key pair(actually a certain uid) - * @param target target key pair - * @param uid target - * @param expires expire date and time of the signature - * @return if successful - */ -bool GpgME::GpgContext::signKey(const GpgKey &target, const QVector<GpgKey> &keys, const QString &uid, - const QDateTime *expires) { - - setSigners(keys, mCtx); - - unsigned int flags = 0; - - unsigned int expires_time_t = 0; - if (expires == nullptr) flags |= GPGME_KEYSIGN_NOEXPIRE; - else expires_time_t = QDateTime::currentDateTime().secsTo(*expires); - - auto gpgmeError = - gpgme_op_keysign(mCtx, target.key_refer, uid.toUtf8().constData(), expires_time_t, flags); - - if (gpgmeError == GPG_ERR_NO_ERROR) { - emit signalKeyUpdated(target.id); - return true; - } else { - checkErr(gpgmeError); - return false; - } -} - -/** * Generate revoke cert of a key pair * @param key target key pair * @param outputFileName out file name(path) * @return the process doing this job */ -void GpgME::GpgContext::generateRevokeCert(const GpgKey &key, const QString &outputFileName) { +void GpgFrontend::GpgContext::generateRevokeCert(const GpgKey &key, const QString &outputFileName) { executeGpgCommand({ "--command-fd", "0", @@ -380,7 +351,7 @@ void GpgME::GpgContext::generateRevokeCert(const GpgKey &key, const QString &out "-o", outputFileName, "--gen-revoke", - key.fpr + key.fpr() }, [](QProcess *proc) -> void { qDebug() << "Function Called" << proc; diff --git a/src/gpg/gpg_context/GpgContextSubkeyOpera.cpp b/src/gpg/gpg_context/GpgContextSubkeyOpera.cpp index 10243f5e..7e73db18 100644 --- a/src/gpg/gpg_context/GpgContextSubkeyOpera.cpp +++ b/src/gpg/gpg_context/GpgContextSubkeyOpera.cpp @@ -30,7 +30,7 @@ * @param params opera args * @return error info */ -gpgme_error_t GpgME::GpgContext::generateSubkey(const GpgKey &key, GenKeyInfo *params) { +gpgme_error_t GpgFrontend::GpgContext::generateSubkey(const GpgKey &key, GenKeyInfo *params) { if (!params->isSubKey()) return GPG_ERR_CANCELED; @@ -48,13 +48,13 @@ gpgme_error_t GpgME::GpgContext::generateSubkey(const GpgKey &key, GenKeyInfo *p flags |= GPGME_CREATE_NOPASSWD; - auto gpgmeError = gpgme_op_createsubkey(mCtx, key.key_refer, + auto gpgmeError = gpgme_op_createsubkey(*this, gpgme_key_t(key), algo, 0, expires, flags); if (gpgme_err_code(gpgmeError) == GPG_ERR_NO_ERROR) { - emit signalKeyUpdated(key.id); + emit signalKeyUpdated(key.id()); return gpgmeError; } else { - checkErr(gpgmeError); + check_gpg_error(gpgmeError); return gpgmeError; } } diff --git a/src/gpg/gpg_context/GpgContextUIDOpera.cpp b/src/gpg/gpg_context/GpgContextUIDOpera.cpp deleted file mode 100644 index b96f5f8f..00000000 --- a/src/gpg/gpg_context/GpgContextUIDOpera.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/** - * 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. - * - * Foobar 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 Foobar. If not, see <https://www.gnu.org/licenses/>. - * - * The initial version of the source code is inherited from gpg4usb-team. - * Their source code version also complies with GNU General Public License. - * - * The source code version of this software was modified and released - * by Saturneric<[email protected]> starting on May 12, 2021. - * - */ - -#include "gpg/GpgContext.h" - -/** - * create a new uid in certain key pair - * @param key target key pair - * @param uid uid args - * @return if successful - */ -bool GpgME::GpgContext::addUID(const GpgKey &key, const GpgUID &uid) { - QString userid = QString("%1 (%3) <%2>").arg(uid.name, uid.email, uid.comment); - auto gpgmeError = gpgme_op_adduid(mCtx, key.key_refer, userid.toUtf8().constData(), 0); - if (gpgmeError == GPG_ERR_NO_ERROR) { - emit signalKeyUpdated(key.id); - return true; - } else { - checkErr(gpgmeError); - return false; - } - -} - -/** - * Revoke(Delete) UID from certain key pair - * @param key target key pair - * @param uid target uid - * @return if successful - */ -bool GpgME::GpgContext::revUID(const GpgKey &key, const GpgUID &uid) { - auto gpgmeError = gpgme_op_revuid(mCtx, key.key_refer, uid.uid.toUtf8().constData(), 0); - if (gpgmeError == GPG_ERR_NO_ERROR) { - emit signalKeyUpdated(key.id); - return true; - } else { - checkErr(gpgmeError); - return false; - } -} - -/** - * Set one of a uid of a key pair as primary - * @param key target key pair - * @param uid target uid - * @return if successful - */ -bool GpgME::GpgContext::setPrimaryUID(const GpgKey &key, const GpgUID &uid) { - auto gpgmeError = gpgme_op_set_uid_flag(mCtx, key.key_refer, - uid.uid.toUtf8().constData(), "primary", nullptr); - if (gpgmeError == GPG_ERR_NO_ERROR) { - emit signalKeyUpdated(key.id); - return true; - } else { - checkErr(gpgmeError); - return false; - } -} - diff --git a/src/gpg/result_analyse/DecryptResultAnalyse.cpp b/src/gpg/result_analyse/DecryptResultAnalyse.cpp index b4d0b14f..7c91e6b2 100644 --- a/src/gpg/result_analyse/DecryptResultAnalyse.cpp +++ b/src/gpg/result_analyse/DecryptResultAnalyse.cpp @@ -24,7 +24,7 @@ #include "gpg/result_analyse/DecryptResultAnalyse.h" -DecryptResultAnalyse::DecryptResultAnalyse(GpgME::GpgContext *ctx, gpgme_error_t error, gpgme_decrypt_result_t result) +DecryptResultAnalyse::DecryptResultAnalyse(GpgFrontend::GpgContext *ctx, gpgme_error_t error, gpgme_decrypt_result_t result) : mCtx(ctx) { stream << tr("[#] Decrypt Operation "); @@ -65,7 +65,7 @@ bool DecryptResultAnalyse::printReci(QTextStream &stream, gpgme_recipient_t reci bool keyFound = true; stream << QApplication::tr(" {>} Recipient: "); - auto key = mCtx->getKeyById(reci->keyid); + auto key = mCtx->getKeyRefById(reci->keyid); if(key.good) { stream << key.name; if (!key.email.isEmpty()) { diff --git a/src/gpg/result_analyse/SignResultAnalyse.cpp b/src/gpg/result_analyse/SignResultAnalyse.cpp index 10d76678..efbbb4db 100644 --- a/src/gpg/result_analyse/SignResultAnalyse.cpp +++ b/src/gpg/result_analyse/SignResultAnalyse.cpp @@ -24,7 +24,7 @@ #include "gpg/result_analyse/SignResultAnalyse.h" -SignResultAnalyse::SignResultAnalyse(GpgME::GpgContext *ctx, gpgme_error_t error, gpgme_sign_result_t result) { +SignResultAnalyse::SignResultAnalyse(GpgFrontend::GpgContext *ctx, gpgme_error_t error, gpgme_sign_result_t result) { qDebug() << "Start Sign Result Analyse"; @@ -58,7 +58,7 @@ SignResultAnalyse::SignResultAnalyse(GpgME::GpgContext *ctx, gpgme_error_t error stream << Qt::endl; - GpgKey singerKey = ctx->getKeyByFpr(new_sign->fpr); + GpgKey singerKey = ctx->getKeyRefByFpr(new_sign->fpr); if(singerKey.good) { stream << tr(" Signer: ") << singerKey.uids.first().uid << Qt::endl; } else { diff --git a/src/gpg/result_analyse/VerifyResultAnalyse.cpp b/src/gpg/result_analyse/VerifyResultAnalyse.cpp index 75e07d33..a2c69d2e 100644 --- a/src/gpg/result_analyse/VerifyResultAnalyse.cpp +++ b/src/gpg/result_analyse/VerifyResultAnalyse.cpp @@ -25,7 +25,7 @@ #include "GpgFrontend.h" #include "gpg/result_analyse/VerifyResultAnalyse.h" -VerifyResultAnalyse::VerifyResultAnalyse(GpgME::GpgContext *ctx, gpgme_error_t error, gpgme_verify_result_t result) +VerifyResultAnalyse::VerifyResultAnalyse(GpgFrontend::GpgContext *ctx, gpgme_error_t error, gpgme_verify_result_t result) : mCtx(ctx) { qDebug() << "Verify Result Analyse Started"; @@ -137,7 +137,7 @@ VerifyResultAnalyse::VerifyResultAnalyse(GpgME::GpgContext *ctx, gpgme_error_t e break; default: stream << QApplication::tr("Error for key with fingerprint ") << - GpgME::GpgContext::beautifyFingerprint(QString(sign->fpr)); + GpgFrontend::GpgContext::beautifyFingerprint(QString(sign->fpr)); setStatus(-1); } stream << Qt::endl; @@ -149,9 +149,7 @@ VerifyResultAnalyse::VerifyResultAnalyse(GpgME::GpgContext *ctx, gpgme_error_t e bool VerifyResultAnalyse::printSigner(QTextStream &stream, gpgme_signature_t sign) { bool keyFound = true; - auto key = mCtx->getKeyByFpr(sign->fpr); - - key = mCtx->getKeyByFpr(sign->fpr); + auto key = mCtx->getKeyRefByFpr(sign->fpr); if (!key.good) { stream << tr(" Signed By: ") << tr("<unknown>") << Qt::endl; diff --git a/src/main.cpp b/src/main.cpp index 1e54d6e7..831a6121 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -86,6 +86,24 @@ int main(int argc, char *argv[]) { QApplication::setQuitOnLastWindowClosed(true); + + /** + * The function `gpgme_check_version' must be called before any other + * function in the library, because it initializes the thread support + * subsystem in GPGME. (from the info page) */ + gpgme_check_version(nullptr); + + // the locale set here is used for the other setlocale calls which have nullptr + // -> nullptr means use default, which is configured here + setlocale(LC_ALL, settings.value("int/lang").toLocale().name().toUtf8().constData()); + + /** set locale, because tests do also */ + gpgme_set_locale(nullptr, LC_CTYPE, setlocale(LC_CTYPE, nullptr)); + //qDebug() << "Locale set to" << LC_CTYPE << " - " << setlocale(LC_CTYPE, nullptr); + #ifndef _WIN32 + gpgme_set_locale(nullptr, LC_MESSAGES, setlocale(LC_MESSAGES, nullptr)); + #endif + MainWindow window; return_from_event_loop_code = QApplication::exec(); diff --git a/src/server/ComUtils.cpp b/src/server/ComUtils.cpp index 01be4ea7..bbcc873c 100644 --- a/src/server/ComUtils.cpp +++ b/src/server/ComUtils.cpp @@ -29,7 +29,7 @@ * @param reply reply data in byte array * @return if successful */ -bool ComUtils::checkServerReply(const QByteArray &reply) { +bool GpgFrontend::ComUtils::checkServerReply(const QByteArray &reply) { if(reply.isEmpty()) { QMessageBox::critical(this, tr("Error"), tr("Nothing Reply. Please check the Internet connection.")); @@ -97,7 +97,7 @@ bool ComUtils::checkServerReply(const QByteArray &reply) { * @param key key of value * @return value in string format */ -QString ComUtils::getDataValueStr(const QString &key) const { +QString GpgFrontend::ComUtils::getDataValueStr(const QString &key) const { if (is_good) { auto k_byte_array = key.toUtf8(); if (dataVal.HasMember(k_byte_array.data())) { @@ -111,7 +111,7 @@ QString ComUtils::getDataValueStr(const QString &key) const { * @param type service which server provides * @return url */ -QString ComUtils::getUrl(ComUtils::ServiceType type) const { +QString GpgFrontend::ComUtils::getUrl(ComUtils::ServiceType type) const { auto host = settings.value("general/currentGpgfrontendServer", "service.gpgfrontend.pub").toString(); @@ -145,19 +145,19 @@ QString ComUtils::getUrl(ComUtils::ServiceType type) const { return url; } -bool ComUtils::checkDataValueStr(const QString &key) const { +bool GpgFrontend::ComUtils::checkDataValueStr(const QString &key) const { auto key_byte_array_data = key.toUtf8().constData(); if (is_good) { return dataVal.HasMember(key_byte_array_data) && dataVal[key_byte_array_data].IsString(); } else return false; } -bool ComUtils::checkServiceTokenFormat(const QString &uuid) const { +bool GpgFrontend::ComUtils::checkServiceTokenFormat(const QString &uuid) const { return re_uuid.match(uuid).hasMatch(); } -QByteArray ComUtils::getSignStringBase64(GpgME::GpgContext *ctx, const QString &str, const GpgKey &key) { - QVector<GpgKey> keys{key}; +QByteArray GpgFrontend::ComUtils::getSignStringBase64(GpgFrontend::GpgContext *ctx, const QString &str, const GpgKey &key) { + std::vector<GpgKey> keys{key}; QByteArray outSignText; auto signData = str.toUtf8(); @@ -173,7 +173,7 @@ QByteArray ComUtils::getSignStringBase64(GpgME::GpgContext *ctx, const QString & return outSignText.toBase64(); } -const rapidjson::Value &ComUtils::getDataValue(const QString &key) const { +const rapidjson::Value &GpgFrontend::ComUtils::getDataValue(const QString &key) const { if (is_good) { auto k_byte_array = key.toUtf8(); if (dataVal.HasMember(k_byte_array.data())) { @@ -183,14 +183,14 @@ const rapidjson::Value &ComUtils::getDataValue(const QString &key) const { throw std::runtime_error("Inner Error"); } -bool ComUtils::checkDataValue(const QString &key) const{ +bool GpgFrontend::ComUtils::checkDataValue(const QString &key) const{ auto key_byte_array_data = key.toUtf8().constData(); if (is_good) { return dataVal.HasMember(key_byte_array_data); } else return false; } -void ComUtils::clear() { +void GpgFrontend::ComUtils::clear() { this->dataVal.Clear(); this->replyDoc.Clear(); is_good = false; diff --git a/src/server/api/PubkeyGetter.cpp b/src/server/api/PubkeyGetter.cpp index 2ba55d11..6505cb3e 100644 --- a/src/server/api/PubkeyGetter.cpp +++ b/src/server/api/PubkeyGetter.cpp @@ -24,7 +24,7 @@ #include "server/api/PubkeyGetter.h" -PubkeyGetter::PubkeyGetter(GpgME::GpgContext *ctx, const QVector<QString> &fprs) : BaseAPI(ComUtils::GetPubkey), +PubkeyGetter::PubkeyGetter(GpgFrontend::GpgContext *ctx, const QVector<QString> &fprs) : BaseAPI(ComUtils::GetPubkey), mCtx(ctx), mFprs(fprs) { } diff --git a/src/server/api/PubkeyUploader.cpp b/src/server/api/PubkeyUploader.cpp index c6101c65..2842c2d7 100644 --- a/src/server/api/PubkeyUploader.cpp +++ b/src/server/api/PubkeyUploader.cpp @@ -24,7 +24,7 @@ #include "server/api/PubkeyUploader.h" -PubkeyUploader::PubkeyUploader(GpgME::GpgContext *ctx, const QVector<GpgKey> &keys) : BaseAPI(ComUtils::UploadPubkey), +PubkeyUploader::PubkeyUploader(GpgFrontend::GpgContext *ctx, const QVector<GpgKey> &keys) : BaseAPI(ComUtils::UploadPubkey), mCtx(ctx), mKeys(keys) { } diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index b6552227..170e7454 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -9,6 +9,4 @@ aux_source_directory(./settings UI_SOURCE) add_library(gpgfrontend-ui STATIC ${UI_SOURCE}) target_link_libraries(gpgfrontend-ui - Qt5::Network Qt5::PrintSupport Qt5::Widgets Qt5::Test Qt5::Core) - -message(STATUS "UI SOURCE ${UI_SOURCE}")
\ No newline at end of file + Qt5::Network Qt5::PrintSupport Qt5::Widgets Qt5::Test Qt5::Core)
\ No newline at end of file diff --git a/src/ui/FileEncryptionDialog.cpp b/src/ui/FileEncryptionDialog.cpp index 23ec0b2a..55c8e5f0 100755 --- a/src/ui/FileEncryptionDialog.cpp +++ b/src/ui/FileEncryptionDialog.cpp @@ -24,7 +24,7 @@ #include "ui/FileEncryptionDialog.h" -FileEncryptionDialog::FileEncryptionDialog(GpgME::GpgContext *ctx, QStringList keyList, DialogAction action, +FileEncryptionDialog::FileEncryptionDialog(GpgFrontend::GpgContext *ctx, QStringList keyList, DialogAction action, QWidget *parent) : QDialog(parent), mAction(action), mCtx(ctx){ @@ -92,13 +92,13 @@ FileEncryptionDialog::FileEncryptionDialog(GpgME::GpgContext *ctx, QStringList k if(mAction == Encrypt) mKeyList->setFilter([](const GpgKey &key) -> bool { - if(!GpgME::GpgContext::checkIfKeyCanEncr(key)) return false; + if(!GpgFrontend::GpgContext::checkIfKeyCanEncr(key)) return false; else return true; }); if(mAction == Sign) mKeyList->setFilter([](const GpgKey &key) -> bool { - if(!GpgME::GpgContext::checkIfKeyCanSign(key)) return false; + if(!GpgFrontend::GpgContext::checkIfKeyCanSign(key)) return false; else return true; }); diff --git a/src/ui/KeyImportDetailDialog.cpp b/src/ui/KeyImportDetailDialog.cpp index 8d303886..8614051b 100644 --- a/src/ui/KeyImportDetailDialog.cpp +++ b/src/ui/KeyImportDetailDialog.cpp @@ -24,7 +24,7 @@ #include <ui/KeyImportDetailDialog.h> -KeyImportDetailDialog::KeyImportDetailDialog(GpgME::GpgContext *ctx, GpgImportInformation result, bool automatic, +KeyImportDetailDialog::KeyImportDetailDialog(GpgFrontend::GpgContext *ctx, GpgImportInformation result, bool automatic, QWidget *parent) : QDialog(parent), mCtx(ctx), mResult(std::move(result)) { @@ -115,7 +115,7 @@ void KeyImportDetailDialog::createKeysTable() { int row = 0; for (const auto &impKey : mResult.importedKeys) { keysTable->setRowCount(row + 1); - GpgKey key = mCtx->getKeyByFpr(impKey.fpr); + GpgKey key = mCtx->getKeyRefByFpr(impKey.fpr); if(!key.good) continue; keysTable->setItem(row, 0, new QTableWidgetItem(key.name)); keysTable->setItem(row, 1, new QTableWidgetItem(key.email)); diff --git a/src/ui/KeyMgmt.cpp b/src/ui/KeyMgmt.cpp index 77f3b760..9f3665d3 100755 --- a/src/ui/KeyMgmt.cpp +++ b/src/ui/KeyMgmt.cpp @@ -26,7 +26,7 @@ #include <utility> -KeyMgmt::KeyMgmt(GpgME::GpgContext *ctx, QWidget *parent) : +KeyMgmt::KeyMgmt(GpgFrontend::GpgContext *ctx, QWidget *parent) : QMainWindow(parent), appPath(qApp->applicationDirPath()), settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini", QSettings::IniFormat) { mCtx = ctx; @@ -251,7 +251,7 @@ void KeyMgmt::deleteKeysWithWarning(QStringList *uidList) { } QString keynames; for (const auto &uid : *uidList) { - auto key = mCtx->getKeyById(uid); + auto key = mCtx->getKeyRefById(uid); if (!key.good) continue; keynames.append(key.name); keynames.append("<i> <"); @@ -275,7 +275,7 @@ void KeyMgmt::slotShowKeyDetails() { return; } - auto key = mCtx->getKeyById(mKeyList->getSelected()->first()); + auto key = mCtx->getKeyRefById(mKeyList->getSelected()->first()); if (!key.good) { QMessageBox::critical(nullptr, tr("Error"), tr("Key Not Found.")); @@ -291,7 +291,7 @@ void KeyMgmt::slotExportKeyToFile() { delete keyArray; return; } - auto key = mCtx->getKeyById(mKeyList->getSelected()->first()); + auto key = mCtx->getKeyRefById(mKeyList->getSelected()->first()); if (!key.good) { QMessageBox::critical(nullptr, tr("Error"), tr("Key Not Found.")); return; @@ -339,7 +339,7 @@ void KeyMgmt::slotGenerateSubKey() { tr("Please select one KeyPair before doing this operation.")); return; } - const auto key = mCtx->getKeyById(selectedList->first()); + const auto key = mCtx->getKeyRefById(selectedList->first()); if (!key.good) { QMessageBox::critical(nullptr, tr("Error"), tr("Key Not Found.")); return; diff --git a/src/ui/KeyServerImportDialog.cpp b/src/ui/KeyServerImportDialog.cpp index a1355120..4343eb79 100644 --- a/src/ui/KeyServerImportDialog.cpp +++ b/src/ui/KeyServerImportDialog.cpp @@ -26,7 +26,7 @@ #include <utility> -KeyServerImportDialog::KeyServerImportDialog(GpgME::GpgContext *ctx, KeyList *keyList, bool automatic, +KeyServerImportDialog::KeyServerImportDialog(GpgFrontend::GpgContext *ctx, KeyList *keyList, bool automatic, QWidget *parent) : QDialog(parent), appPath(qApp->applicationDirPath()), settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini", QSettings::IniFormat), @@ -437,7 +437,7 @@ void KeyServerImportDialog::setLoading(bool status) { } } -KeyServerImportDialog::KeyServerImportDialog(GpgME::GpgContext *ctx, QWidget *parent) +KeyServerImportDialog::KeyServerImportDialog(GpgFrontend::GpgContext *ctx, QWidget *parent) : QDialog(parent), appPath(qApp->applicationDirPath()), settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini", QSettings::IniFormat), mCtx(ctx), mAutomatic(true) { diff --git a/src/ui/KeyUploadDialog.cpp b/src/ui/KeyUploadDialog.cpp index ab38569f..321441b7 100644 --- a/src/ui/KeyUploadDialog.cpp +++ b/src/ui/KeyUploadDialog.cpp @@ -24,7 +24,7 @@ #include "ui/KeyUploadDialog.h" -KeyUploadDialog::KeyUploadDialog(GpgME::GpgContext *ctx, const QVector<GpgKey> &keys, QWidget *parent) +KeyUploadDialog::KeyUploadDialog(GpgFrontend::GpgContext *ctx, const QVector<GpgKey> &keys, QWidget *parent) : appPath(qApp->applicationDirPath()), settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini", QSettings::IniFormat), mCtx(ctx), diff --git a/src/ui/VerifyDetailsDialog.cpp b/src/ui/VerifyDetailsDialog.cpp index 641c09e9..3462ad69 100644 --- a/src/ui/VerifyDetailsDialog.cpp +++ b/src/ui/VerifyDetailsDialog.cpp @@ -24,7 +24,7 @@ #include "ui/VerifyDetailsDialog.h" -VerifyDetailsDialog::VerifyDetailsDialog(QWidget *parent, GpgME::GpgContext *ctx, KeyList *keyList, gpg_error_t error, +VerifyDetailsDialog::VerifyDetailsDialog(QWidget *parent, GpgFrontend::GpgContext *ctx, KeyList *keyList, gpg_error_t error, gpgme_verify_result_t result) : QDialog(parent), mCtx(ctx), mKeyList(keyList), sign(result->signatures), error(error) { diff --git a/src/ui/Wizard.cpp b/src/ui/Wizard.cpp index 8b482675..4c7b8d7c 100644 --- a/src/ui/Wizard.cpp +++ b/src/ui/Wizard.cpp @@ -24,7 +24,7 @@ #include "ui/Wizard.h" -Wizard::Wizard(GpgME::GpgContext *ctx, KeyMgmt *keyMgmt, QWidget *parent) +Wizard::Wizard(GpgFrontend::GpgContext *ctx, KeyMgmt *keyMgmt, QWidget *parent) : QWizard(parent), appPath(qApp->applicationDirPath()), settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini", QSettings::IniFormat) { mCtx = ctx; @@ -177,7 +177,7 @@ void ChoosePage::slotJumpPage(const QString &page) { wizard()->next(); } -KeyGenPage::KeyGenPage(GpgME::GpgContext *ctx, QWidget *parent) +KeyGenPage::KeyGenPage(GpgFrontend::GpgContext *ctx, QWidget *parent) : QWizardPage(parent) { mCtx = ctx; setTitle(tr("Create a keypair...")); diff --git a/src/ui/help/AboutDialog.cpp b/src/ui/help/AboutDialog.cpp index e5798541..deb6a3bc 100644 --- a/src/ui/help/AboutDialog.cpp +++ b/src/ui/help/AboutDialog.cpp @@ -82,7 +82,7 @@ InfoTab::InfoTab(QWidget *parent) "If you have any questions or suggestions, raise an issue<br/>" "at <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>.") + tr("<br><br> Built with Qt ") + qVersion() - + tr(" and GPGME ") + GpgME::GpgContext::getGpgmeVersion() + + + tr(" and GPGME ") + GpgFrontend::GpgContext::getGpgmeVersion() + tr("<br>Built at ") + BUILD_TIMESTAMP + "</center>"); auto *layout = new QGridLayout(); diff --git a/src/ui/keygen/KeygenDialog.cpp b/src/ui/keygen/KeygenDialog.cpp index 98216dc6..958f9ecc 100644 --- a/src/ui/keygen/KeygenDialog.cpp +++ b/src/ui/keygen/KeygenDialog.cpp @@ -25,7 +25,7 @@ #include "ui/keygen/KeygenDialog.h" #include "ui/WaitingDialog.h" -KeyGenDialog::KeyGenDialog(GpgME::GpgContext *ctx, QWidget *parent) +KeyGenDialog::KeyGenDialog(GpgFrontend::GpgContext *ctx, QWidget *parent) : QDialog(parent), mCtx(ctx) { buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); diff --git a/src/ui/keygen/SubkeyGenerateDialog.cpp b/src/ui/keygen/SubkeyGenerateDialog.cpp index 3d709d81..8e5d01a3 100644 --- a/src/ui/keygen/SubkeyGenerateDialog.cpp +++ b/src/ui/keygen/SubkeyGenerateDialog.cpp @@ -25,7 +25,7 @@ #include "ui/keygen/SubkeyGenerateDialog.h" #include "ui/WaitingDialog.h" -SubkeyGenerateDialog::SubkeyGenerateDialog(GpgME::GpgContext *ctx, const GpgKey &key, QWidget *parent) +SubkeyGenerateDialog::SubkeyGenerateDialog(GpgFrontend::GpgContext *ctx, const GpgKey &key, QWidget *parent) : genKeyInfo(true), mCtx(ctx), mKey(key), QDialog(parent) { buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); diff --git a/src/ui/keypair_details/KeyDetailsDialog.cpp b/src/ui/keypair_details/KeyDetailsDialog.cpp index c80374d4..0d94e584 100644 --- a/src/ui/keypair_details/KeyDetailsDialog.cpp +++ b/src/ui/keypair_details/KeyDetailsDialog.cpp @@ -24,7 +24,7 @@ #include "ui/keypair_details/KeyDetailsDialog.h" -KeyDetailsDialog::KeyDetailsDialog(GpgME::GpgContext *ctx, const GpgKey& key, QWidget *parent) +KeyDetailsDialog::KeyDetailsDialog(GpgFrontend::GpgContext *ctx, const GpgKey& key, QWidget *parent) : QDialog(parent) { tabWidget = new QTabWidget(); diff --git a/src/ui/keypair_details/KeyNewUIDDialog.cpp b/src/ui/keypair_details/KeyNewUIDDialog.cpp index e12af750..7c6e1ca5 100644 --- a/src/ui/keypair_details/KeyNewUIDDialog.cpp +++ b/src/ui/keypair_details/KeyNewUIDDialog.cpp @@ -24,7 +24,7 @@ #include "ui/keypair_details/KeyNewUIDDialog.h" -KeyNewUIDDialog::KeyNewUIDDialog(GpgME::GpgContext *ctx, const GpgKey &key, QWidget *parent) : +KeyNewUIDDialog::KeyNewUIDDialog(GpgFrontend::GpgContext *ctx, const GpgKey &key, QWidget *parent) : mCtx(ctx), mKey(key), QDialog(parent) { name = new QLineEdit(); diff --git a/src/ui/keypair_details/KeyPairDetailTab.cpp b/src/ui/keypair_details/KeyPairDetailTab.cpp index c0a2df99..1f5d4095 100644 --- a/src/ui/keypair_details/KeyPairDetailTab.cpp +++ b/src/ui/keypair_details/KeyPairDetailTab.cpp @@ -25,7 +25,7 @@ #include "ui/keypair_details/KeyPairDetailTab.h" #include "ui/WaitingDialog.h" -KeyPairDetailTab::KeyPairDetailTab(GpgME::GpgContext *ctx, const GpgKey &mKey, QWidget *parent) : mKey(mKey), +KeyPairDetailTab::KeyPairDetailTab(GpgFrontend::GpgContext *ctx, const GpgKey &mKey, QWidget *parent) : mKey(mKey), QWidget(parent) { mCtx = ctx; @@ -214,7 +214,7 @@ void KeyPairDetailTab::slotExportPrivateKey() { return; } - auto key = mCtx->getKeyById(*keyid); + auto key = mCtx->getKeyRefById(*keyid); if (!key.good) { QMessageBox::critical(nullptr, tr("Error"), tr("Key Not Found.")); return; @@ -279,13 +279,13 @@ void KeyPairDetailTab::slotRefreshKeyInfo() { QString actualUsage; QTextStream actual_usage_steam(&actualUsage); - if (GpgME::GpgContext::checkIfKeyCanCert(mKey)) + if (GpgFrontend::GpgContext::checkIfKeyCanCert(mKey)) actual_usage_steam << "Cert "; - if (GpgME::GpgContext::checkIfKeyCanEncr(mKey)) + if (GpgFrontend::GpgContext::checkIfKeyCanEncr(mKey)) actual_usage_steam << "Encr "; - if (GpgME::GpgContext::checkIfKeyCanSign(mKey)) + if (GpgFrontend::GpgContext::checkIfKeyCanSign(mKey)) actual_usage_steam << "Sign "; - if (GpgME::GpgContext::checkIfKeyCanAuth(mKey)) + if (GpgFrontend::GpgContext::checkIfKeyCanAuth(mKey)) actual_usage_steam << "Auth "; actualUsageVarLabel->setText(actualUsage); diff --git a/src/ui/keypair_details/KeyPairSubkeyTab.cpp b/src/ui/keypair_details/KeyPairSubkeyTab.cpp index 6a924394..e2714303 100644 --- a/src/ui/keypair_details/KeyPairSubkeyTab.cpp +++ b/src/ui/keypair_details/KeyPairSubkeyTab.cpp @@ -24,7 +24,7 @@ #include "ui/keypair_details/KeyPairSubkeyTab.h" -KeyPairSubkeyTab::KeyPairSubkeyTab(GpgME::GpgContext *ctx, const GpgKey &key, QWidget *parent) : mCtx(ctx), mKey(key), QWidget(parent) { +KeyPairSubkeyTab::KeyPairSubkeyTab(GpgFrontend::GpgContext *ctx, const GpgKey &key, QWidget *parent) : mCtx(ctx), mKey(key), QWidget(parent) { createSubkeyList(); createSubkeyOperaMenu(); diff --git a/src/ui/keypair_details/KeyPairUIDTab.cpp b/src/ui/keypair_details/KeyPairUIDTab.cpp index 2954aadb..fed500a4 100644 --- a/src/ui/keypair_details/KeyPairUIDTab.cpp +++ b/src/ui/keypair_details/KeyPairUIDTab.cpp @@ -24,7 +24,7 @@ #include "ui/keypair_details/KeyPairUIDTab.h" -KeyPairUIDTab::KeyPairUIDTab(GpgME::GpgContext *ctx, const GpgKey &key, QWidget *parent) : QWidget(parent), mKey(key) { +KeyPairUIDTab::KeyPairUIDTab(GpgFrontend::GpgContext *ctx, const GpgKey &key, QWidget *parent) : QWidget(parent), mKey(key) { mCtx = ctx; diff --git a/src/ui/keypair_details/KeySetExpireDateDialog.cpp b/src/ui/keypair_details/KeySetExpireDateDialog.cpp index f76fa3ab..da4f63cf 100644 --- a/src/ui/keypair_details/KeySetExpireDateDialog.cpp +++ b/src/ui/keypair_details/KeySetExpireDateDialog.cpp @@ -24,7 +24,7 @@ #include "ui/keypair_details/KeySetExpireDateDialog.h" -KeySetExpireDateDialog::KeySetExpireDateDialog(GpgME::GpgContext *ctx, const GpgKey &key, const GpgSubKey *subkey, QWidget *parent) : +KeySetExpireDateDialog::KeySetExpireDateDialog(GpgFrontend::GpgContext *ctx, const GpgKey &key, const GpgSubKey *subkey, QWidget *parent) : QDialog(parent), mKey(key), mSubkey(subkey), mCtx(ctx) { QDateTime maxDateTime = QDateTime::currentDateTime().addYears(2); diff --git a/src/ui/keypair_details/KeyUIDSignDialog.cpp b/src/ui/keypair_details/KeyUIDSignDialog.cpp index 9232cfce..90b2033c 100644 --- a/src/ui/keypair_details/KeyUIDSignDialog.cpp +++ b/src/ui/keypair_details/KeyUIDSignDialog.cpp @@ -24,7 +24,7 @@ #include "ui/keypair_details/KeyUIDSignDialog.h" -KeyUIDSignDialog::KeyUIDSignDialog(GpgME::GpgContext *ctx, const GpgKey &key, const QVector<GpgUID> &uid, QWidget *parent) : +KeyUIDSignDialog::KeyUIDSignDialog(GpgFrontend::GpgContext *ctx, const GpgKey &key, const QVector<GpgUID> &uid, QWidget *parent) : mKey(key), mCtx(ctx), mUids(uid), QDialog(parent) { mKeyList = new KeyList(ctx, diff --git a/src/ui/main_window/MainWindowFileSlotFunction.cpp b/src/ui/main_window/MainWindowFileSlotFunction.cpp index e391c666..eff84fcf 100644 --- a/src/ui/main_window/MainWindowFileSlotFunction.cpp +++ b/src/ui/main_window/MainWindowFileSlotFunction.cpp @@ -64,7 +64,7 @@ void MainWindow::slotFileEncrypt() { } for (const auto &key : keys) { - if (!GpgME::GpgContext::checkIfKeyCanEncr(key)) { + if (!GpgFrontend::GpgContext::checkIfKeyCanEncr(key)) { QMessageBox::information(this, tr("Invalid Operation"), tr("The selected key contains a key that does not actually have a encrypt usage.<br/>") @@ -241,7 +241,7 @@ void MainWindow::slotFileSign() { } for (const auto &key : keys) { - if (!GpgME::GpgContext::checkIfKeyCanEncr(key)) { + if (!GpgFrontend::GpgContext::checkIfKeyCanEncr(key)) { QMessageBox::information(this, tr("Invalid Operation"), tr("The selected key contains a key that does not actually have a encrypt usage.<br/>") @@ -426,8 +426,8 @@ void MainWindow::slotFileEncryptSign() { bool can_sign = false, can_encr = false; for (const auto &key : keys) { - bool key_can_sign = GpgME::GpgContext::checkIfKeyCanSign(key); - bool key_can_encr = GpgME::GpgContext::checkIfKeyCanEncr(key); + bool key_can_sign = GpgFrontend::GpgContext::checkIfKeyCanSign(key); + bool key_can_encr = GpgFrontend::GpgContext::checkIfKeyCanEncr(key); if (!key_can_sign && !key_can_encr) { QMessageBox::critical(nullptr, diff --git a/src/ui/main_window/MainWindowServerSlotFunction.cpp b/src/ui/main_window/MainWindowServerSlotFunction.cpp index 3a7e9f71..dbbf178a 100644 --- a/src/ui/main_window/MainWindowServerSlotFunction.cpp +++ b/src/ui/main_window/MainWindowServerSlotFunction.cpp @@ -38,7 +38,7 @@ QString MainWindow::getCryptText(const QString &shortenCryptoText) { QString ownKeyId = settings.value("general/ownKeyId").toString(); - GpgKey key = mCtx->getKeyById(ownKeyId); + GpgKey key = mCtx->getKeyRefById(ownKeyId); if (!key.good) { QMessageBox::critical(this, tr("Invalid Own Key"), tr("Own Key can not be use to do any operation. " @@ -149,7 +149,7 @@ void MainWindow::shortenCryptText() { QNetworkRequest request(reqUrl); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); - GpgKey key = mCtx->getKeyById(ownKeyId); + GpgKey key = mCtx->getKeyRefById(ownKeyId); if (!key.good) { QMessageBox::critical(this, tr("Invalid Own Key"), tr("Own Key can not be use to do any operation.")); return; diff --git a/src/ui/main_window/MainWindowSlotFunction.cpp b/src/ui/main_window/MainWindowSlotFunction.cpp index 501418d6..347cf412 100644 --- a/src/ui/main_window/MainWindowSlotFunction.cpp +++ b/src/ui/main_window/MainWindowSlotFunction.cpp @@ -47,7 +47,7 @@ void MainWindow::slotEncrypt() { } for (const auto &key : keys) { - if (!GpgME::GpgContext::checkIfKeyCanEncr(key)) { + if (!GpgFrontend::GpgContext::checkIfKeyCanEncr(key)) { QMessageBox::information(nullptr, tr("Invalid Operation"), tr("The selected key contains a key that does not actually have a encrypt usage.<br/>") @@ -127,7 +127,7 @@ void MainWindow::slotSign() { } for (const auto &key : keys) { - if (!GpgME::GpgContext::checkIfKeyCanSign(key)) { + if (!GpgFrontend::GpgContext::checkIfKeyCanSign(key)) { QMessageBox::information(this, tr("Invalid Operation"), tr("The selected key contains a key that does not actually have a signature usage.<br/>") @@ -179,7 +179,7 @@ void MainWindow::slotDecrypt() { auto decrypted = QByteArray(); QByteArray text = edit->curTextPage()->toPlainText().toUtf8(); - GpgME::GpgContext::preventNoDataErr(&text); + GpgFrontend::GpgContext::preventNoDataErr(&text); if (text.trimmed().startsWith(GpgConstants::GPG_FRONTEND_SHORT_CRYPTO_HEAD)) { QMessageBox::critical(this, tr("Notice"), tr("Short Crypto Text only supports Decrypt & Verify.")); @@ -244,7 +244,7 @@ void MainWindow::slotVerify() { if (edit->slotCurPageTextEdit() != nullptr) { QByteArray text = edit->curTextPage()->toPlainText().toUtf8(); - GpgME::GpgContext::preventNoDataErr(&text); + GpgFrontend::GpgContext::preventNoDataErr(&text); gpgme_verify_result_t result; @@ -298,7 +298,7 @@ void MainWindow::slotEncryptSign() { } for (const auto &key : keys) { - bool key_can_encr = GpgME::GpgContext::checkIfKeyCanEncr(key); + bool key_can_encr = GpgFrontend::GpgContext::checkIfKeyCanEncr(key); if (!key_can_encr) { QMessageBox::critical(nullptr, @@ -432,7 +432,7 @@ void MainWindow::slotDecryptVerify() { QByteArray text = plainText.toUtf8(); - GpgME::GpgContext::preventNoDataErr(&text); + GpgFrontend::GpgContext::preventNoDataErr(&text); gpgme_decrypt_result_t d_result = nullptr; gpgme_verify_result_t v_result = nullptr; @@ -516,7 +516,7 @@ void MainWindow::slotCopyMailAddressToClipboard() { if (mKeyList->getSelected()->isEmpty()) { return; } - auto key = mCtx->getKeyById(mKeyList->getSelected()->first()); + auto key = mCtx->getKeyRefById(mKeyList->getSelected()->first()); if (!key.good) { QMessageBox::critical(nullptr, tr("Error"), tr("Key Not Found.")); return; @@ -530,7 +530,7 @@ void MainWindow::slotShowKeyDetails() { if (mKeyList->getSelected()->isEmpty()) { return; } - auto key = mCtx->getKeyById(mKeyList->getSelected()->first()); + auto key = mCtx->getKeyRefById(mKeyList->getSelected()->first()); if (key.good) { new KeyDetailsDialog(mCtx, key, this); } else { diff --git a/src/ui/settings/SettingsDialog.cpp b/src/ui/settings/SettingsDialog.cpp index 0ca188f7..33595b25 100644 --- a/src/ui/settings/SettingsDialog.cpp +++ b/src/ui/settings/SettingsDialog.cpp @@ -25,7 +25,7 @@ #include "ui/SettingsDialog.h" #include "ui/WaitingDialog.h" -SettingsDialog::SettingsDialog(GpgME::GpgContext *ctx, QWidget *parent) +SettingsDialog::SettingsDialog(GpgFrontend::GpgContext *ctx, QWidget *parent) : QDialog(parent) { mCtx = ctx; tabWidget = new QTabWidget; diff --git a/src/ui/settings/SettingsGeneral.cpp b/src/ui/settings/SettingsGeneral.cpp index bec66154..666556a0 100644 --- a/src/ui/settings/SettingsGeneral.cpp +++ b/src/ui/settings/SettingsGeneral.cpp @@ -28,7 +28,7 @@ #include "rapidjson/prettywriter.h" -GeneralTab::GeneralTab(GpgME::GpgContext *ctx, QWidget *parent) +GeneralTab::GeneralTab(GpgFrontend::GpgContext *ctx, QWidget *parent) : QWidget(parent), appPath(qApp->applicationDirPath()), settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini", QSettings::IniFormat) { @@ -104,7 +104,7 @@ GeneralTab::GeneralTab(GpgME::GpgContext *ctx, QWidget *parent) keyIds.insert("", tr("<none>")); for (const auto &keyid : *mKeyList->getAllPrivateKeys()) { - auto key = mCtx->getKeyById(keyid); + auto key = mCtx->getKeyRefById(keyid); if (!key.good) continue; keyIds.insert(key.id, key.uids.first().uid); } @@ -260,7 +260,7 @@ void GeneralTab::slotGetServiceToken() { QByteArray keyDataBuf; mCtx->exportKeys(&selectedKeyIds, &keyDataBuf); - GpgKey key = mCtx->getKeyById(keyId); + GpgKey key = mCtx->getKeyRefById(keyId); if (!key.good) { QMessageBox::critical(this, tr("Error"), @@ -341,7 +341,7 @@ void GeneralTab::slotGetServiceToken() { QString serviceTokenTemp = utils->getDataValueStr("serviceToken"); QString fpr = utils->getDataValueStr("fpr"); - auto key = mCtx->getKeyByFpr(fpr); + auto key = mCtx->getKeyRefByFpr(fpr); if (utils->checkServiceTokenFormat(serviceTokenTemp) && key.good) { serviceToken = serviceTokenTemp; qDebug() << "Get Service Token" << serviceToken; diff --git a/src/ui/widgets/InfoBoardWidget.cpp b/src/ui/widgets/InfoBoardWidget.cpp index b9372c59..0c0b6bcd 100644 --- a/src/ui/widgets/InfoBoardWidget.cpp +++ b/src/ui/widgets/InfoBoardWidget.cpp @@ -24,7 +24,7 @@ #include "ui/widgets/InfoBoardWidget.h" -InfoBoardWidget::InfoBoardWidget(QWidget *parent, GpgME::GpgContext *ctx, KeyList *keyList) : +InfoBoardWidget::InfoBoardWidget(QWidget *parent, GpgFrontend::GpgContext *ctx, KeyList *keyList) : QWidget(parent), mCtx(ctx), mKeyList(keyList), appPath(qApp->applicationDirPath()), settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini", QSettings::IniFormat) { diff --git a/src/ui/widgets/KeyList.cpp b/src/ui/widgets/KeyList.cpp index 9c9c6763..8a334e3e 100644 --- a/src/ui/widgets/KeyList.cpp +++ b/src/ui/widgets/KeyList.cpp @@ -26,7 +26,7 @@ #include <utility> -KeyList::KeyList(GpgME::GpgContext *ctx, +KeyList::KeyList(GpgFrontend::GpgContext *ctx, KeyListRow::KeyType selectType, KeyListColumn::InfoType infoType, QWidget *parent) @@ -175,13 +175,13 @@ void KeyList::slotRefresh() { QString usage; QTextStream usage_steam(&usage); - if (GpgME::GpgContext::checkIfKeyCanCert(*it)) + if (GpgFrontend::GpgContext::checkIfKeyCanCert(*it)) usage_steam << "C"; - if (GpgME::GpgContext::checkIfKeyCanEncr(*it)) + if (GpgFrontend::GpgContext::checkIfKeyCanEncr(*it)) usage_steam << "E"; - if (GpgME::GpgContext::checkIfKeyCanSign(*it)) + if (GpgFrontend::GpgContext::checkIfKeyCanSign(*it)) usage_steam << "S"; - if (GpgME::GpgContext::checkIfKeyCanAuth(*it)) + if (GpgFrontend::GpgContext::checkIfKeyCanAuth(*it)) usage_steam << "A"; auto *temp_usage = new QTableWidgetItem(usage); @@ -390,7 +390,7 @@ void KeyList::setFilter(std::function<bool(const GpgKey &)> filter) { void KeyList::slotDoubleClicked(const QModelIndex &index) { if (mAction != nullptr) { - const auto key = mCtx->getKeyById(buffered_keys[index.row()].id); + const auto key = mCtx->getKeyRefById(buffered_keys[index.row()].id); mAction(key, this); } diff --git a/src/ui/widgets/SignersPicker.cpp b/src/ui/widgets/SignersPicker.cpp index 00df5fdd..b48752c7 100644 --- a/src/ui/widgets/SignersPicker.cpp +++ b/src/ui/widgets/SignersPicker.cpp @@ -24,7 +24,7 @@ #include "ui/widgets/SignersPicker.h" -SignersPicker::SignersPicker(GpgME::GpgContext *ctx, QWidget *parent) : mCtx(ctx), QDialog(parent) { +SignersPicker::SignersPicker(GpgFrontend::GpgContext *ctx, QWidget *parent) : mCtx(ctx), QDialog(parent) { auto confirmButton = new QPushButton(tr("Confirm")); connect(confirmButton, SIGNAL(clicked(bool)), this, SLOT(accept())); @@ -33,7 +33,7 @@ SignersPicker::SignersPicker(GpgME::GpgContext *ctx, QWidget *parent) : mCtx(ctx KeyListColumn::NAME | KeyListColumn::EmailAddress | KeyListColumn::Usage); mKeyList->setFilter([](const GpgKey &key) -> bool { - if (!GpgME::GpgContext::checkIfKeyCanSign(key)) return false; + if (!GpgFrontend::GpgContext::checkIfKeyCanSign(key)) return false; else return true; }); diff --git a/src/ui/widgets/VerifyKeyDetailBox.cpp b/src/ui/widgets/VerifyKeyDetailBox.cpp index e0f79c3e..4d88389c 100644 --- a/src/ui/widgets/VerifyKeyDetailBox.cpp +++ b/src/ui/widgets/VerifyKeyDetailBox.cpp @@ -24,7 +24,7 @@ #include "ui/widgets/VerifyKeyDetailBox.h" -VerifyKeyDetailBox::VerifyKeyDetailBox(QWidget *parent, GpgME::GpgContext *ctx, KeyList *keyList, +VerifyKeyDetailBox::VerifyKeyDetailBox(QWidget *parent, GpgFrontend::GpgContext *ctx, KeyList *keyList, gpgme_signature_t signature) : QGroupBox(parent), mCtx(ctx), mKeyList(keyList), fpr(signature->fpr) { @@ -153,7 +153,7 @@ QString VerifyKeyDetailBox::beautifyFingerprint(QString fingerprint) { QGridLayout *VerifyKeyDetailBox::createKeyInfoGrid(gpgme_signature_t &signature) { auto grid = new QGridLayout(); - GpgKey key = mCtx->getKeyByFpr(signature->fpr); + GpgKey key = mCtx->getKeyRefByFpr(signature->fpr); if(!key.good) return nullptr; grid->addWidget(new QLabel(tr("Signer Name:")), 0, 0); |