Page MenuHome GnuPG

No OneTemporary

diff --git a/tests/test.data b/tests/test.data
index 562184a34..bcbd45d81 100644
--- a/tests/test.data
+++ b/tests/test.data
@@ -1,294 +1,5 @@
-/* -*- mode: c++; c-basic-offset:4 -*-
- tests/test_uiserver.cpp
+Hello Wörld
- This file is part of Kleopatra, the KDE keymanager
- Copyright (c) 2007 Klarälvdalens Datakonsult AB
+This is a test file for Kleopatra.
+Please don't change it without updating the signature.
- Kleopatra 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 2 of the License, or
- (at your option) any later version.
-
- Kleopatra 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 this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-
- In addition, as a special exception, the copyright holders give
- permission to link the code of this program with any edition of
- the Qt library by Trolltech AS, Norway (or with modified versions
- of Qt that use the same license as Qt), and distribute linked
- combinations including the two. You must obey the GNU General
- Public License in all respects for all of the code used other than
- Qt. If you modify this file, you may extend this exception to
- your version of the file, but you are not obligated to do so. If
- you do not wish to do so, delete this exception statement from
- your version.
-*/
-
-//
-// Usage: test_uiserver <socket> --verify-detached <signed data> <signature>
-//
-#ifndef _ASSUAN_ONLY_GPG_ERRORS
-#define _ASSUAN_ONLY_GPG_ERRORS
-#endif
-#include "../uiserver/kleo-assuan.h"
-#include <gpg-error.h>
-
-
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <assert.h>
-
-#include <iostream>
-#include <map>
-#include <string>
-#include <vector>
-
-using namespace Kleo;
-
-static std::vector<int> inFDs, outFDs, msgFDs;
-static std::vector<std::string> inFiles, outFiles, msgFiles;
-static std::map<std::string,std::string> inquireData;
-
-static std::string hexencode( const std::string & in ) {
- std::string result;
- result.reserve( 3 * in.size() );
-
- static const char hex[] = "0123456789ABCDEF";
-
- for ( std::string::const_iterator it = in.begin(), end = in.end() ; it != end ; ++it )
- switch ( const unsigned char ch = *it ) {
- default:
- if ( ch >= '!' && ch <= '~' || ch > 0xA0 ) {
- result += ch;
- break;
- }
- // else fall through
- case ' ':
- result += '+';
- break;
- case '"':
- case '#':
- case '$':
- case '%':
- case '\'':
- case '+':
- case '=':
- result += '%';
- result += hex[ (ch & 0xF0) >> 4 ];
- result += hex[ (ch & 0x0F) ];
- break;
- }
-
- return result;
-}
-
-static void usage( const std::string & msg=std::string() ) {
- std::cerr << msg << std::endl <<
- "\n"
- "Usage: test_uiserver <socket> [<io>] [<options>] [<inquire>] command [<args>]\n"
- "where:\n"
- " <io>: [--input[-fd] <file>] [--output[-fd] <file>] [--message[-fd] <file>]\n"
- " <options>: *[--option name=value]\n"
- " <inquire>: [--inquire keyword=<file>]\n";
- exit( 1 );
-}
-
-static int data( void * void_ctx, const void * buffer, size_t len ) {
- (void)void_ctx; (void)buffer; (void)len;
- return 0; // ### implement me
-}
-
-static int status( void * void_ctx, const char * line ) {
- (void)void_ctx; (void)line;
- return 0;
-}
-
-static int inquire( void * void_ctx, const char * keyword ) {
- assuan_context_t ctx = (assuan_context_t)void_ctx;
- assert( ctx );
- const std::map<std::string,std::string>::const_iterator it = inquireData.find( keyword );
- if ( it == inquireData.end() )
- return gpg_error( GPG_ERR_UNKNOWN_COMMAND );
-
- if ( !it->second.empty() && it->second[0] == '@' )
- return gpg_error( GPG_ERR_NOT_IMPLEMENTED );
-
- if ( const gpg_error_t err = assuan_send_data( ctx, it->second.c_str(), it->second.size() ) ) {
- qDebug( "assuan_write_data: %s", gpg_strerror( err ) );
- return err;
- }
-
- return 0;
-}
-
-int main( int argc, char * argv[] ) {
-
- assuan_set_assuan_err_source( GPG_ERR_SOURCE_DEFAULT );
-
- if ( argc < 3 )
- usage(); // need socket and command, at least
-
- const char * socket = argv[1];
-
- std::vector<const char*> options;
-
- std::string command;
- for ( int optind = 2 ; optind < argc ; ++optind ) {
- const char * const arg = argv[optind];
- if ( qstrcmp( arg, "--input-fd" ) == 0 ) {
- int inFD;
- if ( (inFD = open( argv[++optind], O_RDONLY )) == -1 ) {
- perror( "--input-fd open()" );
- return 1;
- }
- inFDs.push_back( inFD );
- } else if ( qstrcmp( arg, "--output-fd" ) == 0 ) {
- int outFD;
- if ( (outFD = open( argv[++optind], O_WRONLY|O_CREAT )) == -1 ) {
- perror( "--output-fd open()" );
- return 1;
- }
- outFDs.push_back( outFD );
- } else if ( qstrcmp( arg, "--message-fd" ) == 0 ) {
- int msgFD;
- if ( (msgFD = open( argv[++optind], O_RDONLY )) == -1 ) {
- perror( "--message-fd open()" );
- return 1;
- }
- msgFDs.push_back( msgFD );
- } else if ( qstrcmp( arg, "--input" ) == 0 ) {
- const std::string file = argv[++optind];
- inFiles.push_back( file );
- } else if ( qstrcmp( arg, "--output" ) == 0 ) {
- const std::string file = argv[++optind];
- outFiles.push_back( file );
- } else if ( qstrcmp( arg, "--message" ) == 0 ) {
- const std::string file = argv[++optind];
- msgFiles.push_back( file );
- } else if ( qstrcmp( arg, "--option" ) == 0 ) {
- options.push_back( argv[++optind] );
- } else if ( qstrcmp( arg, "--inquire" ) == 0 ) {
- const std::string inqval = argv[++optind];
- const size_t pos = inqval.find( '=' );
- // ### implement indirection with "@file"...
- inquireData[inqval.substr( 0, pos )] = inqval.substr( pos+1 );
- } else {
- while ( optind < argc ) {
- if ( !command.empty() )
- command += ' ';
- command += argv[optind++];
- }
- }
- }
- if ( command.empty() )
- usage( "Command expected, but only options found" );
-
- assuan_context_t ctx = 0;
-
- if ( const gpg_error_t err = assuan_socket_connect_ext( &ctx, socket, -1, 1 ) ) {
- qDebug( "%s", assuan_exception( err, "assuan_socket_connect_ext" ).what() );
- return 1;
- }
-
- assuan_set_log_stream( ctx, stderr );
-
- for ( std::vector<int>::const_iterator it = inFDs.begin(), end = inFDs.end() ; it != end ; ++it ) {
- if ( const gpg_error_t err = assuan_sendfd( ctx, *it ) ) {
- qDebug( "%s", assuan_exception( err, "assuan_sendfd( inFD )" ).what() );
- return 1;
- }
-
- if ( const gpg_error_t err = assuan_transact( ctx, "INPUT FD", 0, 0, 0, 0, 0, 0 ) ) {
- qDebug( "%s", assuan_exception( err, "INPUT FD" ).what() );
- return 1;
- }
- }
-
-
- for ( std::vector<std::string>::const_iterator it = inFiles.begin(), end = inFiles.end() ; it != end ; ++it ) {
- char buffer[1024];
- sprintf( buffer, "INPUT FILE=%s", hexencode( *it ).c_str() );
-
- if ( const gpg_error_t err = assuan_transact( ctx, buffer, 0, 0, 0, 0, 0, 0 ) ) {
- qDebug( "%s", assuan_exception( err, buffer ).what() );
- return 1;
- }
- }
-
-
- for ( std::vector<int>::const_iterator it = msgFDs.begin(), end = msgFDs.end() ; it != end ; ++it ) {
- if ( const gpg_error_t err = assuan_sendfd( ctx, *it ) ) {
- qDebug( "%s", assuan_exception( err, "assuan_sendfd( msgFD )" ).what() );
- return 1;
- }
-
- if ( const gpg_error_t err = assuan_transact( ctx, "MESSAGE FD", 0, 0, 0, 0, 0, 0 ) ) {
- qDebug( "%s", assuan_exception( err, "MESSAGE FD" ).what() );
- return 1;
- }
- }
-
-
- for ( std::vector<std::string>::const_iterator it = msgFiles.begin(), end = msgFiles.end() ; it != end ; ++it ) {
- char buffer[1024];
- sprintf( buffer, "MESSAGE FILE=%s", hexencode( *it ).c_str() );
-
- if ( const gpg_error_t err = assuan_transact( ctx, buffer, 0, 0, 0, 0, 0, 0 ) ) {
- qDebug( "%s", assuan_exception( err, buffer ).what() );
- return 1;
- }
- }
-
-
- for ( std::vector<int>::const_iterator it = outFDs.begin(), end = outFDs.end() ; it != end ; ++it ) {
- if ( const gpg_error_t err = assuan_sendfd( ctx, *it ) ) {
- qDebug( "%s", assuan_exception( err, "assuan_sendfd( outFD )" ).what() );
- return 1;
- }
-
- if ( const gpg_error_t err = assuan_transact( ctx, "OUTPUT FD", 0, 0, 0, 0, 0, 0 ) ) {
- qDebug( "%s", assuan_exception( err, "OUTPUT FD" ).what() );
- return 1;
- }
- }
-
-
- for ( std::vector<std::string>::const_iterator it = outFiles.begin(), end = outFiles.end() ; it != end ; ++it ) {
- char buffer[1024];
- sprintf( buffer, "OUTPUT FILE=%s", hexencode( *it ).c_str() );
-
- if ( const gpg_error_t err = assuan_transact( ctx, buffer, 0, 0, 0, 0, 0, 0 ) ) {
- qDebug( "%s", assuan_exception( err, buffer ).what() );
- return 1;
- }
- }
-
-
-
- Q_FOREACH( const char * opt, options ) {
- std::string line = "OPTION ";
- line += opt;
- if ( const gpg_error_t err = assuan_transact( ctx, line.c_str(), 0, 0, 0, 0, 0, 0 ) ) {
- qDebug( "%s", assuan_exception( err, line ).what() );
- return 1;
- }
- }
-
- if ( const gpg_error_t err = assuan_transact( ctx, command.c_str(), data, ctx, inquire, ctx, status, ctx ) ) {
- qDebug( "%s", assuan_exception( err, command ).what() );
- return 1;
- }
-
- assuan_disconnect( ctx );
-
- return 0;
-}
diff --git a/tests/test.data.sig b/tests/test.data.sig
index 4e2713752..07b0c5ebd 100644
Binary files a/tests/test.data.sig and b/tests/test.data.sig differ
diff --git a/tests/test_verify.cpp b/tests/test_verify.cpp
index bec1a2168..fe6f1a7f4 100644
--- a/tests/test_verify.cpp
+++ b/tests/test_verify.cpp
@@ -1,233 +1,233 @@
/*
This file is part of Kleopatra's test suite.
Copyright (c) 2007 Klarälvdalens Datakonsult AB
Kleopatra 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 2 of the License, or
(at your option) any later version.
Kleopatra 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 this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
In addition, as a special exception, the copyright holders give
permission to link the code of this program with any edition of
the Qt library by Trolltech AS, Norway (or with modified versions
of Qt that use the same license as Qt), and distribute linked
combinations including the two. You must obey the GNU General
Public License in all respects for all of the code used other than
Qt. If you modify this file, you may extend this exception to
your version of the file, but you are not obligated to do so. If
you do not wish to do so, delete this exception statement from
your version.
*/
#include <config-kleopatra.h>
#include "kleo_test.h"
#include <QGpgME/Protocol>
#include <QGpgME/VerifyDetachedJob>
#include <QGpgME/KeyListJob>
#include <QGpgME/DecryptVerifyJob>
#include <gpgme++/error.h>
#include <gpgme++/verificationresult.h>
#include <gpgme++/decryptionresult.h>
#include <gpgme++/key.h>
#include <QTimer>
#include <QObject>
#include <QSignalSpy>
// Replace this with a gpgme version check once GnuPG Bug #2092
// ( https://bugs.gnupg.org/gnupg/issue2092 ) is fixed.
#define GPGME_MULTITHREADED_KEYLIST_BROKEN
Q_DECLARE_METATYPE(GpgME::VerificationResult)
class VerifyTest : public QObject
{
Q_OBJECT
private:
// Data shared with all tests
QByteArray mSignature;
QByteArray mSignedData;
const QGpgME::Protocol *mBackend;
QEventLoop mEventLoop;
// Data for testParallelVerifyAndKeyListJobs()
QList<QGpgME::VerifyDetachedJob *> mParallelVerifyJobs;
QList<QGpgME::KeyListJob *> mParallelKeyListJobs;
// Data for testMixedParallelJobs()
QList<QGpgME::Job *> mRunningJobs;
int mJobsStarted;
public Q_SLOTS:
void slotParallelKeyListJobFinished()
{
mParallelKeyListJobs.removeAll(static_cast<QGpgME::KeyListJob *>(sender()));
// When all jobs are done, quit the event loop
if (mParallelVerifyJobs.isEmpty() && mParallelKeyListJobs.isEmpty()) {
mEventLoop.quit();
}
}
void slotParallelVerifyJobFinished(GpgME::VerificationResult result)
{
// Verify the result of the job is correct
QVERIFY(mParallelVerifyJobs.contains(static_cast<QGpgME::VerifyDetachedJob *>(sender())));
QCOMPARE(result.signature(0).validity(), GpgME::Signature::Full);
mParallelVerifyJobs.removeAll(static_cast<QGpgME::VerifyDetachedJob *>(sender()));
// Start a key list job
QGpgME::KeyListJob *job = mBackend->keyListJob();
mParallelKeyListJobs.append(job);
connect(job, &QGpgME::Job::done,
this, &VerifyTest::slotParallelKeyListJobFinished);
QVERIFY(!job->start(QStringList()));
}
void someJobDone()
{
// Don't bother checking any results here
mRunningJobs.removeAll(static_cast<QGpgME::Job *>(sender()));
}
void startAnotherJob()
{
static int counter = 0;
counter++;
// Randomly kill a running job
if (counter % 10 == 0 && !mRunningJobs.isEmpty()) {
mRunningJobs.at(counter % mRunningJobs.size())->slotCancel();
}
// Randomly either start a keylist or a verify job
QGpgME::Job *job;
if (counter % 2 == 0) {
QGpgME::VerifyDetachedJob *vdj = mBackend->verifyDetachedJob();
QVERIFY(!vdj->start(mSignature, mSignedData));
job = vdj;
} else {
QGpgME::KeyListJob *klj = mBackend->keyListJob();
QVERIFY(!klj->start(QStringList()));
job = klj;
}
mRunningJobs.append(job);
connect(job, &QGpgME::Job::done, this, &VerifyTest::someJobDone);
// Quit after 2500 jobs, that should be enough
mJobsStarted++;
if (mJobsStarted >= 2500) {
QTimer::singleShot(1000, &mEventLoop, &QEventLoop::quit);
} else {
QTimer::singleShot(0, this, &VerifyTest::startAnotherJob);
}
}
private Q_SLOTS:
void initTestCase()
{
qRegisterMetaType<GpgME::VerificationResult>();
const QString sigFileName = QLatin1String(KLEO_TEST_DATADIR) + QLatin1String("/test.data.sig");
const QString dataFileName = QLatin1String(KLEO_TEST_DATADIR) + QLatin1String("/test.data");
QFile sigFile(sigFileName);
QVERIFY(sigFile.open(QFile::ReadOnly));
QFile dataFile(dataFileName);
QVERIFY(dataFile.open(QFile::ReadOnly));
mSignature = sigFile.readAll();
mSignedData = dataFile.readAll();
mBackend = QGpgME::openpgp();
}
void testVerify()
{
QGpgME::VerifyDetachedJob *job = mBackend->verifyDetachedJob();
QSignalSpy spy(job, SIGNAL(result(GpgME::VerificationResult)));
QVERIFY(spy.isValid());
GpgME::Error err = job->start(mSignature, mSignedData);
QVERIFY(!err);
QTest::qWait(1000); // ### we need to enter the event loop, can be done nicer though
QCOMPARE(spy.count(), 1);
GpgME::VerificationResult result = spy.takeFirst().at(0).value<GpgME::VerificationResult>();
QCOMPARE(result.numSignatures(), 1U);
GpgME::Signature sig = result.signature(0);
QCOMPARE(sig.summary() & GpgME::Signature::KeyMissing, 0);
- QCOMPARE((quint64) sig.creationTime(), Q_UINT64_C(1189650248));
+ QCOMPARE((quint64) sig.creationTime(), Q_UINT64_C(1530524124));
QCOMPARE(sig.validity(), GpgME::Signature::Full);
}
/* Test that the decrypt verify job also works with signed only, not
* encrypted PGP messages */
void testDecryptVerifyOpaqueSigned()
{
const QString sigFileName = QLatin1String(KLEO_TEST_DATADIR) +
QLatin1String("/test.data.signed-opaque.asc");
std::pair<GpgME::DecryptionResult, GpgME::VerificationResult> result;
QByteArray plaintext;
QFile sigFile(sigFileName);
QVERIFY(sigFile.open(QFile::ReadOnly));
const QByteArray ciphertext = sigFile.readAll();
QGpgME::DecryptVerifyJob *job = mBackend->decryptVerifyJob();
result = job->exec(ciphertext, plaintext);
QVERIFY(result.first.error().code());
QVERIFY(result.second.numSignatures());
GpgME::Signature sig = result.second.signature(0);
QVERIFY(sig.validity() == GpgME::Signature::Validity::Full);
QVERIFY(!sig.status().code());
QVERIFY(QString::fromUtf8(plaintext).startsWith(
QLatin1String("/* -*- mode: c++; c-basic-offset:4 -*-")));
}
#ifndef GPGME_MULTITHREADED_KEYLIST_BROKEN
// The following two tests are disabled because they trigger an
// upstream bug in gpgme. See: https://bugs.gnupg.org/gnupg/issue2092
// Which has a testcase attached that does similar things using gpgme
// directly and triggers various problems.
void testParallelVerifyAndKeyListJobs()
{
// ### Increasing 10 to 500 makes the verify jobs fail!
// ^ This should also be reevaluated if the underlying bug in gpgme
// is fixed.
for (int i = 0; i < 10; ++i) {
QGpgME::VerifyDetachedJob *job = mBackend->verifyDetachedJob();
mParallelVerifyJobs.append(job);
QVERIFY(!job->start(mSignature, mSignedData));
connect(job, SIGNAL(result(GpgME::VerificationResult)),
this, SLOT(slotParallelVerifyJobFinished(GpgME::VerificationResult)));
}
mEventLoop.exec();
}
void testMixedParallelJobs()
{
mJobsStarted = 0;
QTimer::singleShot(0, this, SLOT(startAnotherJob()));
mEventLoop.exec();
}
#endif
};
QTEST_KLEOMAIN(VerifyTest)
#include "test_verify.moc"

File Metadata

Mime Type
text/x-diff
Expires
Sun, Dec 14, 2:49 PM (1 d, 14 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
0d/64/3ac3c5935546ddf21f960e7208f2

Event Timeline