annotate ui/tests/createcertlisttest.cpp @ 1345:db9dfd4740af

Added tag 0.9.4 for changeset cf1cd6cda97b
author Andre Heinecke <andre.heinecke@intevation.de>
date Tue, 28 Oct 2014 12:01:37 +0100
parents 317ee9dc4684
children
rev   line source
468
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
1 /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
2 * Software engineering by Intevation GmbH
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
3 *
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
4 * This file is Free Software under the GNU GPL (v>=2)
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY!
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
6 * See LICENSE.txt for details.
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
7 */
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
8 #include "createcertlisttest.h"
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
9 #include "sslhelp.h"
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
10 #include "createcertlistdialog.h"
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
11 #include "certificatelist.h"
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
12
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
13 #include <polarssl/pk.h>
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
14
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
15 #include <QDateTime>
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
16 #include <QTemporaryFile>
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
17 #include <QTest>
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
18
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
19 void CreateCertListTest::testListCreation() {
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
20 QTemporaryFile tmpFile, outputFile, keyFile;
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
21
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
22 /* Get a valid list */
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
23 QFile res(":/list-valid-signed.txt");
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
24 res.open(QIODevice::ReadOnly);
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
25 tmpFile.open();
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
26 tmpFile.write(res.readAll());
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
27 tmpFile.close();
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
28 CertificateList validList = CertificateList(tmpFile.fileName().toLocal8Bit().data());
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
29 QVERIFY(validList.isValid());
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
30
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
31 /* Get a key */
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
32 QFile keyRes(":/testkey-priv.pem");
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
33 keyRes.open(QIODevice::ReadOnly);
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
34 keyFile.open();
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
35 keyFile.write(keyRes.readAll());
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
36 keyFile.close();
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
37 pk_context * pk = new pk_context;
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
38 pk_init(pk);
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
39 int ret = pk_parse_keyfile(pk, keyFile.fileName().toLocal8Bit().constData(), "");
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
40 QVERIFY(ret == 0);
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
41
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
42 /* Write the certificates from that list to another file */
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
43 outputFile.open();
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
44 QDateTime current = QDateTime::currentDateTimeUtc();
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
45 QVERIFY(CreateCertListDialog::writeList(validList.getCertificates(),
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
46 outputFile.fileName(), current, pk));
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
47 pk_free(pk);
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
48
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
49 CertificateList outputList = CertificateList(outputFile.fileName().toLocal8Bit().data());
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
50 QVERIFY(outputList.isValid());
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
51 QVERIFY(outputList.getCertificates() == validList.getCertificates());
474
bcae22d57e67 Do not verify Msec equality on the DateTime. We only store seconds
Andre Heinecke <aheinecke@intevation.de>
parents: 471
diff changeset
52 QVERIFY(outputList.date().date() == current.date());
bcae22d57e67 Do not verify Msec equality on the DateTime. We only store seconds
Andre Heinecke <aheinecke@intevation.de>
parents: 471
diff changeset
53 QVERIFY(outputList.date().time().hour() == current.time().hour());
bcae22d57e67 Do not verify Msec equality on the DateTime. We only store seconds
Andre Heinecke <aheinecke@intevation.de>
parents: 471
diff changeset
54 QVERIFY(outputList.date().time().minute() == current.time().minute());
bcae22d57e67 Do not verify Msec equality on the DateTime. We only store seconds
Andre Heinecke <aheinecke@intevation.de>
parents: 471
diff changeset
55 QVERIFY(outputList.date().time().second() == current.time().second());
468
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
56 }
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
57
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
58 void CreateCertListTest::testSha256Sum()
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
59 {
470
a166d740cb5a Damn you line endings ;)
Andre Heinecke <aheinecke@intevation.de>
parents: 468
diff changeset
60 QByteArray input = "foo\n";
468
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
61 QByteArray output = sha256sum(input);
471
dd54c02fc28a Hex != base64
Andre Heinecke <aheinecke@intevation.de>
parents: 470
diff changeset
62 QVERIFY(output == QByteArray::fromHex("b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c"));
468
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
63 }
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
64
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
65 void CreateCertListTest::testSignature()
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
66 {
471
dd54c02fc28a Hex != base64
Andre Heinecke <aheinecke@intevation.de>
parents: 470
diff changeset
67 QByteArray hash = QByteArray::fromHex("b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c");
468
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
68
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
69 QTemporaryFile keyFile;
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
70 QFile keyRes(":/testkey-priv.pem");
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
71 keyRes.open(QIODevice::ReadOnly);
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
72 keyFile.open();
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
73 keyFile.write(keyRes.readAll());
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
74 keyFile.close();
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
75 pk_context * pk = new pk_context;
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
76 pk_init(pk);
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
77 int ret = pk_parse_keyfile(pk, keyFile.fileName().toLocal8Bit().constData(), "");
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
78 QVERIFY(ret == 0);
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
79
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
80 QByteArray signature = rsaSignSHA256Hash(hash, pk);
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
81 pk_free(pk);
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
82
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
83 QVERIFY(signature.size() == 3072 / 8);
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
84 QVERIFY(signature.toBase64() == QByteArray("KMOni98NWbt6SWd13H0JlGA1B7hBlXWH84e883s7gMrWeCCj0fUyHmdsNCyY0rmosu+o9mo2K847S3CdnxFPPJcjbfcmILZWRw0hHMtUYta1i9jypHJbz4oznuDctgXz59L4SQzzliCNUzItNoe6UpUznkS5gja4ZHbzqIj3qDVX3H86Z+qOdLICw+LXKlTs5ghsq+SdhZRAFFpHnt+URICWHjEIQKRlmIGEUIh1NgEHInHB/teFLqNGJMu1khi0MTsWDzesAEF5LQTM7Fo3fKmVxEUSbHKupluZrX1XSfnp5w3MaxBQK/t5nFvkVVdFrdEWvb68FIkMt21XqCvjyCPG2oWNh9jjfx3/R+eQ8kFbXzgUIhlZNxbB7bOCVDe2fYNxlXhy+HAqfHsIDP8qegHU+ngLck7tJHScC5dZwTCBDL6sxAvaeGyb3m6FraqaipNI+SGLii63ou9H7PlH5xWOTY9JvJDXGpfjN9U0UrZ6X5hPutOa/llT7s0pmoQb"));
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
85 }
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
86
1060
317ee9dc4684 (issue46) Make debug output optional in cinst and mozilla and propagate its setting.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 474
diff changeset
87 bool g_debug = true;
317ee9dc4684 (issue46) Make debug output optional in cinst and mozilla and propagate its setting.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 474
diff changeset
88
468
a53286e5b126 Add failing test for certificate list creation
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
89 QTEST_GUILESS_MAIN (CreateCertListTest);

http://wald.intevation.org/projects/trustbridge/