Mercurial > trustbridge
annotate ui/certificate.h @ 327:3261b2a9cab7
Added a first version of the management application gui.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Tue, 08 Apr 2014 16:28:07 +0200 |
parents | ffd47b045d19 |
children | 64e38886f903 |
rev | line source |
---|---|
21
dc1e1e9e62ce
Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
1 #ifndef CERTIFICATE_H |
dc1e1e9e62ce
Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
2 #define CERTIFICATE_H |
dc1e1e9e62ce
Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
3 /** |
dc1e1e9e62ce
Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
4 * @file certificate.h |
dc1e1e9e62ce
Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
5 * @brief Class around native certificates. |
dc1e1e9e62ce
Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
6 * |
dc1e1e9e62ce
Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
7 */ |
dc1e1e9e62ce
Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
8 |
dc1e1e9e62ce
Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
9 #include <QByteArray> |
186
2551ad24d3c2
Get subject from the certificate and parse it's attributes
Andre Heinecke <andre.heinecke@intevation.de>
parents:
94
diff
changeset
|
10 #include <QMap> |
21
dc1e1e9e62ce
Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
11 #include <QString> |
dc1e1e9e62ce
Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
12 |
dc1e1e9e62ce
Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
13 #ifdef Q_OS_WIN |
dc1e1e9e62ce
Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
14 #include <windows.h> |
dc1e1e9e62ce
Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
15 #include <wincrypt.h> |
dc1e1e9e62ce
Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
16 #endif |
dc1e1e9e62ce
Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
17 |
dc1e1e9e62ce
Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
18 class Certificate |
dc1e1e9e62ce
Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
19 { |
dc1e1e9e62ce
Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
20 public: |
94
f1ebab8639dc
Do not save the x509 cert as a member variable
Andre Heinecke <aheinecke@intevation.de>
parents:
83
diff
changeset
|
21 |
265
ffd47b045d19
Added certificate status enum and register it as metatype.
Raimund Renkert <rrenkert@intevation.de>
parents:
248
diff
changeset
|
22 enum Status { |
ffd47b045d19
Added certificate status enum and register it as metatype.
Raimund Renkert <rrenkert@intevation.de>
parents:
248
diff
changeset
|
23 InstallNew = 1, |
ffd47b045d19
Added certificate status enum and register it as metatype.
Raimund Renkert <rrenkert@intevation.de>
parents:
248
diff
changeset
|
24 InstallOld, |
ffd47b045d19
Added certificate status enum and register it as metatype.
Raimund Renkert <rrenkert@intevation.de>
parents:
248
diff
changeset
|
25 RemoveNew, |
ffd47b045d19
Added certificate status enum and register it as metatype.
Raimund Renkert <rrenkert@intevation.de>
parents:
248
diff
changeset
|
26 RemoveOld |
ffd47b045d19
Added certificate status enum and register it as metatype.
Raimund Renkert <rrenkert@intevation.de>
parents:
248
diff
changeset
|
27 }; |
ffd47b045d19
Added certificate status enum and register it as metatype.
Raimund Renkert <rrenkert@intevation.de>
parents:
248
diff
changeset
|
28 |
83
ba8a548ff252
Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
29 /** @brief construct a certificate from a line of a certificate list. |
ba8a548ff252
Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
30 * |
ba8a548ff252
Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
31 * The first two characters of the string are expected to be |
ba8a548ff252
Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
32 * the command. I: or R: |
ba8a548ff252
Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
33 * |
ba8a548ff252
Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
34 * @param[in] b64Line The line from the certificate list. |
21
dc1e1e9e62ce
Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
35 **/ |
94
f1ebab8639dc
Do not save the x509 cert as a member variable
Andre Heinecke <aheinecke@intevation.de>
parents:
83
diff
changeset
|
36 Certificate(const QString& b64Line = QString()); |
21
dc1e1e9e62ce
Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
37 |
dc1e1e9e62ce
Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
38 /** @brief check if this certificate could be parsed */ |
78 | 39 bool isValid() const {return mValid;} |
21
dc1e1e9e62ce
Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
40 |
dc1e1e9e62ce
Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
41 /** @brief get a short description of the certificate |
dc1e1e9e62ce
Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
42 * |
dc1e1e9e62ce
Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
43 * This description should be used as a short overview |
dc1e1e9e62ce
Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
44 * for this certificate |
dc1e1e9e62ce
Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
45 * |
dc1e1e9e62ce
Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
46 **/ |
186
2551ad24d3c2
Get subject from the certificate and parse it's attributes
Andre Heinecke <andre.heinecke@intevation.de>
parents:
94
diff
changeset
|
47 QString shortDescription() const; |
83
ba8a548ff252
Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
48 |
ba8a548ff252
Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
49 /** @brief get details for the certificate |
ba8a548ff252
Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
50 * |
ba8a548ff252
Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
51 * Get the X509 information that is returned by x509_crt_info |
ba8a548ff252
Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
52 * |
ba8a548ff252
Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
53 **/ |
ba8a548ff252
Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
54 const QString& details() const {return mDetails;} |
ba8a548ff252
Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
55 |
ba8a548ff252
Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
56 /** @brief get the line from which this certificate was constructed |
ba8a548ff252
Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
57 * |
ba8a548ff252
Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
58 * The resulting line includes the instruction e.g. |
ba8a548ff252
Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
59 * |
ba8a548ff252
Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
60 * I:BASE64ENCODEDATA... |
ba8a548ff252
Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
61 * |
ba8a548ff252
Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
62 **/ |
ba8a548ff252
Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
63 const QString& base64Line() const {return mBaseLine;} |
21
dc1e1e9e62ce
Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
64 |
186
2551ad24d3c2
Get subject from the certificate and parse it's attributes
Andre Heinecke <andre.heinecke@intevation.de>
parents:
94
diff
changeset
|
65 /** @brief get a single attribute of the subject |
2551ad24d3c2
Get subject from the certificate and parse it's attributes
Andre Heinecke <andre.heinecke@intevation.de>
parents:
94
diff
changeset
|
66 * |
2551ad24d3c2
Get subject from the certificate and parse it's attributes
Andre Heinecke <andre.heinecke@intevation.de>
parents:
94
diff
changeset
|
67 * Returns a single attribute of the subject such as the |
2551ad24d3c2
Get subject from the certificate and parse it's attributes
Andre Heinecke <andre.heinecke@intevation.de>
parents:
94
diff
changeset
|
68 * common name. |
2551ad24d3c2
Get subject from the certificate and parse it's attributes
Andre Heinecke <andre.heinecke@intevation.de>
parents:
94
diff
changeset
|
69 * |
2551ad24d3c2
Get subject from the certificate and parse it's attributes
Andre Heinecke <andre.heinecke@intevation.de>
parents:
94
diff
changeset
|
70 * @param[in] attr the Attribute name. to get e.g. "CN" |
2551ad24d3c2
Get subject from the certificate and parse it's attributes
Andre Heinecke <andre.heinecke@intevation.de>
parents:
94
diff
changeset
|
71 * |
2551ad24d3c2
Get subject from the certificate and parse it's attributes
Andre Heinecke <andre.heinecke@intevation.de>
parents:
94
diff
changeset
|
72 * @returns the value of the attribute or a null string |
2551ad24d3c2
Get subject from the certificate and parse it's attributes
Andre Heinecke <andre.heinecke@intevation.de>
parents:
94
diff
changeset
|
73 **/ |
2551ad24d3c2
Get subject from the certificate and parse it's attributes
Andre Heinecke <andre.heinecke@intevation.de>
parents:
94
diff
changeset
|
74 QString getSubjectAttr(const QString& attr) const; |
2551ad24d3c2
Get subject from the certificate and parse it's attributes
Andre Heinecke <andre.heinecke@intevation.de>
parents:
94
diff
changeset
|
75 |
248
9f0865dc8b14
Add accessor to check if the certificate should be installed
Andre Heinecke <aheinecke@intevation.de>
parents:
186
diff
changeset
|
76 /** @brief Check if this certificate has the install instruction. |
9f0865dc8b14
Add accessor to check if the certificate should be installed
Andre Heinecke <aheinecke@intevation.de>
parents:
186
diff
changeset
|
77 * |
9f0865dc8b14
Add accessor to check if the certificate should be installed
Andre Heinecke <aheinecke@intevation.de>
parents:
186
diff
changeset
|
78 * This is shorthand for baseLine.startsWith("I:"); |
9f0865dc8b14
Add accessor to check if the certificate should be installed
Andre Heinecke <aheinecke@intevation.de>
parents:
186
diff
changeset
|
79 **/ |
9f0865dc8b14
Add accessor to check if the certificate should be installed
Andre Heinecke <aheinecke@intevation.de>
parents:
186
diff
changeset
|
80 bool isInstallCert() const {return mBaseLine.startsWith("I:");} |
9f0865dc8b14
Add accessor to check if the certificate should be installed
Andre Heinecke <aheinecke@intevation.de>
parents:
186
diff
changeset
|
81 |
21
dc1e1e9e62ce
Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
82 private: |
dc1e1e9e62ce
Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
83 bool mValid; |
248
9f0865dc8b14
Add accessor to check if the certificate should be installed
Andre Heinecke <aheinecke@intevation.de>
parents:
186
diff
changeset
|
84 bool mInstCert; |
83
ba8a548ff252
Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
85 |
ba8a548ff252
Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
86 QString mDetails; |
ba8a548ff252
Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
87 QString mBaseLine; |
186
2551ad24d3c2
Get subject from the certificate and parse it's attributes
Andre Heinecke <andre.heinecke@intevation.de>
parents:
94
diff
changeset
|
88 QMap <QString, QString> mSubjectAttrs; |
21
dc1e1e9e62ce
Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
89 }; |
dc1e1e9e62ce
Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
90 #endif |