andre@636: /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik andre@636: * Software engineering by Intevation GmbH andre@636: * andre@636: * This file is Free Software under the GNU GPL (v>=2) andre@636: * and comes with ABSOLUTELY NO WARRANTY! andre@636: * See LICENSE.txt for details. andre@636: */ andre@636: #include "binverify.h" andre@636: #include "binverifytest.h" andre@636: andre@636: #include andre@636: andre@636: #ifdef Q_OS_WIN andre@636: # define EXE_SUFFIX ".exe" andre@636: #else andre@636: # define EXE_SUFFIX "" andre@636: #endif andre@636: andre@636: /* Some general robustness checks */ andre@636: void BinVerifyTest::testMiscErrors() andre@636: { andre@636: QVERIFY (verify_binary (NULL, 10) != VerifyValid); andre@636: QVERIFY (verify_binary ("foo", 10) != VerifyValid); andre@636: QVERIFY (verify_binary ("bar", -1) != VerifyValid); andre@636: /* On windows the next line will check that a valid microsoft andre@636: * signed executable is not valid for us (pinning). On linux andre@636: * it will just fail with a read error. */ andre@636: QVERIFY (verify_binary ("c:\\Windows\\System32\\mmc.exe", andre@636: strlen("c:\\Windows\\System32\\mmc.exe")) != VerifyValid); andre@636: QVERIFY (verify_binary ("/dev/null", strlen("/dev/null")) != VerifyValid); andre@636: } andre@636: andre@636: /* Check that no signature is not validated */ andre@636: /* Check that an invalid signature is not validated */ andre@636: /* Check that a signature with only a different key (of the same size) andre@636: * is not validated */ andre@636: /* Check that a signature with a different certificate is not validated */ andre@636: void BinVerifyTest::testNoSignature() andre@636: { andre@636: QVERIFY(VerifyInvalidSignature == verify_binary ("fakeinst" EXE_SUFFIX, andre@636: strlen("fakeinst" EXE_SUFFIX))); andre@636: } andre@636: andre@636: /* Check that a valid signed executable is verified */ andre@636: void BinVerifyTest::testValidBinary() andre@636: { andre@636: QVERIFY (VerifyValid == verify_binary ("fakeinst-signed" EXE_SUFFIX, andre@636: strlen("fakeinst-signed" EXE_SUFFIX))); andre@636: } andre@636: andre@636: QTEST_GUILESS_MAIN (BinVerifyTest);