aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorubbo <ubbo@34ebc366-c3a9-4b3c-9f84-69acf7962910>2012-05-01 11:27:14 +0000
committerubbo <ubbo@34ebc366-c3a9-4b3c-9f84-69acf7962910>2012-05-01 11:27:14 +0000
commit4ecc173307c8c1ed13f28b6955484a484a25402a (patch)
tree9a08a04864f4818a88a66c6860101e394f8b76d7
parentsign files integrated (diff)
downloadgpg4usb-4ecc173307c8c1ed13f28b6955484a484a25402a.tar.gz
gpg4usb-4ecc173307c8c1ed13f28b6955484a484a25402a.zip
verify for files (not yet working)
git-svn-id: http://cpunk.de/svn/src/gpg4usb/trunk@909 34ebc366-c3a9-4b3c-9f84-69acf7962910
-rwxr-xr-xfileencryptiondialog.cpp47
-rwxr-xr-xfileencryptiondialog.h8
-rw-r--r--gpgcontext.cpp14
-rw-r--r--gpgcontext.h2
-rw-r--r--verifydetailsdialog.cpp22
-rw-r--r--verifydetailsdialog.h5
-rw-r--r--verifynotification.cpp6
7 files changed, 88 insertions, 16 deletions
diff --git a/fileencryptiondialog.cpp b/fileencryptiondialog.cpp
index 8735b9d..4e652a6 100755
--- a/fileencryptiondialog.cpp
+++ b/fileencryptiondialog.cpp
@@ -60,15 +60,27 @@ FileEncryptionDialog::FileEncryptionDialog(GpgME::GpgContext *ctx, QStringList k
QLabel *fl2 = new QLabel(tr("Output"));
fl2->setBuddy(outputFileEdit);
+
+
QGridLayout *gLayout = new QGridLayout();
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(selectSignFile()));
+ 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);
@@ -111,6 +123,8 @@ void FileEncryptionDialog::selectInputFile()
outputFileEdit->setText(infileName + ".asc");
} else if (mAction == Sign) {
outputFileEdit->setText(infileName + ".sig");
+ } else if (mAction == Sign) {
+ signFileEdit->setText(infileName + ".sig");
} else {
if (infileName.endsWith(".asc", Qt::CaseInsensitive)) {
QString ofn = infileName;
@@ -135,6 +149,24 @@ void FileEncryptionDialog::selectOutputFile()
}
+void FileEncryptionDialog::selectSignFile()
+{
+ 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::executeAction()
{
@@ -155,7 +187,18 @@ void FileEncryptionDialog::executeAction()
}
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)) {
+ qDebug() << tr("Couldn't Open file: ") + signFileEdit->text();
+ }
+ 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 7888bc0..73e191b 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;
@@ -82,6 +83,12 @@ public slots:
/**
* @brief
*
+ * @fn selectSignFile
+ */
+ void selectSignFile();
+ /**
+ * @brief
+ *
* @fn executeAction
*/
void executeAction();
@@ -101,6 +108,7 @@ public slots:
private:
QLineEdit *outputFileEdit; /**< TODO */
QLineEdit *inputFileEdit; /**< TODO */
+ QLineEdit *signFileEdit; /**< TODO */
DialogAction mAction; /**< TODO */
protected:
GpgME::GpgContext *mCtx; /**< TODO */
diff --git a/gpgcontext.cpp b/gpgcontext.cpp
index f3aef91..78a124c 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, NULL, in);
+ } else {
+ err = gpgme_op_verify (mCtx, in, NULL, in);
+ }
error = checkErr(err);
if (error != 0) {
diff --git a/gpgcontext.h b/gpgcontext.h
index 7b83394..cdb522d 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 e6980b8..557646e 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(refresh()));
@@ -48,9 +51,16 @@ void VerifyDetailsDialog::refresh()
mainLayout->addWidget(mVbox);
// 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) {
+ qDebug() << "insig: " << *mInputSignature;
+ sign = mCtx->verify(mInputData, mInputSignature);
+ qDebug() << gpg_err_code(sign->status);
+ } else {
+ sign = mCtx->verify(mInputData);
+ }
// Get timestamp of signature of current text
QDateTime timestamp;
@@ -60,7 +70,7 @@ void VerifyDetailsDialog::refresh()
if(gpg_err_code(sign->status) == GPG_ERR_BAD_SIGNATURE) {
mVboxLayout->addWidget(new QLabel(tr("Error Validating signature")));
} else {
- switch (mCtx->textIsSigned(text))
+ switch (mCtx->textIsSigned(*mInputData))
{
case 2:
{
diff --git a/verifydetailsdialog.h b/verifydetailsdialog.h
index 4feee35..5ce7ff7 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 refresh();
@@ -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 3e056b9..1230534 100644
--- a/verifynotification.cpp
+++ b/verifynotification.cpp
@@ -87,7 +87,9 @@ void VerifyNotification::showImportAction(bool visible)
void VerifyNotification::showVerifyDetails()
{
- new VerifyDetailsDialog(this, mCtx, mKeyList, mTextpage);
+ QByteArray text = mTextpage->toPlainText().toUtf8();
+ mCtx->preventNoDataErr(&text);
+ new VerifyDetailsDialog(this, mCtx, mKeyList, &text);
}
bool VerifyNotification::refresh()
@@ -98,7 +100,7 @@ bool VerifyNotification::refresh()
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;