diff options
-rw-r--r-- | context.cpp | 75 | ||||
-rw-r--r-- | context.h | 1 | ||||
-rw-r--r-- | gpgwin.cpp | 26 | ||||
-rw-r--r-- | gpgwin.h | 6 |
4 files changed, 103 insertions, 5 deletions
diff --git a/context.cpp b/context.cpp index ebdb042..e6c0aae 100644 --- a/context.cpp +++ b/context.cpp @@ -602,8 +602,83 @@ void Context::decryptVerify(QByteArray in) { void Context::sign(const QByteArray &inBuffer, QByteArray *outBuffer) { + gpgme_error_t err; + gpgme_data_t in, out; + gpgme_sign_result_t result; + + err = gpgme_data_new_from_mem (&in, "Hallo Leute\n", 12, 0); + checkErr(err); + + err = gpgme_data_new (&out); + checkErr(err); +/* + `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 = gpgme_op_sign (mCtx, in, out, GPGME_SIG_MODE_NORMAL); + err = gpgme_op_sign (mCtx, in, out, GPGME_SIG_MODE_CLEAR); + checkErr(err); + result = gpgme_op_sign_result (mCtx); + + err = readToBuffer(out, outBuffer); + + qDebug() << "sig: " << QString::fromUtf8(*outBuffer); + } +bool Context::sign(QStringList *uidList, const QByteArray &inBuffer, QByteArray *outBuffer ) { + + gpgme_error_t err; + gpgme_data_t in, out; + gpgme_sign_result_t result; + + if (uidList->count() == 0) { + QMessageBox::critical(0, tr("No Key Selected"), tr("No Key Selected")); + return false; + } + + // at start or end? + gpgme_signers_clear(mCtx); + + //gpgme_encrypt_result_t e_result; + gpgme_key_t signers[uidList->count()+1]; + + + // TODO: do we really need array? adding one key in loop should be ok + for (int i = 0; i < uidList->count(); i++) { + // the last 0 is for public keys, 1 would return private keys + gpgme_op_keylist_start(mCtx, uidList->at(i).toAscii().constData(), 0); + gpgme_op_keylist_next(mCtx, &signers[i]); + gpgme_op_keylist_end(mCtx); + + err = gpgme_signers_add (mCtx, signers[i]); + checkErr(err); + } + + err = gpgme_data_new_from_mem(&in, inBuffer.data(), inBuffer.size(), 1); + checkErr(err); + err = gpgme_data_new (&out); + checkErr(err); + + err = gpgme_op_sign (mCtx, in, out, GPGME_SIG_MODE_CLEAR); + checkErr (err); + result = gpgme_op_sign_result (mCtx); + err = readToBuffer(out, outBuffer); + + gpgme_data_release(in); + gpgme_data_release(out); + + return (err == GPG_ERR_NO_ERROR); +} } @@ -73,6 +73,7 @@ public: void verify(QByteArray in); void decryptVerify(QByteArray in); void sign(const QByteArray &inBuffer, QByteArray *outBuffer); + bool sign(QStringList *uidList, const QByteArray &inBuffer, QByteArray *outBuffer ); signals: void keyDBChanged(); @@ -218,6 +218,12 @@ void GpgWin::createActions() fileEncryptionAct->setToolTip(tr("Encrypt/Decrypt File")); connect(fileEncryptionAct, SIGNAL(triggered()), this, SLOT(fileEncryption())); + signAct = new QAction(tr("&Sign"), this); + //signAct->setIcon(QIcon(iconPath + "encrypted.png")); + //signAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_E)); + signAct->setToolTip(tr("Sign Message")); + connect(signAct, SIGNAL(triggered()), this, SLOT(sign())); + /** Key Menu */ importKeyFromFileAct = new QAction(tr("&File"), this); @@ -288,6 +294,7 @@ void GpgWin::createMenus() cryptMenu = menuBar()->addMenu(tr("&Crypt")); cryptMenu->addAction(encryptAct); cryptMenu->addAction(decryptAct); + cryptMenu->addAction(signAct); cryptMenu->addSeparator(); cryptMenu->addAction(fileEncryptionAct); @@ -540,7 +547,7 @@ void GpgWin::encrypt() void GpgWin::decrypt() { QByteArray *decrypted = new QByteArray(); - QByteArray text = edit->toPlainText().toAscii(); + QByteArray text = edit->toPlainText().toAscii(); // TODO: toUtf8() here? preventNoDataErr(&text); mCtx->decrypt(text, decrypted); if (!decrypted->isEmpty()) { @@ -689,8 +696,6 @@ void GpgWin::importKeyFromFile() void GpgWin::openKeyManagement() { - mCtx->verify(QByteArray()); - if (!keyMgmt) { keyMgmt = new KeyMgmt(mCtx, iconPath); // keyMgmt->resize(800, 400); @@ -700,6 +705,21 @@ void GpgWin::openKeyManagement() keyMgmt->activateWindow(); } +void GpgWin::sign() { + // test-stuff that does not belong here ;-) + //mCtx->verify(QByteArray()); + //mCtx->sign(QByteArray(), new QByteArray()); + // end of test + + QStringList *uidList = mKeyList->getChecked(); + + QByteArray *tmp = new QByteArray(); + if (mCtx->sign(uidList, edit->toPlainText().toUtf8(), tmp)) { + QString *tmp2 = new QString(*tmp); + edit->setPlainText(*tmp2); + } +} + void GpgWin::importKeyDialog() { @@ -81,6 +81,7 @@ public slots: void openSettingsDialog(); void openTutorial(); void checkAttachmentFolder(); + void sign(); // void dropEvent(QDropEvent *event); private: @@ -121,6 +122,7 @@ private: QAction *quitAct; QAction *encryptAct; QAction *decryptAct; + QAction *signAct; QAction *importKeyDialogAct; QAction *importKeyFromFileAct; QAction *importKeyFromEditAct; @@ -131,8 +133,8 @@ private: QAction *cutAct; QAction *pasteAct; QAction *selectallAct; - QAction *undoAct; - QAction *redoAct; + QAction *undoAct; + QAction *redoAct; QAction *aboutAct; QAction *fileEncryptionAct; QAction *openSettingsAct; |