Mercurial > trustbridge
comparison ui/tests/createcertlisttest.cpp @ 468:a53286e5b126
Add failing test for certificate list creation
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Wed, 23 Apr 2014 16:21:49 +0000 |
parents | |
children | a166d740cb5a |
comparison
equal
deleted
inserted
replaced
467:5ebee91c0bb8 | 468:a53286e5b126 |
---|---|
1 /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik | |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU GPL (v>=2) | |
5 * and comes with ABSOLUTELY NO WARRANTY! | |
6 * See LICENSE.txt for details. | |
7 */ | |
8 #include "createcertlisttest.h" | |
9 #include "sslhelp.h" | |
10 #include "createcertlistdialog.h" | |
11 #include "certificatelist.h" | |
12 | |
13 #include <polarssl/pk.h> | |
14 | |
15 #include <QDateTime> | |
16 #include <QTemporaryFile> | |
17 #include <QTest> | |
18 | |
19 void CreateCertListTest::testListCreation() { | |
20 QTemporaryFile tmpFile, outputFile, keyFile; | |
21 | |
22 /* Get a valid list */ | |
23 QFile res(":/list-valid-signed.txt"); | |
24 res.open(QIODevice::ReadOnly); | |
25 tmpFile.open(); | |
26 tmpFile.write(res.readAll()); | |
27 tmpFile.close(); | |
28 CertificateList validList = CertificateList(tmpFile.fileName().toLocal8Bit().data()); | |
29 QVERIFY(validList.isValid()); | |
30 | |
31 /* Get a key */ | |
32 QFile keyRes(":/testkey-priv.pem"); | |
33 keyRes.open(QIODevice::ReadOnly); | |
34 keyFile.open(); | |
35 keyFile.write(keyRes.readAll()); | |
36 keyFile.close(); | |
37 pk_context * pk = new pk_context; | |
38 pk_init(pk); | |
39 int ret = pk_parse_keyfile(pk, keyFile.fileName().toLocal8Bit().constData(), ""); | |
40 QVERIFY(ret == 0); | |
41 | |
42 /* Write the certificates from that list to another file */ | |
43 outputFile.open(); | |
44 QDateTime current = QDateTime::currentDateTimeUtc(); | |
45 QVERIFY(CreateCertListDialog::writeList(validList.getCertificates(), | |
46 outputFile.fileName(), current, pk)); | |
47 pk_free(pk); | |
48 | |
49 CertificateList outputList = CertificateList(outputFile.fileName().toLocal8Bit().data()); | |
50 QVERIFY(outputList.isValid()); | |
51 QVERIFY(outputList.getCertificates() == validList.getCertificates()); | |
52 QVERIFY(outputList.date() == current); | |
53 } | |
54 | |
55 void CreateCertListTest::testSha256Sum() | |
56 { | |
57 QByteArray input = "foo"; | |
58 QByteArray output = sha256sum(input); | |
59 QVERIFY(output.toBase64() == QByteArray("b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c")); | |
60 } | |
61 | |
62 void CreateCertListTest::testSignature() | |
63 { | |
64 QByteArray hash = QByteArray::fromBase64("b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c"); | |
65 | |
66 QTemporaryFile keyFile; | |
67 QFile keyRes(":/testkey-priv.pem"); | |
68 keyRes.open(QIODevice::ReadOnly); | |
69 keyFile.open(); | |
70 keyFile.write(keyRes.readAll()); | |
71 keyFile.close(); | |
72 pk_context * pk = new pk_context; | |
73 pk_init(pk); | |
74 int ret = pk_parse_keyfile(pk, keyFile.fileName().toLocal8Bit().constData(), ""); | |
75 QVERIFY(ret == 0); | |
76 | |
77 QByteArray signature = rsaSignSHA256Hash(hash, pk); | |
78 pk_free(pk); | |
79 | |
80 QVERIFY(signature.size() == 3072 / 8); | |
81 QVERIFY(signature.toBase64() == QByteArray("KMOni98NWbt6SWd13H0JlGA1B7hBlXWH84e883s7gMrWeCCj0fUyHmdsNCyY0rmosu+o9mo2K847S3CdnxFPPJcjbfcmILZWRw0hHMtUYta1i9jypHJbz4oznuDctgXz59L4SQzzliCNUzItNoe6UpUznkS5gja4ZHbzqIj3qDVX3H86Z+qOdLICw+LXKlTs5ghsq+SdhZRAFFpHnt+URICWHjEIQKRlmIGEUIh1NgEHInHB/teFLqNGJMu1khi0MTsWDzesAEF5LQTM7Fo3fKmVxEUSbHKupluZrX1XSfnp5w3MaxBQK/t5nFvkVVdFrdEWvb68FIkMt21XqCvjyCPG2oWNh9jjfx3/R+eQ8kFbXzgUIhlZNxbB7bOCVDe2fYNxlXhy+HAqfHsIDP8qegHU+ngLck7tJHScC5dZwTCBDL6sxAvaeGyb3m6FraqaipNI+SGLii63ou9H7PlH5xWOTY9JvJDXGpfjN9U0UrZ6X5hPutOa/llT7s0pmoQb")); | |
82 } | |
83 | |
84 QTEST_GUILESS_MAIN (CreateCertListTest); |