Mercurial > trustbridge
changeset 243:4b67cc2d4dad
Merged
author | Sascha Wilde <wilde@intevation.de> |
---|---|
date | Fri, 28 Mar 2014 18:38:34 +0100 |
parents | 809eaca3898c (current diff) c05e126b0b9e (diff) |
children | 0145d2401f46 |
files | cinst/mozilla.c |
diffstat | 11 files changed, 99 insertions(+), 52 deletions(-) [+] |
line wrap: on
line diff
--- a/cinst/mozilla.c Fri Mar 28 18:37:59 2014 +0100 +++ b/cinst/mozilla.c Fri Mar 28 18:38:34 2014 +0100 @@ -4,12 +4,12 @@ * * Reads from stdin a list of instructions in the form: * - * I:<base64 DER econded certificate>\r\n - * R:<base64 DER econded certificate>\r\n + * I:<base64 DER econded certificate> + * R:<base64 DER econded certificate> * ... * - * The maximum size of an input line is 9999 characters - * (including the \r\n) at the end of the line. + * With one instruction per line. the maximum size of an input + * line is 9999 characters (including the \r\n) at the end of the line. * * Certificates marked with I: will be installed and the ones * marked with R: will be searched and if available removed from @@ -22,6 +22,10 @@ * has to ensure that those are terminated before this process is * executed. * + * If the same certificate is marked to be installed and to be removed + * in one call the behavior is undefined. This should be avoided and + * may lead to errors. + * * Returns 0 on success (Even when no stores where found) an error value * as defined in errorcodes.h otherwise. *
--- a/common/strhelp.h Fri Mar 28 18:37:59 2014 +0100 +++ b/common/strhelp.h Fri Mar 28 18:38:34 2014 +0100 @@ -84,6 +84,14 @@ * The memory allocated for dest needs to be free'd by the * caller. * + * _Input warning:_ + * If the input contains invalid base64 characters an error + * is returned. + * + * If the input is invalid base64 but consists of valid + * base64 characters _no error_ is returned and dst contains + * the valid input up to the error. + * * @param [out] dst Pointer to the destination. Needs to be NULL * @param [out] dst_size Size allocated for the destination. * @param [in] src Pointer to the base64 encoded data.
--- a/ui/tests/CMakeLists.txt Fri Mar 28 18:37:59 2014 +0100 +++ b/ui/tests/CMakeLists.txt Fri Mar 28 18:38:34 2014 +0100 @@ -29,13 +29,13 @@ # Add the current source dir to the definition # so that it can be used in file names in the tests. add_definitions(-DSOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}") -add_m13_test(certlistparsertest.cpp "${CERTIFICATELIST_SOURCES}") +add_m13_test(certlistparsertest.cpp "${CERTIFICATELIST_SOURCES};${CMAKE_CURRENT_SOURCE_DIR}/common.cpp") # Downloader if (HIAWATHA_EXECUTABLE) set(DOWNLOADER_SOURCES_WITH_RESOURCES ${DOWNLOADER_SOURCES}) qt5_add_resources(DOWNLOADER_SOURCES_WITH_RESOURCES ${M13UI_RESOURCES}) - add_m13_test(downloadertest.cpp "${DOWNLOADER_SOURCES_WITH_RESOURCES}") + add_m13_test(downloadertest.cpp "${DOWNLOADER_SOURCES_WITH_RESOURCES};${CMAKE_CURRENT_SOURCE_DIR}/common.cpp") endif() # Cinstprocess
--- a/ui/tests/certlistparsertest.cpp Fri Mar 28 18:37:59 2014 +0100 +++ b/ui/tests/certlistparsertest.cpp Fri Mar 28 18:38:34 2014 +0100 @@ -1,6 +1,7 @@ #include "certlistparsertest.h" #include "certificatelist.h" #include "certificate.h" +#include "common.h" #include <QDebug> @@ -114,37 +115,6 @@ delete certList; } -QString CertListTest::getRandomDataFile(size_t size) -{ - QTemporaryFile tmpfile; - tmpfile.setAutoRemove(false); - tmpfile.open(); - size_t bufsize = 1024 * 1024; - if (bufsize > size) { - bufsize = size; - } - char buf[bufsize]; - - for (size_t i = 0; i < bufsize; i++) { - buf[i] = (char) qrand() % 255; - } - - size_t bytesWritten=0; - int retval = 0; - do { - size_t toWrite = size - bytesWritten; - if (toWrite < bufsize) { - retval = tmpfile.write(buf, toWrite); - } else { - retval = tmpfile.write(buf, bufsize); - } - bytesWritten += retval; - } while (retval != -1 && bytesWritten < size); - - tmpfile.close(); - return tmpfile.fileName(); -} - void CertListTest::testTooLarge() { QString fname = getRandomDataFile(MAX_LINE_LENGTH * MAX_LINES + 1);
--- a/ui/tests/certlistparsertest.h Fri Mar 28 18:37:59 2014 +0100 +++ b/ui/tests/certlistparsertest.h Fri Mar 28 18:38:34 2014 +0100 @@ -11,7 +11,6 @@ Q_OBJECT CertificateList* testWithFile(const char *filename); - QString getRandomDataFile(size_t size); private Q_SLOTS: void testInvalidSig();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/tests/common.cpp Fri Mar 28 18:38:34 2014 +0100 @@ -0,0 +1,42 @@ +#include <QString> +#include <QTemporaryFile> +#include <QDebug> +#include "common.h" + +QString getRandomDataFile(size_t size, const QDir &inDir) +{ + QTemporaryFile *tmpfile; + if (inDir != QDir()) { + tmpfile = new QTemporaryFile(inDir.path() + "/downloadertest"); + } else { + tmpfile = new QTemporaryFile(); + } + tmpfile->setAutoRemove(false); + tmpfile->open(); + size_t bufsize = 1024 * 1024; + if (bufsize > size) { + bufsize = size; + } + char buf[bufsize]; + + for (size_t i = 0; i < bufsize; i++) { + buf[i] = (char) qrand() % 255; + } + + size_t bytesWritten=0; + int retval = 0; + do { + size_t toWrite = size - bytesWritten; + if (toWrite < bufsize) { + retval = tmpfile->write(buf, toWrite); + } else { + retval = tmpfile->write(buf, bufsize); + } + bytesWritten += retval; + } while (retval != -1 && bytesWritten < size); + + tmpfile->close(); + QString ret = tmpfile->fileName(); + delete tmpfile; + return ret; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/tests/common.h Fri Mar 28 18:38:34 2014 +0100 @@ -0,0 +1,11 @@ +#ifndef COMMON_H +#define COMMON_H +#include <QDir> +#include <QString> + +/** @file common.h + * @brief Common testing code used in multiple tests. */ + +/* @brief get the file name of a file filled with garbage */ +QString getRandomDataFile(size_t size, const QDir &inDir = QDir()); +#endif // COMMON_H
--- a/ui/tests/commontest.cpp Fri Mar 28 18:37:59 2014 +0100 +++ b/ui/tests/commontest.cpp Fri Mar 28 18:38:34 2014 +0100 @@ -5,6 +5,18 @@ #include "commontest.h" #include "strhelp.h" +void CommonTest::testInvalidInput() { + const char * foo = "Zm9vA"; /* Invalid input with a bit valid input */ + char *data = NULL; + size_t data_size = 0; + int ret = -1; + ret = str_base64_decode(&data, &data_size, (char *)foo, 5); + + QVERIFY(ret == 0); + QVERIFY(data == QString::fromLatin1("foo")); + free(data); +} + void CommonTest::testStrBase64Decode() { char garbage[1000]; char *data = NULL; @@ -24,13 +36,6 @@ QVERIFY(data_size == 1000); QVERIFY(data); - ret = str_base64_decode(&data, &data_size, (char *)ba.constData(), ba.size()); - QVERIFY(ret != 0); - - const char * foo = "bla"; - ret = str_base64_decode(&data, &data_size, (char *)foo, 3); - QVERIFY(ret != 0); - for (size_t i = 0; i < data_size; i++) { QVERIFY(garbage[i] == data[i]); }
--- a/ui/tests/commontest.h Fri Mar 28 18:37:59 2014 +0100 +++ b/ui/tests/commontest.h Fri Mar 28 18:38:34 2014 +0100 @@ -9,5 +9,6 @@ private Q_SLOTS: void testStrBase64Decode(); + void testInvalidInput(); }; #endif
--- a/ui/tests/downloadertest.cpp Fri Mar 28 18:37:59 2014 +0100 +++ b/ui/tests/downloadertest.cpp Fri Mar 28 18:38:34 2014 +0100 @@ -1,10 +1,11 @@ #include "downloadertest.h" #include "downloader.h" +#include "common.h" #include <QTextStream> #include <QFile> #include <QVariant> -#include "unistd.h" +#include <unistd.h> #define MAX_WAIT 20 @@ -28,7 +29,6 @@ mimeConfig.close(); /* just an empty file */ QTextStream configStream(&serverConfig); - qDebug() << "Config file name: " << serverConfig.fileName(); configStream << "Binding { " << endl << "Port = 44443 " << endl << @@ -37,7 +37,7 @@ "Interface = 127.0.0.1" << endl << "}" << endl << "Hostname = 127.0.0.1" << endl << - "WebsiteRoot = " << SOURCE_DIR << "/data" << endl; + "WebsiteRoot = " << serverConfigDir.path() << endl; configStream.flush(); serverConfig.close(); @@ -52,6 +52,10 @@ serverProc.setArguments(arguments); qRegisterMetaType<SSLConnection::ErrorCode>("SSLConnection::ErrorCode"); startServer(); + garbageInfo = QFileInfo(getRandomDataFile(2 * 1024, serverConfigDir.path())); + QVERIFY(QFile::copy(QString::fromLocal8Bit(SOURCE_DIR"/data/list-valid.txt"), + serverConfigDir.path() + "/" + "list-valid.txt")); + QTest::qWait(1000); /* Wait for the server to settle */ } @@ -80,12 +84,14 @@ "/data/valid_ssl_rsa.pem"); otherCert.open(QIODevice::ReadOnly); + QFileInfo fi(getRandomDataFile(200)); + Downloader* downloader = new Downloader(this, QString::fromLatin1("https://localhost:44443"), otherCert.readAll(), QDateTime::currentDateTime(), // Last installed SW QDateTime::fromString("2010", "YYYY"), - "/garbage_2MB", + "/" + garbageInfo.fileName(), "/list-valid.txt"); otherCert.close(); @@ -146,7 +152,7 @@ validCert.readAll(), QDateTime::fromString("2010", "YYYY"), QDateTime::currentDateTime(), - "/garbage_2MB", + "/" + garbageInfo.fileName(), "/list-valid.txt"); validCert.close(); @@ -170,7 +176,7 @@ QList<QVariant> arguments = newSoftwareAvailable.takeFirst(); - QVERIFY(filesEqual(QString::fromLatin1(SOURCE_DIR) + "/data/garbage_2MB", + QVERIFY(filesEqual(serverConfigDir.path() + "/" + garbageInfo.fileName(), arguments.at(0).toString())); delete downloader; @@ -187,7 +193,7 @@ validCert.readAll(), QDateTime::currentDateTime(), // Last installed SW QDateTime::fromString("2010", "YYYY"), - "/garbage_2MB", + "/" + garbageInfo.fileName(), "/list-valid.txt"); validCert.close();
--- a/ui/tests/downloadertest.h Fri Mar 28 18:37:59 2014 +0100 +++ b/ui/tests/downloadertest.h Fri Mar 28 18:38:34 2014 +0100 @@ -17,6 +17,7 @@ private: QProcess serverProc; QTemporaryDir serverConfigDir; + QFileInfo garbageInfo; public Q_SLOTS: void downloaderError(const QString &message, SSLConnection::ErrorCode error);