Mercurial > trustbridge
annotate ui/tests/binverifytest.cpp @ 636:2fd4f9980a2a
Add test for authenticode verificate (binverify)
Still incomplete
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Mon, 23 Jun 2014 18:00:45 +0200 |
parents | |
children | be30d50bc4f0 |
rev | line source |
---|---|
636
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1 /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
2 * Software engineering by Intevation GmbH |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
3 * |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
4 * This file is Free Software under the GNU GPL (v>=2) |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
6 * See LICENSE.txt for details. |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
7 */ |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
8 #include "binverify.h" |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
9 #include "binverifytest.h" |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
10 |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
11 #include <QTest> |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
12 |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
13 #ifdef Q_OS_WIN |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
14 # define EXE_SUFFIX ".exe" |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
15 #else |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
16 # define EXE_SUFFIX "" |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
17 #endif |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
18 |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
19 /* Some general robustness checks */ |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
20 void BinVerifyTest::testMiscErrors() |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
21 { |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
22 QVERIFY (verify_binary (NULL, 10) != VerifyValid); |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
23 QVERIFY (verify_binary ("foo", 10) != VerifyValid); |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
24 QVERIFY (verify_binary ("bar", -1) != VerifyValid); |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
25 /* On windows the next line will check that a valid microsoft |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
26 * signed executable is not valid for us (pinning). On linux |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
27 * it will just fail with a read error. */ |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
28 QVERIFY (verify_binary ("c:\\Windows\\System32\\mmc.exe", |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
29 strlen("c:\\Windows\\System32\\mmc.exe")) != VerifyValid); |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
30 QVERIFY (verify_binary ("/dev/null", strlen("/dev/null")) != VerifyValid); |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
31 } |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
32 |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
33 /* Check that no signature is not validated */ |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
34 /* Check that an invalid signature is not validated */ |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
35 /* Check that a signature with only a different key (of the same size) |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
36 * is not validated */ |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
37 /* Check that a signature with a different certificate is not validated */ |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
38 void BinVerifyTest::testNoSignature() |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
39 { |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
40 QVERIFY(VerifyInvalidSignature == verify_binary ("fakeinst" EXE_SUFFIX, |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
41 strlen("fakeinst" EXE_SUFFIX))); |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
42 } |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
43 |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
44 /* Check that a valid signed executable is verified */ |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
45 void BinVerifyTest::testValidBinary() |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
46 { |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
47 QVERIFY (VerifyValid == verify_binary ("fakeinst-signed" EXE_SUFFIX, |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
48 strlen("fakeinst-signed" EXE_SUFFIX))); |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
49 } |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
50 |
2fd4f9980a2a
Add test for authenticode verificate (binverify)
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
51 QTEST_GUILESS_MAIN (BinVerifyTest); |