Mercurial > trustbridge
annotate ui/certificatelist.cpp @ 1371:23df332b2a4c
(issue179) Read install signature timestamp from config
This also changes the way the sigDt is propgated to the
MainWindow. It no longer uses the settings but hands
it over as a parameter directly.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Mon, 24 Nov 2014 15:48:49 +0100 |
parents | cf25bb040186 |
children |
rev | line source |
---|---|
404 | 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 */ | |
4
9849250f50f2
Start implementation of certificatelist parser
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
8 #include "certificatelist.h" |
9849250f50f2
Start implementation of certificatelist parser
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
9 |
7
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
4
diff
changeset
|
10 #include <QDebug> |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
4
diff
changeset
|
11 |
9
2ad9a96518e3
Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents:
7
diff
changeset
|
12 #define PARSER_VERSION "1" |
2ad9a96518e3
Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents:
7
diff
changeset
|
13 |
70
64c8c6350e60
Add default constructor to certificatelist. Remove Q_OBJECT use
Andre Heinecke <aheinecke@intevation.de>
parents:
31
diff
changeset
|
14 CertificateList::CertificateList() : mStatus(NoList) |
64c8c6350e60
Add default constructor to certificatelist. Remove Q_OBJECT use
Andre Heinecke <aheinecke@intevation.de>
parents:
31
diff
changeset
|
15 { |
64c8c6350e60
Add default constructor to certificatelist. Remove Q_OBJECT use
Andre Heinecke <aheinecke@intevation.de>
parents:
31
diff
changeset
|
16 } |
64c8c6350e60
Add default constructor to certificatelist. Remove Q_OBJECT use
Andre Heinecke <aheinecke@intevation.de>
parents:
31
diff
changeset
|
17 |
64c8c6350e60
Add default constructor to certificatelist. Remove Q_OBJECT use
Andre Heinecke <aheinecke@intevation.de>
parents:
31
diff
changeset
|
18 list_status_t CertificateList::readList(const char *fileName) |
4
9849250f50f2
Start implementation of certificatelist parser
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
19 { |
7
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
4
diff
changeset
|
20 char *data = NULL; |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
4
diff
changeset
|
21 size_t size = 0; |
4
9849250f50f2
Start implementation of certificatelist parser
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
22 |
249
6a7eb102716d
Remove code duplication by unifying the certificatelist.
Andre Heinecke <aheinecke@intevation.de>
parents:
203
diff
changeset
|
23 mCertificates.clear(); |
203
60c5df8e7980
Reinitialize certificatelist when readFile is called
Andre Heinecke <andre.heinecke@intevation.de>
parents:
97
diff
changeset
|
24 mDate = QDateTime(); |
60c5df8e7980
Reinitialize certificatelist when readFile is called
Andre Heinecke <andre.heinecke@intevation.de>
parents:
97
diff
changeset
|
25 mData = QString(); |
249
6a7eb102716d
Remove code duplication by unifying the certificatelist.
Andre Heinecke <aheinecke@intevation.de>
parents:
203
diff
changeset
|
26 mFileName = QString::fromUtf8(fileName); |
203
60c5df8e7980
Reinitialize certificatelist when readFile is called
Andre Heinecke <andre.heinecke@intevation.de>
parents:
97
diff
changeset
|
27 |
31
37fc66967517
Implement signature verification wiht polarssl
Andre Heinecke <aheinecke@intevation.de>
parents:
21
diff
changeset
|
28 mStatus = read_and_verify_list(fileName, &data, &size); |
4
9849250f50f2
Start implementation of certificatelist parser
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
29 |
9
2ad9a96518e3
Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents:
7
diff
changeset
|
30 if (!isValid()) { |
70
64c8c6350e60
Add default constructor to certificatelist. Remove Q_OBJECT use
Andre Heinecke <aheinecke@intevation.de>
parents:
31
diff
changeset
|
31 return mStatus; |
9
2ad9a96518e3
Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents:
7
diff
changeset
|
32 } |
2ad9a96518e3
Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents:
7
diff
changeset
|
33 |
2ad9a96518e3
Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents:
7
diff
changeset
|
34 // Take the data into the Qt Universe where memory is plentiful |
2ad9a96518e3
Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents:
7
diff
changeset
|
35 // and CPU's are fast :) |
84
00a93409e93e
Keep raw data around to later pass it to the installer
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
36 mData = QString::fromLatin1(data, size); |
9
2ad9a96518e3
Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents:
7
diff
changeset
|
37 free(data); |
2ad9a96518e3
Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents:
7
diff
changeset
|
38 data = NULL; |
84
00a93409e93e
Keep raw data around to later pass it to the installer
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
39 QStringList lines = mData.split("\n"); |
9
2ad9a96518e3
Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents:
7
diff
changeset
|
40 |
2ad9a96518e3
Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents:
7
diff
changeset
|
41 for (int i = 0; i < lines.size(); ++i) { |
2ad9a96518e3
Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents:
7
diff
changeset
|
42 QString curLine = lines[i].trimmed(); |
2ad9a96518e3
Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents:
7
diff
changeset
|
43 if (curLine.startsWith("F:")) { |
2ad9a96518e3
Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents:
7
diff
changeset
|
44 if (curLine.right(1) != PARSER_VERSION) { |
2ad9a96518e3
Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents:
7
diff
changeset
|
45 qDebug() << "Invalid Format Version"; |
2ad9a96518e3
Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents:
7
diff
changeset
|
46 mStatus = IncompatibleVersion; |
70
64c8c6350e60
Add default constructor to certificatelist. Remove Q_OBJECT use
Andre Heinecke <aheinecke@intevation.de>
parents:
31
diff
changeset
|
47 return mStatus; |
9
2ad9a96518e3
Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents:
7
diff
changeset
|
48 } |
2ad9a96518e3
Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents:
7
diff
changeset
|
49 } else if (curLine.startsWith("D:")) { |
2ad9a96518e3
Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents:
7
diff
changeset
|
50 curLine.remove(0, 2); |
472
cf25bb040186
Change date format to ISO as specificed for the certificate list
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
51 mDate = QDateTime::fromString(curLine, Qt::ISODate); |
cf25bb040186
Change date format to ISO as specificed for the certificate list
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
52 if (!mDate.isValid()) { |
cf25bb040186
Change date format to ISO as specificed for the certificate list
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
53 qDebug() << "Invalid Date: " << curLine; |
9
2ad9a96518e3
Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents:
7
diff
changeset
|
54 mStatus = InvalidFormat; |
70
64c8c6350e60
Add default constructor to certificatelist. Remove Q_OBJECT use
Andre Heinecke <aheinecke@intevation.de>
parents:
31
diff
changeset
|
55 return mStatus; |
9
2ad9a96518e3
Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents:
7
diff
changeset
|
56 } |
2ad9a96518e3
Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents:
7
diff
changeset
|
57 } else if (curLine.startsWith("I:")) { |
249
6a7eb102716d
Remove code duplication by unifying the certificatelist.
Andre Heinecke <aheinecke@intevation.de>
parents:
203
diff
changeset
|
58 mCertificates << Certificate(curLine); |
9
2ad9a96518e3
Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents:
7
diff
changeset
|
59 } else if (curLine.startsWith("R:")) { |
249
6a7eb102716d
Remove code duplication by unifying the certificatelist.
Andre Heinecke <aheinecke@intevation.de>
parents:
203
diff
changeset
|
60 mCertificates << Certificate(curLine); |
9
2ad9a96518e3
Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents:
7
diff
changeset
|
61 } else if (curLine.startsWith("S:")) { |
31
37fc66967517
Implement signature verification wiht polarssl
Andre Heinecke <aheinecke@intevation.de>
parents:
21
diff
changeset
|
62 // Signature is verified in read_and_verify_list |
9
2ad9a96518e3
Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents:
7
diff
changeset
|
63 continue; |
2ad9a96518e3
Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents:
7
diff
changeset
|
64 } else if (!curLine.isEmpty()){ |
2ad9a96518e3
Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents:
7
diff
changeset
|
65 qDebug () << "Don't know how to handle: " << curLine; |
2ad9a96518e3
Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents:
7
diff
changeset
|
66 } |
7
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
4
diff
changeset
|
67 } |
70
64c8c6350e60
Add default constructor to certificatelist. Remove Q_OBJECT use
Andre Heinecke <aheinecke@intevation.de>
parents:
31
diff
changeset
|
68 return mStatus; |
4
9849250f50f2
Start implementation of certificatelist parser
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
69 } |
70
64c8c6350e60
Add default constructor to certificatelist. Remove Q_OBJECT use
Andre Heinecke <aheinecke@intevation.de>
parents:
31
diff
changeset
|
70 |
64c8c6350e60
Add default constructor to certificatelist. Remove Q_OBJECT use
Andre Heinecke <aheinecke@intevation.de>
parents:
31
diff
changeset
|
71 CertificateList::CertificateList(const char *fileName) : mStatus(NoList) |
64c8c6350e60
Add default constructor to certificatelist. Remove Q_OBJECT use
Andre Heinecke <aheinecke@intevation.de>
parents:
31
diff
changeset
|
72 { |
64c8c6350e60
Add default constructor to certificatelist. Remove Q_OBJECT use
Andre Heinecke <aheinecke@intevation.de>
parents:
31
diff
changeset
|
73 readList(fileName); |
64c8c6350e60
Add default constructor to certificatelist. Remove Q_OBJECT use
Andre Heinecke <aheinecke@intevation.de>
parents:
31
diff
changeset
|
74 } |
79
1dd8e91972a8
Add accessors to certificate's in certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents:
70
diff
changeset
|
75 |
249
6a7eb102716d
Remove code duplication by unifying the certificatelist.
Andre Heinecke <aheinecke@intevation.de>
parents:
203
diff
changeset
|
76 const QList<Certificate>& CertificateList::getCertificates() const |
6a7eb102716d
Remove code duplication by unifying the certificatelist.
Andre Heinecke <aheinecke@intevation.de>
parents:
203
diff
changeset
|
77 { |
6a7eb102716d
Remove code duplication by unifying the certificatelist.
Andre Heinecke <aheinecke@intevation.de>
parents:
203
diff
changeset
|
78 return mCertificates; |
79
1dd8e91972a8
Add accessors to certificate's in certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents:
70
diff
changeset
|
79 } |