Mercurial > trustbridge
comparison ui/tests/binverifytest.cpp @ 1081:edbf5e5e88f4
(issue118) Extend verify_binary to carry an open file
* binverify.c: Change result to a structure containing an open fptr
Use in Memory data for windows verification.
* mainwindow.cpp, selftest.c: Handle the returend structure
* binverifytest.cpp: Test for the exclusive read and update signature.
* listutil.c: Add optional fptr parameter to read_file
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Thu, 11 Sep 2014 12:05:24 +0200 |
parents | 317ee9dc4684 |
children | 948f03bb5254 |
comparison
equal
deleted
inserted
replaced
1080:898b1ddcca11 | 1081:edbf5e5e88f4 |
---|---|
28 #endif | 28 #endif |
29 | 29 |
30 /* Some general robustness checks */ | 30 /* Some general robustness checks */ |
31 void BinVerifyTest::testMiscErrors() | 31 void BinVerifyTest::testMiscErrors() |
32 { | 32 { |
33 QVERIFY (verify_binary (NULL, 10) != VerifyValid); | 33 QVERIFY (verify_binary (NULL, 10).result != VerifyValid); |
34 QVERIFY (verify_binary ("foo", 10) != VerifyValid); | 34 QVERIFY (verify_binary ("foo", 10).result != VerifyValid); |
35 QVERIFY (verify_binary ("bar", -1) != VerifyValid); | 35 QVERIFY (verify_binary ("bar", -1).result!= VerifyValid); |
36 /* On windows the next line will check that a valid microsoft | 36 /* On windows the next line will check that a valid microsoft |
37 * signed executable is not valid for us (pinning). On linux | 37 * signed executable is not valid for us (pinning). On linux |
38 * it will just fail with a read error which we tested above */ | 38 * it will just fail with a read error which we tested above */ |
39 #ifdef Q_OS_WIN | 39 #ifdef Q_OS_WIN |
40 QVERIFY (verify_binary ("c:\\Windows\\System32\\mmc.exe", | 40 QVERIFY (verify_binary ("c:\\Windows\\System32\\mmc.exe", |
41 strlen("c:\\Windows\\System32\\mmc.exe")) != VerifyInvalidCertificate); | 41 strlen("c:\\Windows\\System32\\mmc.exe")).result != VerifyInvalidCertificate); |
42 #endif | 42 #endif |
43 QVERIFY (verify_binary ("/dev/null", strlen("/dev/null")) != VerifyValid); | 43 QVERIFY (verify_binary ("/dev/null", strlen("/dev/null")).result != VerifyValid); |
44 } | 44 } |
45 | 45 |
46 /* Check that a signature with only a different key (of the same size) | 46 /* Check that a signature with only a different key (of the same size) |
47 * is not validated (Invalid signature because key and cert don't match)*/ | 47 * is not validated (Invalid signature because key and cert don't match)*/ |
48 void BinVerifyTest::testOtherKey() | 48 void BinVerifyTest::testOtherKey() |
49 { | 49 { |
50 QVERIFY(VerifyInvalidSignature == verify_binary ("fakeinst-other-key" EXE_SUFFIX, | 50 QVERIFY(VerifyInvalidSignature == verify_binary ("fakeinst-other-key" EXE_SUFFIX, |
51 strlen("fakeinst-other-key" EXE_SUFFIX))); | 51 strlen("fakeinst-other-key" EXE_SUFFIX)).result); |
52 } | 52 } |
53 | 53 |
54 /* Check that an invalid signature is not validated */ | 54 /* Check that an invalid signature is not validated */ |
55 void BinVerifyTest::testInvalidSig() | 55 void BinVerifyTest::testInvalidSig() |
56 { | 56 { |
57 QVERIFY(VerifyValid != verify_binary ("fakeinst-invalid" EXE_SUFFIX, | 57 bin_verify_result res = verify_binary ("fakeinst-invalid" EXE_SUFFIX, |
58 strlen("fakeinst-invalid" EXE_SUFFIX))); | 58 strlen("fakeinst-invalid" EXE_SUFFIX)); |
59 QVERIFY(VerifyValid != res.result); | |
60 QVERIFY(res.fptr == NULL); | |
59 } | 61 } |
60 | 62 |
61 #ifdef Q_OS_WIN | 63 #ifdef Q_OS_WIN |
62 /* Check that a signature with a different (valid) certificate is not validated | 64 /* Check that a signature with a different (valid) certificate is not validated |
63 * on Linux only the key is checked not the certificate */ | 65 * on Linux only the key is checked not the certificate */ |
64 void BinVerifyTest::testOtherCert() | 66 void BinVerifyTest::testOtherCert() |
65 { | 67 { |
66 QVERIFY(VerifyInvalidCertificate == verify_binary ("fakeinst-other-cert" EXE_SUFFIX, | 68 QVERIFY(VerifyInvalidCertificate == verify_binary ("fakeinst-other-cert" EXE_SUFFIX, |
67 strlen("fakeinst-other-cert" EXE_SUFFIX))); | 69 strlen("fakeinst-other-cert" EXE_SUFFIX)).result); |
68 } | 70 } |
69 #endif | 71 #endif |
70 | 72 |
71 /* Check that no signature is not validated */ | 73 /* Check that no signature is not validated */ |
72 void BinVerifyTest::testNoSignature() | 74 void BinVerifyTest::testNoSignature() |
73 { | 75 { |
74 QVERIFY(VerifyValid != verify_binary ("fakeinst" EXE_SUFFIX, | 76 bin_verify_result res = verify_binary ("fakeinst" EXE_SUFFIX, |
75 strlen("fakeinst" EXE_SUFFIX))); | 77 strlen("fakeinst" EXE_SUFFIX)); |
78 QVERIFY(VerifyValid != res.result); | |
79 QVERIFY(res.fptr == NULL); | |
76 } | 80 } |
77 | 81 |
78 /* Check that a valid signed executable is verified */ | 82 /* Check that a valid signed executable is verified */ |
79 void BinVerifyTest::testValidBinary() | 83 void BinVerifyTest::testValidBinary() |
80 { | 84 { |
81 QVERIFY (VerifyValid == verify_binary ("fakeinst-signed" EXE_SUFFIX, | 85 bin_verify_result res = verify_binary ("fakeinst-signed" EXE_SUFFIX, |
82 strlen("fakeinst-signed" EXE_SUFFIX))); | 86 strlen("fakeinst-signed" EXE_SUFFIX)); |
87 QVERIFY (VerifyValid == res.result); | |
88 QFile thefile ("fakeinst-signed" EXE_SUFFIX); | |
89 #ifdef WIN32 | |
90 /* Verifies the deny write open mode. But on linuy we dont have it. */ | |
91 QVERIFY (!thefile.open(QIODevice::ReadWrite)); | |
92 #endif | |
93 QVERIFY (res.fptr != NULL); | |
94 fclose(res.fptr); | |
95 QVERIFY (thefile.open(QIODevice::ReadWrite)); | |
96 thefile.close(); | |
83 } | 97 } |
84 | 98 |
85 void BinVerifyTest::testSignatureCreation() | 99 void BinVerifyTest::testSignatureCreation() |
86 { | 100 { |
87 QSettings testsettings; | 101 QSettings testsettings; |
93 outfile.open(); | 107 outfile.open(); |
94 outfile.close(); | 108 outfile.close(); |
95 bool ret = theDialog->appendTextSignatureToFile (garbage, outfile.fileName()); | 109 bool ret = theDialog->appendTextSignatureToFile (garbage, outfile.fileName()); |
96 QVERIFY(QFile::remove(garbage)); | 110 QVERIFY(QFile::remove(garbage)); |
97 QVERIFY(ret == true); | 111 QVERIFY(ret == true); |
98 QVERIFY(VerifyValid == verify_binary (outfile.fileName().toUtf8().constData(), | 112 bin_verify_result res = verify_binary (outfile.fileName().toUtf8().constData(), |
99 outfile.fileName().toUtf8().size())); | 113 outfile.fileName().toUtf8().size()); |
114 QVERIFY(VerifyValid == res.result); | |
100 } | 115 } |
101 bool g_debug = true; | 116 bool g_debug = true; |
102 | 117 |
103 QTEST_MAIN (BinVerifyTest); | 118 QTEST_MAIN (BinVerifyTest); |