annotate ui/certificatelist.cpp @ 240:c05e126b0b9e

Fix downloadertest and factor out generating file input.
author Andre Heinecke <aheinecke@intevation.de>
date Fri, 28 Mar 2014 15:21:02 +0000
parents 60c5df8e7980
children 6a7eb102716d
rev   line source
4
9849250f50f2 Start implementation of certificatelist parser
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
1 #include "certificatelist.h"
9849250f50f2 Start implementation of certificatelist parser
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
2
7
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents: 4
diff changeset
3 #include <QDebug>
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents: 4
diff changeset
4
9
2ad9a96518e3 Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents: 7
diff changeset
5 #define PARSER_VERSION "1"
2ad9a96518e3 Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents: 7
diff changeset
6
70
64c8c6350e60 Add default constructor to certificatelist. Remove Q_OBJECT use
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
7 CertificateList::CertificateList() : mStatus(NoList)
64c8c6350e60 Add default constructor to certificatelist. Remove Q_OBJECT use
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
8 {
64c8c6350e60 Add default constructor to certificatelist. Remove Q_OBJECT use
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
9 }
64c8c6350e60 Add default constructor to certificatelist. Remove Q_OBJECT use
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
10
64c8c6350e60 Add default constructor to certificatelist. Remove Q_OBJECT use
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
11 list_status_t CertificateList::readList(const char *fileName)
4
9849250f50f2 Start implementation of certificatelist parser
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
12 {
7
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents: 4
diff changeset
13 char *data = NULL;
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents: 4
diff changeset
14 size_t size = 0;
4
9849250f50f2 Start implementation of certificatelist parser
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
15
203
60c5df8e7980 Reinitialize certificatelist when readFile is called
Andre Heinecke <andre.heinecke@intevation.de>
parents: 97
diff changeset
16 mCertificatesRemove.clear();
60c5df8e7980 Reinitialize certificatelist when readFile is called
Andre Heinecke <andre.heinecke@intevation.de>
parents: 97
diff changeset
17 mCertificatesInstall.clear();
60c5df8e7980 Reinitialize certificatelist when readFile is called
Andre Heinecke <andre.heinecke@intevation.de>
parents: 97
diff changeset
18 mDate = QDateTime();
60c5df8e7980 Reinitialize certificatelist when readFile is called
Andre Heinecke <andre.heinecke@intevation.de>
parents: 97
diff changeset
19 mData = QString();
60c5df8e7980 Reinitialize certificatelist when readFile is called
Andre Heinecke <andre.heinecke@intevation.de>
parents: 97
diff changeset
20
31
37fc66967517 Implement signature verification wiht polarssl
Andre Heinecke <aheinecke@intevation.de>
parents: 21
diff changeset
21 mStatus = read_and_verify_list(fileName, &data, &size);
4
9849250f50f2 Start implementation of certificatelist parser
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
22
9
2ad9a96518e3 Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents: 7
diff changeset
23 if (!isValid()) {
70
64c8c6350e60 Add default constructor to certificatelist. Remove Q_OBJECT use
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
24 return mStatus;
9
2ad9a96518e3 Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents: 7
diff changeset
25 }
2ad9a96518e3 Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents: 7
diff changeset
26
2ad9a96518e3 Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents: 7
diff changeset
27 // 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
28 // 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
29 mData = QString::fromLatin1(data, size);
9
2ad9a96518e3 Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents: 7
diff changeset
30 free(data);
2ad9a96518e3 Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents: 7
diff changeset
31 data = NULL;
84
00a93409e93e Keep raw data around to later pass it to the installer
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
32 QStringList lines = mData.split("\n");
9
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 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
35 QString curLine = lines[i].trimmed();
2ad9a96518e3 Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents: 7
diff changeset
36 if (curLine.startsWith("F:")) {
2ad9a96518e3 Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents: 7
diff changeset
37 if (curLine.right(1) != PARSER_VERSION) {
2ad9a96518e3 Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents: 7
diff changeset
38 qDebug() << "Invalid Format Version";
2ad9a96518e3 Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents: 7
diff changeset
39 mStatus = IncompatibleVersion;
70
64c8c6350e60 Add default constructor to certificatelist. Remove Q_OBJECT use
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
40 return mStatus;
9
2ad9a96518e3 Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents: 7
diff changeset
41 }
2ad9a96518e3 Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents: 7
diff changeset
42 } else if (curLine.startsWith("D:")) {
2ad9a96518e3 Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents: 7
diff changeset
43 bool ok = false;
2ad9a96518e3 Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents: 7
diff changeset
44 qlonglong timestamp = 0;
2ad9a96518e3 Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents: 7
diff changeset
45
2ad9a96518e3 Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents: 7
diff changeset
46 curLine.remove(0, 2);
2ad9a96518e3 Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents: 7
diff changeset
47 timestamp = curLine.toLongLong(&ok);
2ad9a96518e3 Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents: 7
diff changeset
48 if (!ok) {
2ad9a96518e3 Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents: 7
diff changeset
49 qDebug() << "Invalid Date";
2ad9a96518e3 Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents: 7
diff changeset
50 mStatus = InvalidFormat;
70
64c8c6350e60 Add default constructor to certificatelist. Remove Q_OBJECT use
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
51 return mStatus;
9
2ad9a96518e3 Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents: 7
diff changeset
52 }
2ad9a96518e3 Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents: 7
diff changeset
53
2ad9a96518e3 Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents: 7
diff changeset
54 mDate = QDateTime::fromMSecsSinceEpoch(timestamp * 1000);
2ad9a96518e3 Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents: 7
diff changeset
55 } else if (curLine.startsWith("I:")) {
84
00a93409e93e Keep raw data around to later pass it to the installer
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
56 mCertificatesInstall << Certificate(curLine);
9
2ad9a96518e3 Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents: 7
diff changeset
57 } else if (curLine.startsWith("R:")) {
97
e478deca18f5 Correctly split between certificates to install and to remove
Andre Heinecke <aheinecke@intevation.de>
parents: 96
diff changeset
58 mCertificatesRemove << 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("S:")) {
31
37fc66967517 Implement signature verification wiht polarssl
Andre Heinecke <aheinecke@intevation.de>
parents: 21
diff changeset
60 // 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
61 continue;
2ad9a96518e3 Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents: 7
diff changeset
62 } else if (!curLine.isEmpty()){
2ad9a96518e3 Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents: 7
diff changeset
63 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
64 }
7
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents: 4
diff changeset
65 }
70
64c8c6350e60 Add default constructor to certificatelist. Remove Q_OBJECT use
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
66 return mStatus;
4
9849250f50f2 Start implementation of certificatelist parser
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
67 }
70
64c8c6350e60 Add default constructor to certificatelist. Remove Q_OBJECT use
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
68
64c8c6350e60 Add default constructor to certificatelist. Remove Q_OBJECT use
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
69 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
70 {
64c8c6350e60 Add default constructor to certificatelist. Remove Q_OBJECT use
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
71 readList(fileName);
64c8c6350e60 Add default constructor to certificatelist. Remove Q_OBJECT use
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
72 }
79
1dd8e91972a8 Add accessors to certificate's in certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 70
diff changeset
73
1dd8e91972a8 Add accessors to certificate's in certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 70
diff changeset
74 const QList<Certificate>& CertificateList::getInstallCertificates() const {
1dd8e91972a8 Add accessors to certificate's in certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 70
diff changeset
75 return mCertificatesInstall;
1dd8e91972a8 Add accessors to certificate's in certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 70
diff changeset
76 }
1dd8e91972a8 Add accessors to certificate's in certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 70
diff changeset
77
1dd8e91972a8 Add accessors to certificate's in certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 70
diff changeset
78 const QList<Certificate>& CertificateList::getRemoveCertificates() const {
1dd8e91972a8 Add accessors to certificate's in certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 70
diff changeset
79 return mCertificatesRemove;
1dd8e91972a8 Add accessors to certificate's in certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 70
diff changeset
80 }

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