aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/gpg/GpgContext.h2
-rw-r--r--include/gpg/GpgGenKeyInfo.h253
-rw-r--r--include/ui/KeygenDialog.h50
-rw-r--r--include/ui/KeygenThread.h6
4 files changed, 294 insertions, 17 deletions
diff --git a/include/gpg/GpgContext.h b/include/gpg/GpgContext.h
index 71c857ad..95b61f93 100644
--- a/include/gpg/GpgContext.h
+++ b/include/gpg/GpgContext.h
@@ -99,7 +99,7 @@ namespace GpgME {
bool exportKeys(QStringList *uidList, QByteArray *outBuffer);
- void generateKey(GenKeyInfo *params);
+ bool generateKey(GenKeyInfo *params);
GpgKeyList listKeys();
diff --git a/include/gpg/GpgGenKeyInfo.h b/include/gpg/GpgGenKeyInfo.h
index 397123d9..ab416b81 100644
--- a/include/gpg/GpgGenKeyInfo.h
+++ b/include/gpg/GpgGenKeyInfo.h
@@ -8,16 +8,257 @@
#include <QString>
#include <QTime>
-struct GenKeyInfo {
- bool isSubKey = false;
+class GenKeyInfo {
+
+ bool subKey = true;
QString userid;
QString algo;
- int keySize;
- QDateTime expired;
+ int keySize = 2048;
+ QDateTime expired = QDateTime::currentDateTime().addYears(2);
bool nonExpired = false;
- bool allowSigning = true;
- bool allowEncryption = true;
+
+ bool noPassPhrase = false;
+ bool allowNoPassPhrase = true;
+
+ int suggestMaxKeySize = 1024;
+ int suggestSizeAdditionStep = 1024;
+ int suggestMinKeySize = 4096;
+
QString passPhrase;
+
+public:
+
+ static const QVector<QString> SupportedAlgo;
+
+ [[nodiscard]] bool isSubKey() const {
+ return subKey;
+ }
+
+ void setIsSubKey(bool m_sub_key) {
+ GenKeyInfo::subKey = m_sub_key;
+ }
+
+ [[nodiscard]] const QString &getUserid() const {
+ return userid;
+ }
+
+ void setUserid(const QString &m_userid) {
+ GenKeyInfo::userid = m_userid;
+ }
+
+ [[nodiscard]] const QString &getAlgo() const {
+ 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;
+ setAllowAuthentication(false);
+ allowChangeAuthentication = false;
+
+ suggestMinKeySize = 1024;
+ suggestMaxKeySize = 3072;
+ suggestSizeAdditionStep = 1024;
+ setKeySize(2048);
+
+ } else if (lower_algo == "elg") {
+ /**
+ * GnuPG supports the Elgamal asymmetric encryption algorithm in key lengths ranging from 1024 to 4096 bits.
+ */
+ suggestMinKeySize = 1024;
+ suggestMaxKeySize = 4096;
+ suggestSizeAdditionStep = 1024;
+ setKeySize(2048);
+ }
+ GenKeyInfo::algo = lower_algo;
+ }
+
+ [[nodiscard]] int getKeySize() const {
+ return keySize;
+ }
+
+ void setKeySize(int m_key_size) {
+ if (m_key_size < 0 || m_key_size > 8192) {
+ return;
+ }
+ GenKeyInfo::keySize = 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;
+ }
+ }
+
+ [[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;
+ }
+
+ [[nodiscard]] bool isNoPassPhrase() const {
+ return this->noPassPhrase;
+ }
+
+ void setNonPassPhrase(bool m_non_pass_phrase) {
+ GenKeyInfo::noPassPhrase = true;
+ }
+
+ [[nodiscard]] bool isAllowSigning() const {
+ return allowSigning;
+ }
+
+ [[nodiscard]] bool isAllowNoPassPhrase() const {
+ return allowNoPassPhrase;
+ }
+
+ void setAllowSigning(bool m_allow_signing) {
+ if(allowChangeSigning)
+ GenKeyInfo::allowSigning = m_allow_signing;
+ }
+
+ [[nodiscard]] bool isAllowEncryption() const {
+ return allowEncryption;
+ }
+
+ void setAllowEncryption(bool m_allow_encryption) {
+ if(allowChangeEncryption)
+ GenKeyInfo::allowEncryption = m_allow_encryption;
+ }
+
+ [[nodiscard]] bool isAllowCertification() const {
+ return allowCertification;
+ }
+
+ void setAllowCertification(bool m_allow_certification) {
+ if(allowChangeCertification)
+ GenKeyInfo::allowCertification = m_allow_certification;
+ }
+
+ [[nodiscard]] bool isAllowAuthentication() const {
+ return allowAuthentication;
+ }
+
+ void setAllowAuthentication(bool m_allow_authentication) {
+ if(allowChangeAuthentication)
+ GenKeyInfo::allowAuthentication = m_allow_authentication;
+ }
+
+ [[nodiscard]] const QString &getPassPhrase() const {
+ return passPhrase;
+ }
+
+ void setPassPhrase(const QString &m_pass_phrase) {
+ GenKeyInfo::passPhrase = m_pass_phrase;
+ }
+
+ [[nodiscard]] bool isAllowChangeSigning() const {
+ return allowChangeSigning;
+ }
+ [[nodiscard]] bool isAllowChangeEncryption() const {
+ return allowChangeEncryption;
+ }
+
+ [[nodiscard]] bool isAllowChangeCertification() const {
+ return allowChangeCertification;
+ }
+
+ [[nodiscard]] bool isAllowChangeAuthentication() const {
+ return allowChangeAuthentication;
+ }
+
+ [[nodiscard]] int getSuggestMaxKeySize() const {
+ return suggestMaxKeySize;
+ }
+
+ [[nodiscard]] int getSuggestMinKeySize() const {
+ return suggestMinKeySize;
+ }
+
+ [[nodiscard]] int getSizeChangeStep() const {
+ return suggestSizeAdditionStep;
+ }
+
+
+private:
+ bool allowEncryption = true;
+ bool allowChangeEncryption = true;
+
+ bool allowCertification = true;
+ bool allowChangeCertification = true;
+
+ bool allowAuthentication = true;
+ bool allowChangeAuthentication = true;
+
+ 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();
+
+ }
+
+public:
+
+ explicit GenKeyInfo(bool m_is_sub_key = false) : subKey(m_is_sub_key) {
+ setAlgo("rsa");
+ }
+
+
};
#endif //GPG4USB_GPGGENKEYINFO_H
diff --git a/include/ui/KeygenDialog.h b/include/ui/KeygenDialog.h
index cca92830..933f8bbe 100644
--- a/include/ui/KeygenDialog.h
+++ b/include/ui/KeygenDialog.h
@@ -42,18 +42,17 @@ public:
explicit KeyGenDialog(GpgME::GpgContext *ctx, QWidget *parent = nullptr);
private:
- void generateKeyDialog();
- /**
- * @details Check the password strength of the text in the passwordEdit member
- *
- * @return digit between 0 and 6, the higher the more secure is the password
- */
- int checkPassWordStrength();
+ QGroupBox *create_key_usage_group_box();
+
+ 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 */
__attribute__((unused)) KeyGenThread *keyGenThread{}; /** Thread for key generation */
__attribute__((unused)) QStringList errorMessages; /** List of errors occuring when checking entries of lineedits */
+ GenKeyInfo genKeyInfo{};
+
QDialogButtonBox *buttonBox; /** Box for standardbuttons */
QLabel *errorLabel{}; /** Label containing error message */
QLineEdit *nameEdit{}; /** Lineedit for the keys name */
@@ -65,8 +64,35 @@ private:
QComboBox *keyTypeComboBox{}; /** Combobox for Keytpe */
QDateTimeEdit *dateEdit{}; /** Dateedit for expiration date */
QCheckBox *expireCheckBox{}; /** Checkbox, if key should expire */
+ QCheckBox *noPassPhraseCheckBox{};
QSlider *pwStrengthSlider{}; /** Slider showing the password strength */
+ QGroupBox *keyUsageGroupBox{}; /** Group of Widgets detecting the usage of the Key **/
+
+// ENCR, SIGN, CERT, AUTH
+ std::vector<QCheckBox *> keyUsageCheckBoxes;
+
+ KeyGenThread *kg = nullptr;
+
+ void generateKeyDialog();
+
+ /**
+ * @details Check the password strength of the text in the passwordEdit member
+ *
+ * @return digit between 0 and 6, the higher the more secure is the password
+ */
+ int checkPassWordStrength();
+
+
+ /**
+ * @details Refresh widgets state by GenKeyInfo
+ */
+ void refresh_widgets_state();
+
+ void set_signal_slot();
+
+ bool check_email_address(const QString &str);
+
private slots:
/**
@@ -84,6 +110,16 @@ private slots:
*/
void slotKeyGenAccept();
+ void slotEncryptionBoxChanged(int state);
+
+ void slotSigningBoxChanged(int state);
+
+ void slotCertificationBoxChanged(int state);
+
+ void slotAuthenticationBoxChanged(int state);
+
+ void slotActivatedKeyType(int index);
+
};
#endif // __KEYGENDIALOG_H__
diff --git a/include/ui/KeygenThread.h b/include/ui/KeygenThread.h
index 467d8338..5f73efdb 100644
--- a/include/ui/KeygenThread.h
+++ b/include/ui/KeygenThread.h
@@ -34,14 +34,14 @@ class KeyGenThread : public QThread {
Q_OBJECT
public:
- KeyGenThread(GenKeyInfo keyGenParams, GpgME::GpgContext *ctx);
+ KeyGenThread(GenKeyInfo *keyGenParams, GpgME::GpgContext *ctx);
signals:
- void signalKeyGenerated();
+ void signalKeyGenerated(bool success);
private:
- GenKeyInfo keyGenParams;
+ GenKeyInfo *keyGenParams;
GpgME::GpgContext *mCtx;
[[maybe_unused]] bool abort;
QMutex mutex;