diff options
author | Saturneric <[email protected]> | 2021-05-21 16:15:54 +0000 |
---|---|---|
committer | Saturneric <[email protected]> | 2021-05-21 16:15:54 +0000 |
commit | 21f4730e92d088c06dea01684f3f736f3f9beff0 (patch) | |
tree | c1dc4dc6836903adc688b03cafabc06fc845743f /include | |
parent | Modified KeyList and Add Usage Support; (diff) | |
download | GpgFrontend-21f4730e92d088c06dea01684f3f736f3f9beff0.tar.gz GpgFrontend-21f4730e92d088c06dea01684f3f736f3f9beff0.zip |
Expand Key Details Dialog;
Expand and Improve GpgKey and GpgSubKey;
Change Interface getKeyDetails();
Code Modified;
Signed-off-by: Saturneric <[email protected]>
Diffstat (limited to 'include')
-rw-r--r-- | include/gpg/GpgContext.h | 2 | ||||
-rw-r--r-- | include/gpg/GpgGenKeyInfo.h | 120 | ||||
-rw-r--r-- | include/gpg/GpgKey.h | 140 | ||||
-rw-r--r-- | include/gpg/GpgSubKey.h | 37 | ||||
-rw-r--r-- | include/ui/KeyDetailsDialog.h | 60 | ||||
-rw-r--r-- | include/ui/KeyPairDetailTab.h | 62 |
6 files changed, 207 insertions, 214 deletions
diff --git a/include/gpg/GpgContext.h b/include/gpg/GpgContext.h index 071fff8b..81ff3152 100644 --- a/include/gpg/GpgContext.h +++ b/include/gpg/GpgContext.h @@ -102,7 +102,7 @@ namespace GpgME { void exportSecretKey(const QString &uid, QByteArray *outBuffer); - gpgme_key_t getKeyDetails(const QString &uid); + void getKeyDetails(const QString &uid, GpgKey& key); gpgme_signature_t verify(QByteArray *inBuffer, QByteArray *sigBuffer = nullptr); diff --git a/include/gpg/GpgGenKeyInfo.h b/include/gpg/GpgGenKeyInfo.h index f4273b05..ee2b0262 100644 --- a/include/gpg/GpgGenKeyInfo.h +++ b/include/gpg/GpgGenKeyInfo.h @@ -25,8 +25,7 @@ #ifndef GPG4USB_GPGGENKEYINFO_H #define GPG4USB_GPGGENKEYINFO_H -#include <QString> -#include <QTime> +#include "GpgFrontend.h" class GenKeyInfo { @@ -70,111 +69,35 @@ public: return algo; } - void setAlgo(const QString &m_algo) { - - qDebug() << "set algo " << m_algo; - - reset_options(); - - if (!this->subKey) { - this->setAllowCertification(true); - this->allowChangeCertification = false; - } - - auto lower_algo = m_algo.toLower(); - - if(lower_algo == "rsa") { - /** - * RSA is the world’s premier asymmetric cryptographic algorithm, - * and is built on the difficulty of factoring extremely large composites. - * GnuPG supports RSA with key sizes of between 1024 and 4096 bits. - */ - suggestMinKeySize = 1024; - suggestMaxKeySize = 4096; - suggestSizeAdditionStep = 1024; - setKeySize(2048); - - } else if (lower_algo == "dsa") { - /** - * Algorithm (DSA) as a government standard for digital signatures. - * Originally, it supported key lengths between 512 and 1024 bits. - * Recently, NIST has declared 512-bit keys obsolete: - * now, DSA is available in 1024, 2048 and 3072-bit lengths. - */ - setAllowEncryption(false); - allowChangeEncryption = false; - - suggestMinKeySize = 1024; - suggestMaxKeySize = 3072; - suggestSizeAdditionStep = 1024; - setKeySize(2048); - - } else if (lower_algo == "ed25519") { - /** - * GnuPG supports the Elgamal asymmetric encryption algorithm in key lengths ranging from 1024 to 4096 bits. - */ - - setAllowEncryption(false); - allowChangeEncryption = false; - - suggestMinKeySize = -1; - suggestMaxKeySize = -1; - suggestSizeAdditionStep = -1; - setKeySize(-1); - } - GenKeyInfo::algo = lower_algo; - } - - [[nodiscard]] QString getKeySizeStr() const { - if(keySize > 0) { - return QString::number(keySize); - } - else { - return QString(); - } + void setAlgo(const QString &m_algo); - } + [[nodiscard]] QString getKeySizeStr() const; [[nodiscard]] int getKeySize() const { return keySize; } - void setKeySize(int m_key_size) { - if (m_key_size < suggestMinKeySize || m_key_size > suggestMaxKeySize) { - return; - } - GenKeyInfo::keySize = m_key_size; - } + void setKeySize(int m_key_size); [[nodiscard]] const QDateTime &getExpired() const { return expired; } - void setExpired(const QDateTime &m_expired) { - auto current = QDateTime::currentDateTime(); - if (isNonExpired() && m_expired < current.addYears(2)) { - GenKeyInfo::expired = m_expired; - } - } + void setExpired(const QDateTime &m_expired); [[nodiscard]] bool isNonExpired() const { return nonExpired; } - void setNonExpired(bool m_non_expired) { - if (!m_non_expired) { - this->expired = QDateTime(QDateTime::fromTime_t(0)); - } - GenKeyInfo::nonExpired = m_non_expired; - } + void setNonExpired(bool m_non_expired); [[nodiscard]] bool isNoPassPhrase() const { return this->noPassPhrase; } void setNonPassPhrase(bool m_non_pass_phrase) { - GenKeyInfo::noPassPhrase = true; + GenKeyInfo::noPassPhrase = m_non_pass_phrase; } [[nodiscard]] bool isAllowSigning() const { @@ -194,19 +117,13 @@ public: return allowEncryption; } - void setAllowEncryption(bool m_allow_encryption) { - if(allowChangeEncryption) - GenKeyInfo::allowEncryption = m_allow_encryption; - } + void setAllowEncryption(bool m_allow_encryption); [[nodiscard]] bool isAllowCertification() const { return allowCertification; } - void setAllowCertification(bool m_allow_certification) { - if(allowChangeCertification) - GenKeyInfo::allowCertification = m_allow_certification; - } + void setAllowCertification(bool m_allow_certification); [[nodiscard]] bool isAllowAuthentication() const { return allowAuthentication; @@ -266,24 +183,7 @@ private: bool allowSigning = true; bool allowChangeSigning = true; - void reset_options() { - - allowChangeEncryption = true; - setAllowEncryption(true); - - allowChangeCertification = true; - setAllowCertification(true); - - allowChangeSigning = true; - setAllowSigning(true); - - allowChangeAuthentication = true; - setAllowAuthentication(true); - - - passPhrase.clear(); - - } + void reset_options(); public: diff --git a/include/gpg/GpgKey.h b/include/gpg/GpgKey.h index d33bd71d..2dc4f8c8 100644 --- a/include/gpg/GpgKey.h +++ b/include/gpg/GpgKey.h @@ -1,6 +1,26 @@ -// -// Created by eric on 2021/5/21. -// +/** + * 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 @@ -11,17 +31,20 @@ class GpgKey { public: - GpgKey() { - is_private_key = false; - } QString id; QString name; QString email; + QString comment; QString fpr; QString protocol; - int owner_trust; + QString owner_trust; + QString pubkey_algo; QDateTime last_update; + QDateTime expires; + QDateTime create_time; + + int length; bool can_encrypt{}; bool can_sign{}; @@ -34,44 +57,81 @@ public: bool revoked{}; bool disabled{}; - QVector<GpgSubKey> subKeys; - - GpgKey(gpgme_key_t key) { - 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)); - owner_trust = key->owner_trust; + bool good = false; - if (key->uids) { - name = QString::fromUtf8(key->uids->name); - email = QString::fromUtf8(key->uids->email); - } + QVector<GpgSubKey> subKeys; - gpgme_subkey_t next = key->subkeys; + explicit GpgKey(gpgme_key_t key) { + parse(key); + } - while(next != nullptr) { - subKeys.push_back(GpgSubKey(next)); - next = next->next; - } + GpgKey() { + is_private_key = false; + } - if(!subKeys.isEmpty()) { - id = subKeys.first().id; - } else { - id = ""; + void parse(gpgme_key_t key) { + if(key != nullptr) { + good = true; + 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; + } + + + if (key->uids) { + name = QString::fromUtf8(key->uids->name); + email = QString::fromUtf8(key->uids->email); + comment = QString::fromUtf8(key->uids->comment); + } + + gpgme_subkey_t 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; + } else { + id = ""; + } } - - } }; diff --git a/include/gpg/GpgSubKey.h b/include/gpg/GpgSubKey.h index 1c810693..f495c709 100644 --- a/include/gpg/GpgSubKey.h +++ b/include/gpg/GpgSubKey.h @@ -1,18 +1,40 @@ -// -// Created by eric on 2021/5/21. -// - +/** + * 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 <gpgme.h> +#include "GpgFrontend.h" struct GpgSubKey { QString id; QString fpr; + QString pubkey_algo; + + unsigned int length; + bool can_encrypt{}; bool can_sign{}; bool can_certify{}; @@ -33,6 +55,7 @@ struct GpgSubKey { explicit GpgSubKey(gpgme_subkey_t key) { id = key->keyid; + pubkey_algo = gpgme_pubkey_algo_name(key->pubkey_algo); fpr = key->fpr; expired = (key->expired != 0u); @@ -40,6 +63,8 @@ struct GpgSubKey { disabled = key->disabled; + length = key->length; + can_authenticate = key->can_authenticate; can_certify = key->can_certify; can_encrypt = key->can_encrypt; diff --git a/include/ui/KeyDetailsDialog.h b/include/ui/KeyDetailsDialog.h index 96d707b9..1ad2d133 100644 --- a/include/ui/KeyDetailsDialog.h +++ b/include/ui/KeyDetailsDialog.h @@ -26,74 +26,20 @@ #define __KEYDETAILSDIALOG_H__ #include "gpg/GpgContext.h" +#include "KeyPairDetailTab.h" #include <gpgme.h> -QT_BEGIN_NAMESPACE -class QDateTime; - -class QVBoxLayout; - -class QHBoxLayout; - -class QDialogButtonBox; - -class QDialog; - -class QGroupBox; - -class QLabel; - -class QGridLayout; - -class QPushButton; - -QT_END_NAMESPACE - class KeyDetailsDialog : public QDialog { Q_OBJECT public: - KeyDetailsDialog(GpgME::GpgContext *ctx, gpgme_key_t key, QWidget *parent = nullptr); - - /** - * @details Return QString with a space inserted at every fourth character - * - * @param fingerprint The fingerprint to be beautified - */ - static QString beautifyFingerprint(QString fingerprint); - -private slots: - - /** - * @details Export the key to a file, which is choosen in a file dialog - */ - void slotExportPrivateKey(); - /** - * @details Copy the fingerprint to clipboard - */ - void slotCopyFingerprint(); + KeyDetailsDialog(GpgME::GpgContext *ctx, const GpgKey& key, QWidget *parent = nullptr); private: - QString *keyid; /** The id of the key the details should be shown for */ - GpgME::GpgContext *mCtx; /** The current gpg-context */ - QGroupBox *ownerBox; /** Groupbox containing owner information */ - QGroupBox *keyBox; /** Groupbox containing key information */ - QGroupBox *fingerprintBox; /** Groupbox containing fingerprint information */ - QGroupBox *additionalUidBox; /** Groupbox containing information about additional uids */ - QDialogButtonBox *buttonBox; /** Box containing the close button */ + QTabWidget *tabWidget{}; - QLabel *nameVarLabel; /** Label containng the keys name */ - QLabel *emailVarLabel; /** Label containng the keys email */ - QLabel *commentVarLabel; /** Label containng the keys commment */ - QLabel *keySizeVarLabel; /** Label containng the keys keysize */ - QLabel *expireVarLabel; /** Label containng the keys expiration date */ - QLabel *createdVarLabel; /** Label containng the keys creation date */ - QLabel *algorithmVarLabel; /** Label containng the keys algorithm */ - QLabel *keyidVarLabel; /** Label containng the keys keyid */ - QLabel *fingerPrintVarLabel; /** Label containng the keys fingerprint */ - QLabel *addUserIdsVarLabel; /** Label containng info about keys additional uids */ }; #endif // __KEYDETAILSDIALOG_H__ diff --git a/include/ui/KeyPairDetailTab.h b/include/ui/KeyPairDetailTab.h new file mode 100644 index 00000000..5ed40dac --- /dev/null +++ b/include/ui/KeyPairDetailTab.h @@ -0,0 +1,62 @@ +// +// Created by eric on 2021/5/21. +// + +#ifndef GPGFRONTEND_KEYPAIRDETAILTAB_H +#define GPGFRONTEND_KEYPAIRDETAILTAB_H + +#include "GpgFrontend.h" +#include "gpg/GpgContext.h" + +class KeyPairDetailTab : public QWidget { + Q_OBJECT + + /** + * @details Return QString with a space inserted at every fourth character + * + * @param fingerprint The fingerprint to be beautified + */ + static QString beautifyFingerprint(QString fingerprint); + +private slots: + + /** + * @details Export the key to a file, which is choosen in a file dialog + */ + void slotExportPrivateKey(); + + /** + * @details Copy the fingerprint to clipboard + */ + void slotCopyFingerprint(); + +private: + + QString *keyid; /** The id of the key the details should be shown for */ + + GpgME::GpgContext *mCtx; /** The current gpg-context */ + + QGroupBox *ownerBox; /** Groupbox containing owner information */ + QGroupBox *keyBox; /** Groupbox containing key information */ + QGroupBox *fingerprintBox; /** Groupbox containing fingerprint information */ + QGroupBox *additionalUidBox; /** Groupbox containing information about additional uids */ + QDialogButtonBox *buttonBox; /** Box containing the close button */ + + QLabel *nameVarLabel; /** Label containng the keys name */ + QLabel *emailVarLabel; /** Label containng the keys email */ + QLabel *commentVarLabel; /** Label containng the keys commment */ + QLabel *keySizeVarLabel; /** Label containng the keys keysize */ + QLabel *expireVarLabel; /** Label containng the keys expiration date */ + QLabel *createdVarLabel; /** Label containng the keys creation date */ + QLabel *algorithmVarLabel; /** Label containng the keys algorithm */ + QLabel *keyidVarLabel; /** Label containng the keys keyid */ + QLabel *fingerPrintVarLabel; /** Label containng the keys fingerprint */ + QLabel *addUserIdsVarLabel{}; /** Label containng info about keys additional uids */ + QLabel *usageVarLabel; + +public: + explicit KeyPairDetailTab(GpgME::GpgContext *ctx, const GpgKey& key, QWidget *parent = nullptr); +}; + + +#endif //GPGFRONTEND_KEYPAIRDETAILTAB_H |