diff options
author | nils <nils@34ebc366-c3a9-4b3c-9f84-69acf7962910> | 2011-10-30 18:13:10 +0000 |
---|---|---|
committer | nils <nils@34ebc366-c3a9-4b3c-9f84-69acf7962910> | 2011-10-30 18:13:10 +0000 |
commit | 5128c37a83f6d6efa5dad3170d91a9e0b9437682 (patch) | |
tree | 1723ba5da9845d3412ca397c94aeaa3d1ab90ed2 | |
parent | refactored gpgwin -> mainwindow and context -> gpgcontext (diff) | |
download | gpg4usb-5128c37a83f6d6efa5dad3170d91a9e0b9437682.tar.gz gpg4usb-5128c37a83f6d6efa5dad3170d91a9e0b9437682.zip |
put keygendialog to seperate files
git-svn-id: http://cpunk.de/svn/src/gpg4usb/trunk@589 34ebc366-c3a9-4b3c-9f84-69acf7962910
-rw-r--r-- | TODO | 7 | ||||
-rw-r--r-- | gpg4usb.pro | 3 | ||||
-rw-r--r-- | keygendialog.cpp | 233 | ||||
-rw-r--r-- | keygendialog.h | 82 | ||||
-rwxr-xr-x | keymgmt.cpp | 208 | ||||
-rwxr-xr-x | keymgmt.h | 8 |
6 files changed, 324 insertions, 217 deletions
@@ -27,6 +27,9 @@ Release 0.3.1 - beautify icons for verify and sign [DONE] Release 0.3.2 +- refactoring and cleanup: [DONE] + - gpgwin.cpp -> mainwindow.cpp [DONE] + - context.cpp -> gpgcontext.cpp [DONE] - set gpgme error language to chosen language (context.cpp:49) - import from keyserver doesn't end, if network-connection is available, but no connection to keyserver (?) - minimal steganography option: remove or add pgp-headers on demand @@ -34,12 +37,8 @@ Release 0.3.2 - understandable message if no matching private key found for decryption - investigate in adding a offline help system - investigate in embedding a steganography tool -- refactoring and cleanup: [DONE] - - gpgwin.cpp -> mainwindow.cpp [DONE] - - context.cpp -> gpgcontext.cpp [DONE] - optionally open new tab after encryption/decrytion - Release 0.3.3 - Change private key password (catch bad passphrase message) - Wizard on first start (Create Key, Import from older gpg4usb, import from gnupg) diff --git a/gpg4usb.pro b/gpg4usb.pro index 4cce0ca..7d9b4dc 100644 --- a/gpg4usb.pro +++ b/gpg4usb.pro @@ -22,6 +22,7 @@ HEADERS += attachments.h \ keymgmt.h \ fileencryptiondialog.h \ mime.h \ + keygendialog.h \ keygenthread.h \ keydetailsdialog.h \ settingsdialog.h \ @@ -33,6 +34,7 @@ HEADERS += attachments.h \ verifynotification.h \ verifydetailsdialog.h \ verifykeydetailbox.h + SOURCES += attachments.cpp \ gpgcontext.cpp \ mainwindow.cpp \ @@ -41,6 +43,7 @@ SOURCES += attachments.cpp \ keymgmt.cpp \ fileencryptiondialog.cpp \ mime.cpp \ + keygendialog.cpp \ keygenthread.cpp \ keydetailsdialog.cpp \ settingsdialog.cpp \ diff --git a/keygendialog.cpp b/keygendialog.cpp new file mode 100644 index 0000000..cad510a --- /dev/null +++ b/keygendialog.cpp @@ -0,0 +1,233 @@ +/* + * + * keygendialog.cpp + * + * Copyright 2008 gpg4usb-team <[email protected]> + * + * This file is part of gpg4usb. + * + * Gpg4usb 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. + * + * Gpg4usb 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 gpg4usb. If not, see <http://www.gnu.org/licenses/> + */ + +#include "keygendialog.h" + +KeyGenDialog::KeyGenDialog(GpgME::GpgContext *ctx, QWidget *parent) + : QDialog(parent) +{ + mCtx = ctx; + buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + + this->setWindowTitle(tr("Generate Key")); + this->setModal(true); + generateKeyDialog(); +} + +void KeyGenDialog::generateKeyDialog() +{ + + nameLabel = new QLabel(tr("Name:")); + emailLabel = new QLabel(tr("E-Mailaddress::")); + commentLabel = new QLabel(tr("Comment:")); + keySizeLabel = new QLabel(tr("KeySize (in Bit):")); + dateLabel = new QLabel(tr("Expiration Date:")); + passwordLabel = new QLabel(tr("Password:")); + repeatpwLabel = new QLabel(tr("Repeat Password:")); + expireLabel = new QLabel(tr("Never Expire")); + pwStrengthLabel = new QLabel(tr("Password: Strength\nWeak -> Strong")); + errorLabel = new QLabel(tr("")); + nameEdit = new QLineEdit(this); + emailEdit = new QLineEdit(this); + commentEdit = new QLineEdit(this); + + keySizeSpinBox = new QSpinBox(this); + keySizeSpinBox->setRange(768, 8192); + keySizeSpinBox->setValue(2048); + + keySizeSpinBox->setSingleStep(256); + + dateEdit = new QDateEdit(QDate::currentDate().addYears(5), this); + dateEdit->setMinimumDate(QDate::currentDate()); + dateEdit->setDisplayFormat("dd/MM/yyyy"); + dateEdit->setCalendarPopup(true); + dateEdit->setEnabled(false); + + expireCheckBox = new QCheckBox(this); + expireCheckBox->setCheckState(Qt::Checked); + + passwordEdit = new QLineEdit(this); + repeatpwEdit = new QLineEdit(this); + + passwordEdit->setEchoMode(QLineEdit::Password); + repeatpwEdit->setEchoMode(QLineEdit::Password); + + pwStrengthSlider = new QSlider(this); + pwStrengthSlider->setOrientation(Qt::Horizontal); + pwStrengthSlider->setMaximum(6); + pwStrengthSlider->setDisabled(true); + pwStrengthSlider->setToolTip(tr("Password Strength")); + pwStrengthSlider->setTickPosition(QSlider::TicksBelow); + + QGridLayout *vbox1 = new QGridLayout; + vbox1->addWidget(nameLabel, 0, 0); + vbox1->addWidget(nameEdit, 0, 1); + vbox1->addWidget(emailLabel, 1, 0); + vbox1->addWidget(emailEdit, 1, 1); + vbox1->addWidget(commentLabel, 2, 0); + vbox1->addWidget(commentEdit, 2, 1); + vbox1->addWidget(dateLabel, 3, 0); + vbox1->addWidget(dateEdit, 3, 1); + vbox1->addWidget(expireCheckBox, 3, 2); + vbox1->addWidget(expireLabel, 3, 3); + vbox1->addWidget(keySizeLabel, 4, 0); + vbox1->addWidget(keySizeSpinBox, 4, 1); + vbox1->addWidget(passwordLabel, 5, 0); + vbox1->addWidget(passwordEdit, 5, 1); + vbox1->addWidget(pwStrengthLabel, 5, 3); + vbox1->addWidget(repeatpwLabel, 6, 0); + vbox1->addWidget(repeatpwEdit, 6, 1); + vbox1->addWidget(pwStrengthSlider, 6, 3); + + QWidget *nameList = new QWidget(this); + nameList->setLayout(vbox1); + + QVBoxLayout *vbox2 = new QVBoxLayout(); + vbox2->addWidget(nameList); + vbox2->addWidget(errorLabel); + vbox2->addWidget(buttonBox); + + connect(buttonBox, SIGNAL(accepted()), this, SLOT(keyGenAccept())); + connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); + + connect(expireCheckBox, SIGNAL(stateChanged(int)), this, SLOT(expireBoxChanged())); + connect(passwordEdit, SIGNAL(textChanged(QString)), this, SLOT(passwordEditChanged())); + this->setLayout(vbox2); +} + +void KeyGenDialog::keyGenAccept() +{ + QString errorString = ""; + QString keyGenParams = ""; + /** + * check for errors in keygen dialog input + */ + if ((nameEdit->text()).size() < 5) { + errorString.append(tr(" Name must contain at least five characters. \n")); + } + if (passwordEdit->text() != repeatpwEdit->text()) { + errorString.append(tr(" Password and Repeat don't match. ")); + } + + if (errorString.isEmpty()) { + /** + * create the string for key generation + */ + keyGenParams = "<GnupgKeyParms format=\"internal\">\n" + "Key-Type: DSA\n" + "Key-Length: 1024\n" + "Subkey-Type: ELG-E\n" + "Subkey-Length: " + + keySizeSpinBox->cleanText() + "\n" + "Name-Real: " + nameEdit->text() + "\n"; + if (!(commentEdit->text().isEmpty())) { + keyGenParams += "Name-Comment: " + commentEdit->text() + "\n"; + } + if (!(emailEdit->text().isEmpty())) { + keyGenParams += "Name-Email: " + emailEdit->text() + "\n"; + } + if (expireCheckBox->checkState()) { + keyGenParams += "Expire-Date: 0\n"; + } else { + keyGenParams += "Expire-Date: " + dateEdit->sectionText(QDateTimeEdit::YearSection) + "-" + dateEdit->sectionText(QDateTimeEdit::MonthSection) + "-" + dateEdit->sectionText(QDateTimeEdit::DaySection) + "\n"; + } + if (!(passwordEdit->text().isEmpty())) { + keyGenParams += "Passphrase: " + passwordEdit->text() + "\n"; + } + keyGenParams += "</GnupgKeyParms>"; + + KeyGenThread *kg = new KeyGenThread(keyGenParams, mCtx); + kg->start(); + + this->accept(); + + QDialog *dialog = new QDialog(this, Qt::CustomizeWindowHint | Qt::WindowTitleHint); + dialog->setModal(true); + dialog->setWindowTitle(tr("Generating Key...")); + + QLabel *waitMessage = new QLabel(tr("Collecting random data for key generation.\n This may take a while.\n To speed up the process use your computer\n (e.g. browse the net, listen to music,...)")); + QProgressBar *pb = new QProgressBar(); + pb->setRange(0, 0); + + QVBoxLayout *layout = new QVBoxLayout(dialog); + layout->addWidget(waitMessage); + layout->addWidget(pb); + dialog->setLayout(layout); + + dialog->show(); + + while (kg->isRunning()) { + QCoreApplication::processEvents(); + } + + dialog->close(); + } else { + /** + * create error message + */ + errorLabel->setAutoFillBackground(true); + QPalette error = errorLabel->palette(); + error.setColor(QPalette::Background, "#ff8080"); + errorLabel->setPalette(error); + errorLabel->setText(errorString); + + this->show(); + } +} + +void KeyGenDialog::expireBoxChanged() +{ + if (expireCheckBox->checkState()) { + dateEdit->setEnabled(false); + } else { + dateEdit->setEnabled(true); + } +} + +void KeyGenDialog::passwordEditChanged() +{ + pwStrengthSlider->setValue(checkPassWordStrength()); + update(); +} + +int KeyGenDialog::checkPassWordStrength() +{ + int strength = 0; + if ((passwordEdit->text()).length() > 7) { + strength = strength + 2; + } + if ((passwordEdit->text()).contains(QRegExp("\\d"))) { + strength++; + } + if ((passwordEdit->text()).contains(QRegExp("[a-z]"))) { + strength++; + } + if ((passwordEdit->text()).contains(QRegExp("[A-Z]"))) { + strength++; + } + if ((passwordEdit->text()).contains(QRegExp("\\W"))) { + strength++; + } + + return strength; +} + diff --git a/keygendialog.h b/keygendialog.h new file mode 100644 index 0000000..4e0841f --- /dev/null +++ b/keygendialog.h @@ -0,0 +1,82 @@ +/* + * keygendialog.h + * + * Copyright 2008 gpg4usb-team <[email protected]> + * + * This file is part of gpg4usb. + * + * Gpg4usb 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. + * + * Gpg4usb 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 gpg4usb. If not, see <http://www.gnu.org/licenses/> + */ + +#ifndef __KEYGENDIALOG_H__ +#define __KEYGENDIALOG_H__ + +#include "keygenthread.h" +#include "gpgcontext.h" +#include <QtGui> + +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 KeyGenDialog : public QDialog +{ + Q_OBJECT + +public: + KeyGenDialog(GpgME::GpgContext* ctx, QWidget *parent = 0); + +private: + void generateKeyDialog(); + int checkPassWordStrength(); + + GpgME::GpgContext *mCtx; + KeyGenThread *keyGenThread; + QStringList errorMessages; + QDialogButtonBox *buttonBox; + QLabel *nameLabel; + QLabel *emailLabel; + QLabel *commentLabel; + QLabel *keySizeLabel; + QLabel *passwordLabel; + QLabel *repeatpwLabel; + QLabel *errorLabel; + QLabel *dateLabel; + QLabel *expireLabel; + QLabel *pwStrengthLabel; + QLineEdit *nameEdit; + QLineEdit *emailEdit; + QLineEdit *commentEdit; + QLineEdit *passwordEdit; + QLineEdit *repeatpwEdit; + QSpinBox *keySizeSpinBox; + QDateTimeEdit *dateEdit; + QCheckBox *expireCheckBox; + QSlider *pwStrengthSlider; + +private slots: + void expireBoxChanged(); + void passwordEditChanged(); + void keyGenAccept(); + +}; +#endif // __KEYGENDIALOG_H__ diff --git a/keymgmt.cpp b/keymgmt.cpp index 602d8b9..6a0b8f3 100755 --- a/keymgmt.cpp +++ b/keymgmt.cpp @@ -123,7 +123,6 @@ void KeyMgmt::createMenus() keyMenu = menuBar()->addMenu(tr("&Key")); importKeyMenu = keyMenu->addMenu(tr("&Import Key From...")); -// importKeyMenu->setIcon(QIcon(mIconPath + "key_import.png")); importKeyMenu->addAction(importKeyFromFileAct); importKeyMenu->addAction(importKeyFromClipboardAct); importKeyMenu->addAction(importKeyFromKeyServerAct); @@ -253,211 +252,8 @@ void KeyMgmt::exportKeyToClipboard() void KeyMgmt::generateKeyDialog() { - QStringList errorMessages; - genkeyDialog = new QDialog(); - QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); - - genkeyDialog->setWindowTitle(tr("Generate Key")); - genkeyDialog->setModal(true); - - nameLabel = new QLabel(tr("Name:")); - emailLabel = new QLabel(tr("E-Mailaddress::")); - commentLabel = new QLabel(tr("Comment:")); - keySizeLabel = new QLabel(tr("KeySize (in Bit):")); - dateLabel = new QLabel(tr("Expiration Date:")); - passwordLabel = new QLabel(tr("Password:")); - repeatpwLabel = new QLabel(tr("Repeat Password:")); - expireLabel = new QLabel(tr("Never Expire")); - pwStrengthLabel = new QLabel(tr("Password: Strength\nWeak -> Strong")); - errorLabel = new QLabel(tr("")); - nameEdit = new QLineEdit(genkeyDialog); - emailEdit = new QLineEdit(genkeyDialog); - commentEdit = new QLineEdit(genkeyDialog); - - keySizeSpinBox = new QSpinBox(genkeyDialog); - keySizeSpinBox->setRange(768, 8192); - keySizeSpinBox->setValue(2048); - - keySizeSpinBox->setSingleStep(256); - - dateEdit = new QDateEdit(QDate::currentDate().addYears(5), genkeyDialog); - dateEdit->setMinimumDate(QDate::currentDate()); - dateEdit->setDisplayFormat("dd/MM/yyyy"); - dateEdit->setCalendarPopup(true); - dateEdit->setEnabled(false); - - expireCheckBox = new QCheckBox(genkeyDialog); - expireCheckBox->setCheckState(Qt::Checked); - - passwordEdit = new QLineEdit(genkeyDialog); - repeatpwEdit = new QLineEdit(genkeyDialog); - - passwordEdit->setEchoMode(QLineEdit::Password); - repeatpwEdit->setEchoMode(QLineEdit::Password); - - pwStrengthSlider = new QSlider(genkeyDialog); - pwStrengthSlider->setOrientation(Qt::Horizontal); - pwStrengthSlider->setMaximum(6); - pwStrengthSlider->setDisabled(true); - pwStrengthSlider->setToolTip(tr("Password Strength")); - pwStrengthSlider->setTickPosition(QSlider::TicksBelow); - - QGridLayout *vbox1 = new QGridLayout; - vbox1->addWidget(nameLabel, 0, 0); - vbox1->addWidget(nameEdit, 0, 1); - vbox1->addWidget(emailLabel, 1, 0); - vbox1->addWidget(emailEdit, 1, 1); - vbox1->addWidget(commentLabel, 2, 0); - vbox1->addWidget(commentEdit, 2, 1); - vbox1->addWidget(dateLabel, 3, 0); - vbox1->addWidget(dateEdit, 3, 1); - vbox1->addWidget(expireCheckBox, 3, 2); - vbox1->addWidget(expireLabel, 3, 3); - vbox1->addWidget(keySizeLabel, 4, 0); - vbox1->addWidget(keySizeSpinBox, 4, 1); - vbox1->addWidget(passwordLabel, 5, 0); - vbox1->addWidget(passwordEdit, 5, 1); - vbox1->addWidget(pwStrengthLabel, 5, 3); - vbox1->addWidget(repeatpwLabel, 6, 0); - vbox1->addWidget(repeatpwEdit, 6, 1); - vbox1->addWidget(pwStrengthSlider, 6, 3); - - QWidget *nameList = new QWidget(genkeyDialog); - nameList->setLayout(vbox1); - - QVBoxLayout *vbox2 = new QVBoxLayout(); - vbox2->addWidget(nameList); - vbox2->addWidget(errorLabel); - vbox2->addWidget(buttonBox); - - connect(buttonBox, SIGNAL(accepted()), this, SLOT(keyGenAccept())); - connect(buttonBox, SIGNAL(rejected()), genkeyDialog, SLOT(reject())); - - connect(expireCheckBox, SIGNAL(stateChanged(int)), this, SLOT(expireBoxChanged())); - connect(passwordEdit, SIGNAL(textChanged(QString)), this, SLOT(passwordEditChanged())); - genkeyDialog->setLayout(vbox2); - genkeyDialog->show(); - - if (genkeyDialog->exec() == QDialog::Accepted) { - } -} - - -void KeyMgmt::keyGenAccept() -{ - QString errorString = ""; - QString keyGenParams = ""; - /** - * check for errors in keygen dialog input - */ - if ((nameEdit->text()).size() < 5) { - errorString.append(tr(" Name must contain at least five characters. \n")); - } - if (passwordEdit->text() != repeatpwEdit->text()) { - errorString.append(tr(" Password and Repeat don't match. ")); - } - - if (errorString.isEmpty()) { - /** - * create the string for key generation - */ - keyGenParams = "<GnupgKeyParms format=\"internal\">\n" - "Key-Type: DSA\n" - "Key-Length: 1024\n" - "Subkey-Type: ELG-E\n" - "Subkey-Length: " - + keySizeSpinBox->cleanText() + "\n" - "Name-Real: " + nameEdit->text() + "\n"; - if (!(commentEdit->text().isEmpty())) { - keyGenParams += "Name-Comment: " + commentEdit->text() + "\n"; - } - if (!(emailEdit->text().isEmpty())) { - keyGenParams += "Name-Email: " + emailEdit->text() + "\n"; - } - if (expireCheckBox->checkState()) { - keyGenParams += "Expire-Date: 0\n"; - } else { - keyGenParams += "Expire-Date: " + dateEdit->sectionText(QDateTimeEdit::YearSection) + "-" + dateEdit->sectionText(QDateTimeEdit::MonthSection) + "-" + dateEdit->sectionText(QDateTimeEdit::DaySection) + "\n"; - } - if (!(passwordEdit->text().isEmpty())) { - keyGenParams += "Passphrase: " + passwordEdit->text() + "\n"; - } - keyGenParams += "</GnupgKeyParms>"; - - KeyGenThread *kg = new KeyGenThread(keyGenParams, mCtx); - kg->start(); - - genkeyDialog->accept(); - - QDialog *dialog = new QDialog(this, Qt::CustomizeWindowHint | Qt::WindowTitleHint); - dialog->setModal(true); - dialog->setWindowTitle(tr("Generating Key...")); - - QLabel *waitMessage = new QLabel(tr("Collecting random data for key generation.\n This may take a while.\n To speed up the process use your computer\n (e.g. browse the net, listen to music,...)")); - QProgressBar *pb = new QProgressBar(); - pb->setRange(0, 0); - - QVBoxLayout *layout = new QVBoxLayout(dialog); - layout->addWidget(waitMessage); - layout->addWidget(pb); - dialog->setLayout(layout); - - dialog->show(); - - while (kg->isRunning()) { - QCoreApplication::processEvents(); - } - - dialog->close(); - } else { - /** - * create error message - */ - errorLabel->setAutoFillBackground(true); - QPalette error = errorLabel->palette(); - error.setColor(QPalette::Background, "#ff8080"); - errorLabel->setPalette(error); - errorLabel->setText(errorString); - - genkeyDialog->show(); - } -} - -void KeyMgmt::expireBoxChanged() -{ - if (expireCheckBox->checkState()) { - dateEdit->setEnabled(false); - } else { - dateEdit->setEnabled(true); - } -} - -void KeyMgmt::passwordEditChanged() -{ - pwStrengthSlider->setValue(checkPassWordStrength()); - update(); -} - -int KeyMgmt::checkPassWordStrength() -{ - int strength = 0; - if ((passwordEdit->text()).length() > 7) { - strength = strength + 2; - } - if ((passwordEdit->text()).contains(QRegExp("\\d"))) { - strength++; - } - if ((passwordEdit->text()).contains(QRegExp("[a-z]"))) { - strength++; - } - if ((passwordEdit->text()).contains(QRegExp("[A-Z]"))) { - strength++; - } - if ((passwordEdit->text()).contains(QRegExp("\\W"))) { - strength++; - } - - return strength; + KeyGenDialog *keyGenDialog = new KeyGenDialog(mCtx,this); + keyGenDialog->show(); } void KeyMgmt::closeEvent(QCloseEvent *event) @@ -26,6 +26,7 @@ #include "keygenthread.h" #include "keydetailsdialog.h" #include "keyserverimportdialog.h" +#include "keygendialog.h" #include <QtGui> QT_BEGIN_NAMESPACE @@ -62,19 +63,12 @@ public slots: void deleteSelectedKeys(); void deleteCheckedKeys(); void generateKeyDialog(); - void expireBoxChanged(); - void passwordEditChanged(); void showKeyDetails(); -private slots: - void keyGenAccept(); - - private: void createMenus(); void createActions(); void createToolBars(); - int checkPassWordStrength(); void deleteKeysWithWarning(QStringList *uidList); KeyList *mKeyList; |