aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUbbo Veentjer <[email protected]>2017-12-30 23:50:55 +0000
committerUbbo Veentjer <[email protected]>2017-12-30 23:50:55 +0000
commitd327c06ebb5138359e875e8f9a7ac242de45c158 (patch)
tree653664e755ddbfcc00389e2a0075a2a2386536b1
parentrecommit of a06539af3448396f56a44d6859f2a54b787cdd8d (sign files integrated) (diff)
downloadgpg4usb-d327c06ebb5138359e875e8f9a7ac242de45c158.tar.gz
gpg4usb-d327c06ebb5138359e875e8f9a7ac242de45c158.zip
verify files readded (4ecc173307c8c1ed13f28b6955484a484a25402a to 7c874c55c8242baaa770c46718a5c66b3bf8284a)
-rwxr-xr-xfileencryptiondialog.cpp65
-rwxr-xr-xfileencryptiondialog.h9
-rw-r--r--gpgcontext.cpp14
-rw-r--r--gpgcontext.h2
-rw-r--r--verifydetailsdialog.cpp35
-rw-r--r--verifydetailsdialog.h5
-rw-r--r--verifynotification.cpp6
7 files changed, 113 insertions, 23 deletions
diff --git a/fileencryptiondialog.cpp b/fileencryptiondialog.cpp
index b4eb6da..d81d3fd 100755
--- a/fileencryptiondialog.cpp
+++ b/fileencryptiondialog.cpp
@@ -29,14 +29,16 @@ FileEncryptionDialog::FileEncryptionDialog(GpgME::GpgContext *ctx, QStringList k
mCtx = ctx;
if (mAction == Decrypt) {
setWindowTitle(tr("Decrypt File"));
+ resize(500, 200);
} else if (mAction == Encrypt) {
setWindowTitle(tr("Encrypt File"));
- resize(500, 300);
+ resize(500, 400);
} else if (mAction == Sign) {
setWindowTitle(tr("Sign File"));
- resize(500, 300);
+ resize(500, 400);
} else if (mAction == Verify) {
setWindowTitle(tr("Verify File"));
+ resize(500, 200);
}
setModal(true);
@@ -64,11 +66,21 @@ FileEncryptionDialog::FileEncryptionDialog(GpgME::GpgContext *ctx, QStringList k
gLayout->addWidget(fl1, 0, 0);
gLayout->addWidget(inputFileEdit, 0, 1);
gLayout->addWidget(fb1, 0, 2);
- // verify does not need outfile
+ // verify does not need outfile, but signature file
if(mAction != Verify) {
gLayout->addWidget(fl2, 1, 0);
gLayout->addWidget(outputFileEdit, 1, 1);
gLayout->addWidget(fb2, 1, 2);
+ } else {
+ signFileEdit = new QLineEdit();
+ QPushButton *sfb1 = new QPushButton("...");
+ connect(sfb1, SIGNAL(clicked()), this, SLOT(slotSelectSignFile()));
+ QLabel *sfl1 = new QLabel(tr("Signature"));
+ sfl1->setBuddy(signFileEdit);
+
+ gLayout->addWidget(sfl1, 1, 0);
+ gLayout->addWidget(signFileEdit, 1, 1);
+ gLayout->addWidget(sfb1, 1, 2);
}
groupBox1->setLayout(gLayout);
@@ -79,9 +91,13 @@ FileEncryptionDialog::FileEncryptionDialog(GpgME::GpgContext *ctx, QStringList k
mKeyList->setColumnWidth(3, 150);
mKeyList->setChecked(&keyList);
+ statusLabel = new QLabel();
+ statusLabel->setStyleSheet("QLabel {color: red;}");
+
QVBoxLayout *vbox2 = new QVBoxLayout();
vbox2->addWidget(groupBox1);
vbox2->addWidget(mKeyList);
+ vbox2->addWidget(statusLabel);
vbox2->addWidget(buttonBox);
vbox2->addStretch(0);
setLayout(vbox2);
@@ -105,11 +121,15 @@ void FileEncryptionDialog::slotSelectInputFile()
inputFileEdit->setText(infileName);
// try to find a matching output-filename, if not yet done
- if (infileName > 0 && outputFileEdit->text().size() == 0) {
+ if (infileName > 0
+ && outputFileEdit->text().size() == 0
+ && signFileEdit->text().size() == 0) {
if (mAction == Encrypt) {
outputFileEdit->setText(infileName + ".asc");
} else if (mAction == Sign) {
outputFileEdit->setText(infileName + ".sig");
+ } else if (mAction == Verify) {
+ signFileEdit->setText(infileName + ".sig");
} else {
if (infileName.endsWith(".asc", Qt::CaseInsensitive)) {
QString ofn = infileName;
@@ -134,13 +154,33 @@ void FileEncryptionDialog::slotSelectOutputFile()
}
+void FileEncryptionDialog::slotSelectSignFile()
+{
+ QString path = "";
+ if (signFileEdit->text().size() > 0) {
+ path = QFileInfo(signFileEdit->text()).absolutePath();
+ }
+
+ QString signfileName = QFileDialog::getSaveFileName(this, tr("Open File"),path, NULL ,NULL ,QFileDialog::DontConfirmOverwrite);
+ signFileEdit->setText(signfileName);
+
+ if (inputFileEdit->text().size() == 0 && signfileName.endsWith(".sig", Qt::CaseInsensitive)) {
+ QString sfn = signfileName;
+ sfn.chop(4);
+ inputFileEdit->setText(sfn);
+ }
+
+}
+
void FileEncryptionDialog::slotExecuteAction()
{
QFile infile;
infile.setFileName(inputFileEdit->text());
if (!infile.open(QIODevice::ReadOnly)) {
- qDebug() << tr("Couldn't Open file: ") + inputFileEdit->text();
+ statusLabel->setText( tr("Couldn't open file"));
+ inputFileEdit->setStyleSheet("QLineEdit { background: yellow }");
+ return;
}
QByteArray inBuffer = infile.readAll();
@@ -155,7 +195,20 @@ void FileEncryptionDialog::slotExecuteAction()
}
if( mAction == Sign ) {
- mCtx->sign(mKeyList->getChecked(), inBuffer, outBuffer, true);
+ if(! mCtx->sign(mKeyList->getChecked(), inBuffer, outBuffer, true)) return;
+ }
+
+ if( mAction == Verify ) {
+ QFile signfile;
+ signfile.setFileName(signFileEdit->text());
+ if (!signfile.open(QIODevice::ReadOnly)) {
+ statusLabel->setText( tr("Couldn't open file"));
+ signFileEdit->setStyleSheet("QLineEdit { background: yellow }");
+ return;
+ }
+ QByteArray signBuffer = signfile.readAll();
+ new VerifyDetailsDialog(this, mCtx, mKeyList, &inBuffer, &signBuffer);
+ return;
}
QFile outfile(outputFileEdit->text());
diff --git a/fileencryptiondialog.h b/fileencryptiondialog.h
index f634743..af6edff 100755
--- a/fileencryptiondialog.h
+++ b/fileencryptiondialog.h
@@ -24,6 +24,7 @@
#include "gpgcontext.h"
#include "keylist.h"
+#include "verifydetailsdialog.h"
QT_BEGIN_NAMESPACE
class QDialog;
@@ -81,6 +82,12 @@ public slots:
/**
* @brief
*
+ * @fn selectSignFile
+ */
+ void slotSelectSignFile();
+ /**
+ * @brief
+ *
* @fn executeAction
*/
void slotExecuteAction();
@@ -100,7 +107,9 @@ public slots:
private:
QLineEdit *outputFileEdit; /**< TODO */
QLineEdit *inputFileEdit; /**< TODO */
+ QLineEdit *signFileEdit; /**< TODO */
DialogAction mAction; /**< TODO */
+ QLabel *statusLabel; /**< TODO */
protected:
GpgME::GpgContext *mCtx; /**< TODO */
KeyList *mKeyList; /**< TODO */
diff --git a/gpgcontext.cpp b/gpgcontext.cpp
index b9c2567..8f7c07e 100644
--- a/gpgcontext.cpp
+++ b/gpgcontext.cpp
@@ -590,12 +590,14 @@ void GpgContext::executeGpgCommand(QStringList arguments, QByteArray *stdOut, QB
}
/***
+ * if sigbuffer not set, the inbuffer should contain signed text
+ *
* TODO: return type should contain:
* -> list of sigs
* -> valid
* -> errors
*/
-gpgme_signature_t GpgContext::verify(QByteArray inBuffer) {
+gpgme_signature_t GpgContext::verify(QByteArray *inBuffer, QByteArray *sigBuffer) {
int error=0;
gpgme_data_t in;
@@ -603,10 +605,16 @@ gpgme_signature_t GpgContext::verify(QByteArray inBuffer) {
gpgme_signature_t sign;
gpgme_verify_result_t result;
- err = gpgme_data_new_from_mem(&in, inBuffer.data(), inBuffer.size(), 1);
+ err = gpgme_data_new_from_mem(&in, inBuffer->data(), inBuffer->size(), 1);
checkErr(err);
- err = gpgme_op_verify (mCtx, in, NULL, in);
+ if (sigBuffer != NULL ) {
+ gpgme_data_t sigdata;
+ err = gpgme_data_new_from_mem(&sigdata, sigBuffer->data(), sigBuffer->size(), 1);
+ err = gpgme_op_verify (mCtx, sigdata, in, NULL);
+ } else {
+ err = gpgme_op_verify (mCtx, in, NULL, in);
+ }
error = checkErr(err);
if (error != 0) {
diff --git a/gpgcontext.h b/gpgcontext.h
index a01ff8d..5b8f93c 100644
--- a/gpgcontext.h
+++ b/gpgcontext.h
@@ -119,7 +119,7 @@ public:
void clearPasswordCache();
void exportSecretKey(QString uid, QByteArray *outBuffer);
gpgme_key_t getKeyDetails(QString uid);
- gpgme_signature_t verify(QByteArray in);
+ gpgme_signature_t verify(QByteArray *inBuffer, QByteArray *sigBuffer = NULL);
// void decryptVerify(QByteArray in);
bool sign(QStringList *uidList, const QByteArray &inBuffer, QByteArray *outBuffer, bool detached = false);
/**
diff --git a/verifydetailsdialog.cpp b/verifydetailsdialog.cpp
index 67037e0..fc9ab6c 100644
--- a/verifydetailsdialog.cpp
+++ b/verifydetailsdialog.cpp
@@ -21,12 +21,15 @@
#include "verifydetailsdialog.h"
-VerifyDetailsDialog::VerifyDetailsDialog(QWidget *parent, GpgME::GpgContext* ctx, KeyList* keyList, QTextEdit *edit) :
+VerifyDetailsDialog::VerifyDetailsDialog(QWidget *parent, GpgME::GpgContext* ctx, KeyList* keyList, QByteArray* inputData, QByteArray* inputSignature) :
QDialog(parent)
{
mCtx = ctx;
mKeyList = keyList;
- mTextpage = edit;
+ //mTextpage = edit;
+ mInputData = inputData;
+ mInputSignature = inputSignature;
+
this->setWindowTitle(tr("Signaturedetails"));
connect(mCtx, SIGNAL(keyDBChanged()), this, SLOT(slotRefresh()));
@@ -47,10 +50,25 @@ void VerifyDetailsDialog::slotRefresh()
QVBoxLayout *mVboxLayout = new QVBoxLayout(mVbox);
mainLayout->addWidget(mVbox);
+ // Button Box for close button
+ buttonBox = new QDialogButtonBox(QDialogButtonBox::Close);
+ connect(buttonBox, SIGNAL(rejected()), this, SLOT(close()));
+
// Get signature information of current text
- QByteArray text = mTextpage->toPlainText().toUtf8();
- mCtx->preventNoDataErr(&text);
- gpgme_signature_t sign = mCtx->verify(text);
+ //QByteArray text = mTextpage->toPlainText().toUtf8();
+ //mCtx->preventNoDataErr(&text);
+ gpgme_signature_t sign;
+ if(mInputSignature != 0) {
+ sign = mCtx->verify(mInputData, mInputSignature);
+ } else {
+ sign = mCtx->verify(mInputData);
+ }
+
+ if(sign==0) {
+ mVboxLayout->addWidget(new QLabel(tr("No valid input found")));
+ mVboxLayout->addWidget(buttonBox);
+ return;
+ }
// Get timestamp of signature of current text
QDateTime timestamp;
@@ -59,8 +77,10 @@ void VerifyDetailsDialog::slotRefresh()
// Set the title widget depending on sign status
if(gpg_err_code(sign->status) == GPG_ERR_BAD_SIGNATURE) {
mVboxLayout->addWidget(new QLabel(tr("Error Validating signature")));
+ } else if (mInputSignature != 0) {
+ mVboxLayout->addWidget(new QLabel(tr("File was signed on <br/> %1 by:<br/>").arg(timestamp.toString(Qt::SystemLocaleLongDate))));
} else {
- switch (mCtx->textIsSigned(text))
+ switch (mCtx->textIsSigned(*mInputData))
{
case 2:
{
@@ -79,8 +99,5 @@ void VerifyDetailsDialog::slotRefresh()
mVboxLayout->addWidget(sbox);
}
- // Button Box for close button
- buttonBox = new QDialogButtonBox(QDialogButtonBox::Close);
- connect(buttonBox, SIGNAL(rejected()), this, SLOT(close()));
mVboxLayout->addWidget(buttonBox);
}
diff --git a/verifydetailsdialog.h b/verifydetailsdialog.h
index c71afda..b138f46 100644
--- a/verifydetailsdialog.h
+++ b/verifydetailsdialog.h
@@ -30,7 +30,7 @@ class VerifyDetailsDialog : public QDialog
{
Q_OBJECT
public:
- explicit VerifyDetailsDialog(QWidget *parent, GpgME::GpgContext* ctx, KeyList* mKeyList, QTextEdit *edit);
+ explicit VerifyDetailsDialog(QWidget *parent, GpgME::GpgContext* ctx, KeyList* mKeyList, QByteArray* inputData, QByteArray* inputSignature = 0);
private slots:
void slotRefresh();
@@ -40,7 +40,8 @@ private:
KeyList *mKeyList;
QHBoxLayout *mainLayout;
QWidget *mVbox;
- QTextEdit *mTextpage; /** Textedit associated to the notification */
+ QByteArray* mInputData; /** Data to be verified */
+ QByteArray* mInputSignature; /** Data to be verified */
QDialogButtonBox* buttonBox;
};
diff --git a/verifynotification.cpp b/verifynotification.cpp
index 344cbab..6e73961 100644
--- a/verifynotification.cpp
+++ b/verifynotification.cpp
@@ -87,7 +87,9 @@ void VerifyNotification::showImportAction(bool visible)
void VerifyNotification::slotShowVerifyDetails()
{
- new VerifyDetailsDialog(this, mCtx, mKeyList, mTextpage);
+ QByteArray text = mTextpage->toPlainText().toUtf8();
+ mCtx->preventNoDataErr(&text);
+ new VerifyDetailsDialog(this, mCtx, mKeyList, &text);
}
bool VerifyNotification::slotRefresh()
@@ -98,7 +100,7 @@ bool VerifyNotification::slotRefresh()
mCtx->preventNoDataErr(&text);
int textIsSigned = mCtx->textIsSigned(text);
- gpgme_signature_t sign = mCtx->verify(text);
+ gpgme_signature_t sign = mCtx->verify(&text);
if (sign == NULL) {
return false;