diff options
Diffstat (limited to '')
-rw-r--r-- | attachments.cpp | 98 | ||||
-rw-r--r-- | context.cpp | 18 | ||||
-rw-r--r-- | context.h | 8 | ||||
-rwxr-xr-x | fileencryptiondialog.cpp | 67 | ||||
-rwxr-xr-x | fileencryptiondialog.h | 18 | ||||
-rw-r--r-- | gpgwin.cpp | 121 | ||||
-rw-r--r-- | gpgwin.h | 40 | ||||
-rw-r--r-- | keygenthread.cpp | 8 | ||||
-rw-r--r-- | keygenthread.h | 21 | ||||
-rw-r--r-- | keylist.cpp | 20 | ||||
-rw-r--r-- | keylist.h | 4 | ||||
-rwxr-xr-x | keymgmt.cpp | 405 | ||||
-rwxr-xr-x | keymgmt.h | 46 |
13 files changed, 446 insertions, 428 deletions
diff --git a/attachments.cpp b/attachments.cpp index 5f78eec..57ca8b9 100644 --- a/attachments.cpp +++ b/attachments.cpp @@ -82,7 +82,7 @@ void Attachments::addFile() QStringList fileNames; if (dialog.exec()) - fileNames = dialog.selectedFiles(); + fileNames = dialog.selectedFiles(); //foreach(QString tmp, fileNames) qDebug() << tmp; m_attachmentList->addItems(fileNames); @@ -108,64 +108,64 @@ void Attachments::encryptFile() //qDebug() << "buffsize: " << inBuffer.size(); if (m_ctx->encrypt(uidList, inBuffer, outBuffer)) { - //qDebug() << "inb: " << inBuffer.toHex(); - //qDebug() << "outb: " << outBuffer->data(); - QString outFilename = QFileDialog::getSaveFileName(this); - if (outFilename.isEmpty()) { + //qDebug() << "inb: " << inBuffer.toHex(); + //qDebug() << "outb: " << outBuffer->data(); + QString outFilename = QFileDialog::getSaveFileName(this); + if (outFilename.isEmpty()) { + qDebug() << "need Filename"; + return; + } + + QFile outfile(outFilename); + if (!outfile.open(QFile::WriteOnly)) { + QMessageBox::warning(this, tr("File"), + tr("Cannot write file %1:\n%2.") + .arg(outFilename) + .arg(outfile.errorString())); + return; + } + + QTextStream out(&outfile); + out << outBuffer->data(); + } + } +} + +void Attachments::decryptFile() +{ + qDebug() << "dec"; + foreach(QString inFilename, *(getSelected())) { + qDebug() << inFilename; + + QFile infile; + infile.setFileName(inFilename); + if (!infile.open(QIODevice::ReadOnly)) { + qDebug() << tr("couldn't open file: ") + inFilename; + } + + QByteArray inBuffer = infile.readAll(); + QByteArray *outBuffer = new QByteArray(); + m_ctx->decrypt(inBuffer, outBuffer); + + QString outFilename = QFileDialog::getSaveFileName(this); + if (outFilename.isEmpty()) { qDebug() << "need Filename"; return; - } + } - QFile outfile(outFilename); - if (!outfile.open(QFile::WriteOnly)) { + QFile outfile(outFilename); + if (!outfile.open(QFile::WriteOnly)) { QMessageBox::warning(this, tr("File"), tr("Cannot write file %1:\n%2.") .arg(outFilename) .arg(outfile.errorString())); return; - } - - QTextStream out(&outfile); - out << outBuffer->data(); } - } -} -void Attachments::decryptFile() -{ - qDebug() << "dec"; - foreach(QString inFilename, *(getSelected())){ - qDebug() << inFilename; - - QFile infile; - infile.setFileName(inFilename); - if (!infile.open(QIODevice::ReadOnly)) { - qDebug() << tr("couldn't open file: ") + inFilename; - } - - QByteArray inBuffer = infile.readAll(); - QByteArray *outBuffer = new QByteArray(); - m_ctx->decrypt(inBuffer, outBuffer); - - QString outFilename = QFileDialog::getSaveFileName(this); - if (outFilename.isEmpty()) { - qDebug() << "need Filename"; - return; - } - - QFile outfile(outFilename); - if (!outfile.open(QFile::WriteOnly)) { - QMessageBox::warning(this, tr("File"), - tr("Cannot write file %1:\n%2.") - .arg(outFilename) - .arg(outfile.errorString())); - return; - } - - QDataStream out(&outfile); - //out << outBuffer; - out.writeRawData(outBuffer->data(), outBuffer->length()); - //qDebug() << "outb: " << outBuffer->toHex(); + QDataStream out(&outfile); + //out << outBuffer; + out.writeRawData(outBuffer->data(), outBuffer->length()); + //qDebug() << "outb: " << outBuffer->toHex(); } diff --git a/context.cpp b/context.cpp index a46fa87..947aacb 100644 --- a/context.cpp +++ b/context.cpp @@ -113,9 +113,9 @@ void Context::importKey(QByteArray inBuffer) */ void Context::generateKey(QString *params) { - err = gpgme_op_genkey(mCtx, params->toAscii().data(), NULL,NULL); - checkErr(err); - emit keyDBChanged(); + err = gpgme_op_genkey(mCtx, params->toAscii().data(), NULL, NULL); + checkErr(err); + emit keyDBChanged(); } /** Export Key to QByteArray @@ -139,7 +139,7 @@ bool Context::exportKeys(QList<QString> *uidList, QByteArray *outBuffer) err = gpgme_op_export(mCtx, uidList->at(i).toAscii().constData(), 0, out); checkErr(err); - read_bytes = gpgme_data_seek (out, 0, SEEK_END); + read_bytes = gpgme_data_seek(out, 0, SEEK_END); err = readToBuffer(out, outBuffer); checkErr(err); @@ -382,9 +382,9 @@ gpgme_error_t Context::passphrase(const char *uid_hint, if (result) { #ifndef _WIN32 - if( write(fd, m_cache.data(), m_cache.length()) == -1) { - qDebug() << "something is terribly broken"; - } + if (write(fd, m_cache.data(), m_cache.length()) == -1) { + qDebug() << "something is terribly broken"; + } #else DWORD written; WriteFile((HANDLE) fd, m_cache.data(), m_cache.length(), &written, 0); @@ -394,8 +394,8 @@ gpgme_error_t Context::passphrase(const char *uid_hint, } #ifndef _WIN32 - if( write(fd, "\n", 1) == -1 ) { - qDebug() << "something is terribly broken"; + if (write(fd, "\n", 1) == -1) { + qDebug() << "something is terribly broken"; } #else DWORD written; @@ -38,7 +38,7 @@ class GpgKey { public: GpgKey() { - privkey=false; + privkey = false; } QString id; QString name; @@ -53,7 +53,7 @@ namespace GpgME class Context : public QObject { - Q_OBJECT + Q_OBJECT public: Context(); // Consttructor @@ -70,8 +70,8 @@ public: void clearCache(); signals: - void keyDBChanged(); - + void keyDBChanged(); + private: gpgme_ctx_t mCtx; gpgme_data_t in, out; diff --git a/fileencryptiondialog.cpp b/fileencryptiondialog.cpp index cc2a280..9f3f393 100755 --- a/fileencryptiondialog.cpp +++ b/fileencryptiondialog.cpp @@ -16,32 +16,32 @@ FileEncryptionDialog::FileEncryptionDialog(GpgME::Context *ctx, QString iconPath) { - + mCtx = ctx; setWindowTitle(tr("Encrypt / Decrypt File")); resize(500, 200); setModal(true); - QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel); - connect(buttonBox,SIGNAL(accepted()),this, SLOT(executeAction())); - connect(buttonBox,SIGNAL(rejected()), this, SLOT(reject())); - + QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + connect(buttonBox, SIGNAL(accepted()), this, SLOT(executeAction())); + connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); + QGroupBox *groupBox1 = new QGroupBox(tr("File")); QGroupBox *groupBox3 = new QGroupBox(tr("Action")); - + /* Setup input & Outputfileselection*/ inputFileEdit = new QLineEdit(); QPushButton *fb1 = new QPushButton(tr("...")); connect(fb1, SIGNAL(clicked()), this, SLOT(selectInputFile())); QLabel *fl1 = new QLabel("Input"); fl1->setBuddy(inputFileEdit); - + outputFileEdit = new QLineEdit(); QPushButton *fb2 = new QPushButton(tr("...")); connect(fb2, SIGNAL(clicked()), this, SLOT(selectOutputFile())); QLabel *fl2 = new QLabel("Output"); fl2->setBuddy(outputFileEdit); - + QGridLayout *gLayout = new QGridLayout(); gLayout->addWidget(fl1, 0, 0); gLayout->addWidget(inputFileEdit, 0, 1); @@ -49,13 +49,13 @@ FileEncryptionDialog::FileEncryptionDialog(GpgME::Context *ctx, QString iconPath gLayout->addWidget(fl2, 1, 0); gLayout->addWidget(outputFileEdit, 1, 1); gLayout->addWidget(fb2, 1, 2); - + /*Setup KeyList*/ mKeyList = new KeyList(mCtx, iconPath); mKeyList->hide(); - mKeyList->setColumnWidth(2,150); - mKeyList->setColumnWidth(3,150); - + mKeyList->setColumnWidth(2, 150); + mKeyList->setColumnWidth(3, 150); + /* Setup Action */ radioEnc = new QRadioButton(tr("&Encrypt")); connect(radioEnc, SIGNAL(clicked()), this, SLOT(showKeyList())); @@ -69,7 +69,7 @@ FileEncryptionDialog::FileEncryptionDialog(GpgME::Context *ctx, QString iconPath groupBox1->setLayout(gLayout); groupBox3->setLayout(hbox1); - + QVBoxLayout *vbox2 = new QVBoxLayout(); vbox2->addWidget(groupBox1); vbox2->addWidget(groupBox3); @@ -77,37 +77,40 @@ FileEncryptionDialog::FileEncryptionDialog(GpgME::Context *ctx, QString iconPath vbox2->addWidget(buttonBox); vbox2->addStretch(0); setLayout(vbox2); - exec(); + exec(); } -void FileEncryptionDialog::selectInputFile() { +void FileEncryptionDialog::selectInputFile() +{ QString infileName = QFileDialog::getOpenFileName(this, tr("Open File"), "", tr("Files") + "All Files (*.*)"); inputFileEdit->insert(infileName); } -void FileEncryptionDialog::selectOutputFile() { +void FileEncryptionDialog::selectOutputFile() +{ QString outfileName = QFileDialog::getSaveFileName(this); - outputFileEdit->insert(outfileName); + outputFileEdit->insert(outfileName); } -void FileEncryptionDialog::executeAction() { - +void FileEncryptionDialog::executeAction() +{ + QFile infile; infile.setFileName(inputFileEdit->text()); if (!infile.open(QIODevice::ReadOnly)) { qDebug() << tr("couldn't open file: ") + inputFileEdit->text(); } - + QByteArray inBuffer = infile.readAll(); QByteArray *outBuffer = new QByteArray(); - + if (radioEnc->isChecked()) { - if(! mCtx->encrypt(mKeyList->getSelected(), inBuffer, outBuffer)) return; + if (! mCtx->encrypt(mKeyList->getSelected(), inBuffer, outBuffer)) return; } - if (radioDec->isChecked()) { - if(! mCtx->decrypt(inBuffer, outBuffer)) return; + if (radioDec->isChecked()) { + if (! mCtx->decrypt(inBuffer, outBuffer)) return; } QFile outfile(outputFileEdit->text()); @@ -118,18 +121,20 @@ void FileEncryptionDialog::executeAction() { .arg(outfile.errorString())); return; } - + QDataStream out(&outfile); out.writeRawData(outBuffer->data(), outBuffer->length()); - + accept(); - QMessageBox::information(0,"Done","Output saved to " + outputFileEdit->text()); + QMessageBox::information(0, "Done", "Output saved to " + outputFileEdit->text()); } -void FileEncryptionDialog::showKeyList() { - mKeyList->show(); +void FileEncryptionDialog::showKeyList() +{ + mKeyList->show(); } -void FileEncryptionDialog::hideKeyList() { - mKeyList->hide(); +void FileEncryptionDialog::hideKeyList() +{ + mKeyList->hide(); } diff --git a/fileencryptiondialog.h b/fileencryptiondialog.h index 97854e8..5b88087 100755 --- a/fileencryptiondialog.h +++ b/fileencryptiondialog.h @@ -12,21 +12,21 @@ class FileEncryptionDialog : public QDialog public: FileEncryptionDialog(GpgME::Context *ctx, QString iconPath); -public slots: - void selectInputFile(); - void selectOutputFile(); - void executeAction(); - void hideKeyList(); - void showKeyList(); +public slots: + void selectInputFile(); + void selectOutputFile(); + void executeAction(); + void hideKeyList(); + void showKeyList(); private: QLineEdit *outputFileEdit; QLineEdit *inputFileEdit; QRadioButton *radioEnc; QRadioButton *radioDec; - + protected: - GpgME::Context *mCtx; - KeyList *mKeyList; + GpgME::Context *mCtx; + KeyList *mKeyList; }; @@ -103,14 +103,14 @@ void GpgWin::createActions() cutAct->setIcon(QIcon(iconPath + "button_cut.png")); cutAct->setShortcut(tr("Ctrl+X")); cutAct->setToolTip(tr("Cut the current selection's contents to the " - "clipboard")); + "clipboard")); connect(cutAct, SIGNAL(triggered()), edit, SLOT(cut())); copyAct = new QAction(tr("&Copy"), this); copyAct->setIcon(QIcon(iconPath + "button_copy.png")); copyAct->setShortcut(tr("Ctrl+C")); copyAct->setToolTip(tr("Copy the current selection's contents to the " - "clipboard")); + "clipboard")); connect(copyAct, SIGNAL(triggered()), edit, SLOT(copy())); selectallAct = new QAction(tr("Select &All"), this); @@ -133,13 +133,13 @@ void GpgWin::createActions() decryptAct->setToolTip(tr("Decrypt Message")); connect(decryptAct, SIGNAL(triggered()), this, SLOT(decrypt())); - fileEncryptionAct = new QAction(tr("&File Encryption"), this); + fileEncryptionAct = new QAction(tr("&File Encryption"), this); fileEncryptionAct->setIcon(QIcon(iconPath + "fileencrytion.png")); fileEncryptionAct->setToolTip(tr("Encrypt/Decrypt File")); connect(fileEncryptionAct, SIGNAL(triggered()), this, SLOT(fileEncryption())); - /** Key Menu - */ + /** Key Menu + */ importKeyFromFileAct = new QAction(tr("&File"), this); importKeyFromFileAct->setIcon(QIcon(iconPath + "misc_doc.png")); importKeyFromFileAct->setToolTip(tr("Import New Key From File")); @@ -164,7 +164,7 @@ void GpgWin::createActions() importKeyDialogAct->setIcon(QIcon(iconPath + "key_import.png")); importKeyDialogAct->setToolTip(tr("Open Import New Key Dialog")); connect(importKeyDialogAct, SIGNAL(triggered()), this, SLOT(importKeyDialog())); - + /** About Menu */ aboutAct = new QAction(tr("&About"), this); @@ -205,7 +205,7 @@ void GpgWin::createMenus() cryptMenu->addSeparator(); cryptMenu->addAction(fileEncryptionAct); - keyMenu = menuBar()->addMenu(tr("&Keys")); + keyMenu = menuBar()->addMenu(tr("&Keys")); importKeyMenu = keyMenu->addMenu(tr("&Import Key From...")); importKeyMenu->setIcon(QIcon(iconPath + "key_import.png")); importKeyMenu->addAction(importKeyFromFileAct); @@ -241,7 +241,7 @@ void GpgWin::createStatusBar() void GpgWin::createDockWindows() { QDockWidget *dock = new QDockWidget(tr("Encrypt for:"), this); - dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea ); + dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); addDockWidget(Qt::RightDockWidgetArea, dock); dock->setWidget(mKeyList); @@ -381,19 +381,19 @@ void GpgWin::about() { QMessageBox::about(this, tr("About ") + qApp->applicationName(), "<center><h2>" + qApp->applicationName() + " " - + qApp->applicationVersion() +"</h2></center>" - +tr("<center>This Application allows you to do simple<br>" - "encryption/decryption of your text-files.<br>" - "It's licensed under the GPL v2.0<br><br>" - "<b>Developer:</b><br>" - "Bene, Heimer, Juergen, Nils, Ubbo<br><br>" - "If you have any questions and/or<br>" - "suggestions, contact us at<br>" - "gpg4usb at cpunk.de</a><br><br>" - "or feel free to meet us in our channel at<br>" - "gpg4usb at conference.jabber.ccc.de<br><br>" - "and always remember:<br>" - "cpunk is NOT a bot...</center>")); + + qApp->applicationVersion() + "</h2></center>" + + tr("<center>This Application allows you to do simple<br>" + "encryption/decryption of your text-files.<br>" + "It's licensed under the GPL v2.0<br><br>" + "<b>Developer:</b><br>" + "Bene, Heimer, Juergen, Nils, Ubbo<br><br>" + "If you have any questions and/or<br>" + "suggestions, contact us at<br>" + "gpg4usb at cpunk.de</a><br><br>" + "or feel free to meet us in our channel at<br>" + "gpg4usb at conference.jabber.ccc.de<br><br>" + "and always remember:<br>" + "cpunk is NOT a bot...</center>")); } void GpgWin::encrypt() @@ -428,7 +428,7 @@ void GpgWin::decrypt() void GpgWin::preventNoDataErr(QByteArray *in) { int block_start = in->indexOf("-----BEGIN PGP MESSAGE-----"); - if(block_start > 0 && in->at(block_start - 1) != '\n') { + if (block_start > 0 && in->at(block_start - 1) != '\n') { in->insert(block_start, '\n'); } } @@ -448,7 +448,7 @@ void GpgWin::importKeyFromFile() { QFile file; QByteArray inBuffer; - + QString fileName = QFileDialog::getOpenFileName(this, tr("Open Key"), "", tr("Key Files") + " (*.asc *.txt);;All Files (*.*)"); if (! fileName.isNull()) { file.setFileName(fileName); @@ -461,52 +461,54 @@ void GpgWin::importKeyFromFile() } -void GpgWin::openKeyManagement() { - if(!keyMgmt) { - keyMgmt = new KeyMgmt(mCtx, iconPath); - keyMgmt->resize(800,400); - } +void GpgWin::openKeyManagement() +{ + if (!keyMgmt) { + keyMgmt = new KeyMgmt(mCtx, iconPath); + keyMgmt->resize(800, 400); + } keyMgmt->show(); - keyMgmt->raise(); - keyMgmt->activateWindow(); + keyMgmt->raise(); + keyMgmt->activateWindow(); } -void GpgWin::importKeyDialog() { +void GpgWin::importKeyDialog() +{ - QDialog *dialog = new QDialog(); + QDialog *dialog = new QDialog(); - dialog->setWindowTitle(tr("Import Key")); - dialog->setModal(true); + dialog->setWindowTitle(tr("Import Key")); + dialog->setModal(true); - QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel); + QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); - connect(buttonBox,SIGNAL(accepted()),dialog, SLOT(accept())); - connect(buttonBox,SIGNAL(rejected()), dialog, SLOT(reject())); + connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept())); + connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject())); - QGroupBox *groupBox = new QGroupBox(tr("Import Key From...")); - QRadioButton *radio1 = new QRadioButton(tr("&File")); - QRadioButton *radio2 = new QRadioButton(tr("&Editor")); - QRadioButton *radio3 = new QRadioButton(tr("&Clipboard")); - radio1->setChecked(true); + QGroupBox *groupBox = new QGroupBox(tr("Import Key From...")); + QRadioButton *radio1 = new QRadioButton(tr("&File")); + QRadioButton *radio2 = new QRadioButton(tr("&Editor")); + QRadioButton *radio3 = new QRadioButton(tr("&Clipboard")); + radio1->setChecked(true); - QVBoxLayout *vbox1 = new QVBoxLayout(); - vbox1->addWidget(radio1); - vbox1->addWidget(radio2); - vbox1->addWidget(radio3); + QVBoxLayout *vbox1 = new QVBoxLayout(); + vbox1->addWidget(radio1); + vbox1->addWidget(radio2); + vbox1->addWidget(radio3); - groupBox->setLayout(vbox1); + groupBox->setLayout(vbox1); - QVBoxLayout *vbox2 = new QVBoxLayout(); - vbox2->addWidget(groupBox); - vbox2->addWidget(buttonBox); + QVBoxLayout *vbox2 = new QVBoxLayout(); + vbox2->addWidget(groupBox); + vbox2->addWidget(buttonBox); - dialog->setLayout(vbox2); + dialog->setLayout(vbox2); - if(dialog->exec() == QDialog::Accepted ) { - if (radio1->isChecked()) importKeyFromFile(); - if (radio2->isChecked()) importKeyFromEdit(); - if (radio3->isChecked()) importKeyFromClipboard(); - } + if (dialog->exec() == QDialog::Accepted) { + if (radio1->isChecked()) importKeyFromFile(); + if (radio2->isChecked()) importKeyFromEdit(); + if (radio3->isChecked()) importKeyFromClipboard(); + } } @@ -530,8 +532,9 @@ void GpgWin::appendSelectedKeys() } -void GpgWin::fileEncryption() { - +void GpgWin::fileEncryption() +{ + new FileEncryptionDialog(mCtx, iconPath); - + } @@ -64,7 +64,7 @@ public slots: void importKeyFromClipboard(); void importKeyDialog(); void deleteSelectedKeys(); - void appendSelectedKeys(); + void appendSelectedKeys(); void openKeyManagement(); void print(); void about(); @@ -72,7 +72,7 @@ public slots: bool saveAs(); void open(); void fileEncryption(); - + private: void createActions(); void createMenus(); @@ -85,7 +85,7 @@ private: bool maybeSave(); void preventNoDataErr(QByteArray *in); QString strippedName(const QString &fullFileName); - + QPlainTextEdit *edit; QMenu *fileMenu; QMenu *editMenu; @@ -110,7 +110,7 @@ private: QAction *importKeyFromEditAct; QAction *importKeyFromClipboardAct; QAction *deleteSelectedKeysAct; - QAction *appendSelectedKeysAct; + QAction *appendSelectedKeysAct; QAction *openKeyManagementAct; QAction *copyAct; QAction *cutAct; @@ -118,26 +118,26 @@ private: QAction *selectallAct; QAction *aboutAct; QAction *fileEncryptionAct; - - QLineEdit *nameEdit; - QLineEdit *emailEdit; - QLineEdit *commentEdit; - QLineEdit *passwordEdit; - QLineEdit *repeatpwEdit; - QSpinBox *keysizeSpinBox; - QLabel *nameLabel; - QLabel *emailLabel; - QLabel *commentLabel; - QLabel *keysizeLabel; - QLabel *passwordLabel; - QLabel *repeatpwLabel; - QLabel *errorLabel; - + + QLineEdit *nameEdit; + QLineEdit *emailEdit; + QLineEdit *commentEdit; + QLineEdit *passwordEdit; + QLineEdit *repeatpwEdit; + QSpinBox *keysizeSpinBox; + QLabel *nameLabel; + QLabel *emailLabel; + QLabel *commentLabel; + QLabel *keysizeLabel; + QLabel *passwordLabel; + QLabel *repeatpwLabel; + QLabel *errorLabel; + QString curFile; KeyList *mKeyList; Attachments *mAttachments; GpgME::Context *mCtx; QString iconPath; - KeyMgmt *keyMgmt; + KeyMgmt *keyMgmt; }; diff --git a/keygenthread.cpp b/keygenthread.cpp index 5dbb194..ee858fd 100644 --- a/keygenthread.cpp +++ b/keygenthread.cpp @@ -25,12 +25,12 @@ KeyGenThread::KeyGenThread(QString keyGenParams, GpgME::Context *ctx) { - this->keyGenParams=keyGenParams; - this->ctx=ctx; - abort=false; + this->keyGenParams = keyGenParams; + this->ctx = ctx; + abort = false; } void KeyGenThread::run() { - ctx->generateKey(&keyGenParams); + ctx->generateKey(&keyGenParams); } diff --git a/keygenthread.h b/keygenthread.h index 06dfea1..ed69785 100644 --- a/keygenthread.h +++ b/keygenthread.h @@ -29,22 +29,23 @@ class QMessageBox; #include "context.h" -class KeyGenThread : public QThread { - Q_OBJECT +class KeyGenThread : public QThread +{ + Q_OBJECT public: - KeyGenThread(QString keyGenParams, GpgME::Context *ctx); + KeyGenThread(QString keyGenParams, GpgME::Context *ctx); signals: - void keyGenerated(); - + void keyGenerated(); + private: - QString keyGenParams; - GpgME::Context *ctx; - bool abort; - QMutex mutex; + QString keyGenParams; + GpgME::Context *ctx; + bool abort; + QMutex mutex; protected: - void run(); + void run(); }; diff --git a/keylist.cpp b/keylist.cpp index 1aef56b..4e51e31 100644 --- a/keylist.cpp +++ b/keylist.cpp @@ -21,7 +21,7 @@ #include "keylist.h" -KeyList::KeyList(GpgME::Context* ctx, QString iconpath, QWidget *parent) +KeyList::KeyList(GpgME::Context *ctx, QString iconpath, QWidget *parent) : QWidget(parent) { mCtx = ctx; @@ -33,7 +33,7 @@ KeyList::KeyList(GpgME::Context* ctx, QString iconpath, QWidget *parent) mKeyList->setShowGrid(false); mKeyList->setColumnWidth(0, 24); mKeyList->setColumnWidth(1, 20); - mKeyList->sortByColumn(2,Qt::AscendingOrder); + mKeyList->sortByColumn(2, Qt::AscendingOrder); mKeyList->setSelectionBehavior(QAbstractItemView::SelectRows); mKeyList->setColumnHidden(4, true); // tableitems not editable @@ -56,7 +56,7 @@ KeyList::KeyList(GpgME::Context* ctx, QString iconpath, QWidget *parent) setLayout(layout); popupMenu = new QMenu(this); - connect(mCtx, SIGNAL(keyDBChanged()), this, SLOT(refresh())); + connect(mCtx, SIGNAL(keyDBChanged()), this, SLOT(refresh())); refresh(); } @@ -69,7 +69,7 @@ void KeyList::refresh() GpgKeyList keys = mCtx->listKeys(); mKeyList->setRowCount(keys.size()); - int row=0; + int row = 0; GpgKeyList::iterator it = keys.begin(); while (it != keys.end()) { @@ -78,8 +78,8 @@ void KeyList::refresh() tmp0->setCheckState(Qt::Unchecked); mKeyList->setItem(row, 0, tmp0); - if(it->privkey) { - QTableWidgetItem *tmp1 = new QTableWidgetItem(QIcon(iconPath + "kgpg_key2.png"),""); + if (it->privkey) { + QTableWidgetItem *tmp1 = new QTableWidgetItem(QIcon(iconPath + "kgpg_key2.png"), ""); mKeyList->setItem(row, 1, tmp1); } QTableWidgetItem *tmp2 = new QTableWidgetItem(it->name); @@ -101,8 +101,8 @@ QList<QString> *KeyList::getChecked() { QList<QString> *ret = new QList<QString>(); for (int i = 0; i < mKeyList->rowCount(); i++) { - if (mKeyList->item(i,0)->checkState() == Qt::Checked) { - *ret << mKeyList->item(i,4)->text(); + if (mKeyList->item(i, 0)->checkState() == Qt::Checked) { + *ret << mKeyList->item(i, 4)->text(); } } return ret; @@ -113,8 +113,8 @@ QList<QString> *KeyList::getSelected() QList<QString> *ret = new QList<QString>(); for (int i = 0; i < mKeyList->rowCount(); i++) { - if (mKeyList->item(i,0)->isSelected() == 1) { - *ret << mKeyList->item(i,4)->text(); + if (mKeyList->item(i, 0)->isSelected() == 1) { + *ret << mKeyList->item(i, 4)->text(); } } return ret; @@ -42,13 +42,13 @@ public: void setColumnWidth(int row, int size); void addMenuAction(QAction *act); - KeyList(GpgME::Context* ctx, QString iconpath, QWidget *parent = 0); + KeyList(GpgME::Context *ctx, QString iconpath, QWidget *parent = 0); QList<QString> *getChecked(); QList<QString> *getSelected(); public slots: void refresh(); - + private: GpgME::Context *mCtx; QTableWidget *mKeyList; diff --git a/keymgmt.cpp b/keymgmt.cpp index 2487a00..d93c081 100755 --- a/keymgmt.cpp +++ b/keymgmt.cpp @@ -29,11 +29,11 @@ KeyMgmt::KeyMgmt(GpgME::Context *ctx, QString iconpath) { mCtx = ctx; mIconPath = iconpath; - + /* the list of Keys available*/ mKeyList = new KeyList(mCtx, mIconPath); - mKeyList->setColumnWidth(2,250); - mKeyList->setColumnWidth(3,250); + mKeyList->setColumnWidth(2, 250); + mKeyList->setColumnWidth(3, 250); setCentralWidget(mKeyList); createActions(); @@ -82,7 +82,7 @@ void KeyMgmt::createActions() deleteCheckedKeysAct->setToolTip(tr("Delete the Checked keys")); deleteCheckedKeysAct->setIcon(QIcon(mIconPath + "button_cancel.png")); connect(deleteCheckedKeysAct, SIGNAL(triggered()), this, SLOT(deleteCheckedKeys())); - + generateKeyDialogAct = new QAction(tr("Generate Key"), this); generateKeyDialogAct->setToolTip(tr("Generate New Key")); generateKeyDialogAct->setIcon(QIcon(mIconPath + "key_generate.png")); @@ -93,7 +93,7 @@ void KeyMgmt::createMenus() { fileMenu = menuBar()->addMenu(tr("&File")); fileMenu->addAction(closeAct); - + keyMenu = menuBar()->addMenu(tr("&Key")); keyMenu->addAction(importKeyFromFileAct); keyMenu->addAction(importKeyFromClipboardAct); @@ -152,229 +152,238 @@ void KeyMgmt::deleteCheckedKeys() void KeyMgmt::exportKeyToFile() { QByteArray *keyArray = new QByteArray(); - if (!mCtx->exportKeys(mKeyList->getChecked(), keyArray)) { - return; - } + if (!mCtx->exportKeys(mKeyList->getChecked(), keyArray)) { + return; + } QString fileName = QFileDialog::getSaveFileName(this, tr("Export Key To File"), "", tr("Key Files") + " (*.asc *.txt);;All Files (*.*)"); - QFile file(fileName); - if (!file.open( QIODevice::WriteOnly |QIODevice::Text)) + QFile file(fileName); + if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) return; - QTextStream stream( &file ); - stream << *keyArray; - file.close(); - delete keyArray; + QTextStream stream(&file); + stream << *keyArray; + file.close(); + delete keyArray; } void KeyMgmt::exportKeyToClipboard() { QByteArray *keyArray = new QByteArray(); QClipboard *cb = QApplication::clipboard(); - if (!mCtx->exportKeys(mKeyList->getChecked(), keyArray)) { - return; - } + if (!mCtx->exportKeys(mKeyList->getChecked(), keyArray)) { + return; + } cb->setText(*keyArray); - delete keyArray; + delete keyArray; } -void KeyMgmt::generateKeyDialog() +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(512,8192); - keySizeSpinBox->setValue(1024); - - 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 ) { - - } + 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(512, 8192); + keySizeSpinBox->setValue(1024); + + 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=""; + + QString errorString = ""; + QString keyGenParams = ""; /** * check for errors in keygen dialog input */ - if ((nameEdit->text()).size() < 5 ) { - errorString.append(" Name must contain at least five characters. \n"); - } - if (passwordEdit->text() != repeatpwEdit->text()) { - errorString.append(" 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: " - +keySizeSpinBox->cleanText()+"\n" - "Subkey-Type: ELG-E\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" - "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(); - } + if ((nameEdit->text()).size() < 5) { + errorString.append(" Name must contain at least five characters. \n"); + } + if (passwordEdit->text() != repeatpwEdit->text()) { + errorString.append(" 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: " + + keySizeSpinBox->cleanText() + "\n" + "Subkey-Type: ELG-E\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" + "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); - } - + if (expireCheckBox->checkState()) { + dateEdit->setEnabled(false); + } else { + dateEdit->setEnabled(true); + } + } void KeyMgmt::passwordEditChanged() { - pwStrengthSlider->setValue(checkPassWordStrength()); - update(); + 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; + 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; } @@ -55,9 +55,9 @@ public slots: void deleteCheckedKeys(); void deleteSelectedKeys(); void generateKeyDialog(); - void expireBoxChanged(); - void passwordEditChanged(); - + void expireBoxChanged(); + void passwordEditChanged(); + private slots: void keyGenAccept(); @@ -83,30 +83,30 @@ private: QAction *deleteSelectedKeysAct; QAction *generateKeyDialogAct; QAction *closeAct; - KeyGenThread *keyGenThread; + KeyGenThread *keyGenThread; QMessageBox msgbox; /** - * Variables For Key-Generation + * Variables For Key-Generation */ - QLabel *nameLabel; - QLabel *emailLabel; - QLabel *commentLabel; - QLabel *keySizeLabel; - QLabel *passwordLabel; - QLabel *repeatpwLabel; - QLabel *errorLabel; - QLabel *dateLabel; - QLabel *expireLabel; - QLabel *pwStrengthLabel; + 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; + QLineEdit *emailEdit; + QLineEdit *commentEdit; + QLineEdit *passwordEdit; + QLineEdit *repeatpwEdit; + QSpinBox *keySizeSpinBox; + QDateTimeEdit *dateEdit; + QCheckBox *expireCheckBox; + QSlider *pwStrengthSlider; }; #endif // __KEYMGMT_H__ |