Mercurial > trustbridge
comparison ui/downloader.h @ 45:c6125d73faf4
Move SSLConnection into it's own class
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Fri, 14 Mar 2014 16:40:53 +0000 |
parents | d8e93fa1fc93 |
children | 09cd242d8443 |
comparison
equal
deleted
inserted
replaced
44:b3e8e047bc2c | 45:c6125d73faf4 |
---|---|
5 * @brief High level API to download necessary data. | 5 * @brief High level API to download necessary data. |
6 * | 6 * |
7 */ | 7 */ |
8 | 8 |
9 #include <QThread> | 9 #include <QThread> |
10 #include <QDateTime> | |
10 #include <QString> | 11 #include <QString> |
11 #include <QByteArray> | 12 #include <QByteArray> |
12 #include <QDateTime> | |
13 #include <QUrl> | |
14 | 13 |
15 #include <polarssl/x509_crt.h> | 14 #include "sslconnection.h" |
16 #include <polarssl/entropy.h> | |
17 #include <polarssl/ctr_drbg.h> | |
18 #include <polarssl/ssl.h> | |
19 | 15 |
20 class Downloader: public QThread | 16 class Downloader: public QThread |
21 { | 17 { |
22 Q_OBJECT | 18 Q_OBJECT |
23 | 19 |
36 * @param[in] parent the parent object. | 32 * @param[in] parent the parent object. |
37 * @param[in] url the Url to download data from | 33 * @param[in] url the Url to download data from |
38 * @param[in] certificate optional certificate to validate https connection | 34 * @param[in] certificate optional certificate to validate https connection |
39 * @param[in] newestSW datetime after which software should be downloaded | 35 * @param[in] newestSW datetime after which software should be downloaded |
40 * @param[in] newestList datetime after which the list should be downloaded | 36 * @param[in] newestList datetime after which the list should be downloaded |
37 * @param[in] resourceSW the path where the software is to be found | |
38 * @param[in] resourceList the path where the list is to be found | |
41 */ | 39 */ |
42 Downloader(QObject* parent, const QString& url, | 40 Downloader(QObject* parent, const QString& url, |
43 const QByteArray& certificate = QByteArray(), | 41 const QByteArray& certificate = QByteArray(), |
44 const QDateTime& newestSW = QDateTime(), | 42 const QDateTime& newestSW = QDateTime(), |
45 const QDateTime& newestList = QDateTime()); | 43 const QDateTime& newestList = QDateTime(), |
44 const QString& resourceSW = QString(), | |
45 const QString& resourceList = QString()); | |
46 | 46 |
47 ~Downloader(); | 47 ~Downloader(); |
48 | |
49 enum ErrorCode { | |
50 NoError, | |
51 NoConnection, | |
52 SSLHandshakeFailed, | |
53 InvalidCertificate, | |
54 InvalidPinnedCertificate, | |
55 InvalidResponse, | |
56 ConnectionLost, | |
57 Timeout, | |
58 ErrUnknown | |
59 }; | |
60 | 48 |
61 /** | 49 /** |
62 * @brief get the directory where the downloader saves data | 50 * @brief get the directory where the downloader saves data |
63 * | 51 * |
64 * If the directory does not exist this function ensures that it | 52 * If the directory does not exist this function ensures that it |
71 /** | 59 /** |
72 * @brief get the current error state | 60 * @brief get the current error state |
73 * | 61 * |
74 * @returns The current error state. | 62 * @returns The current error state. |
75 **/ | 63 **/ |
76 ErrorCode getErrorState(); | 64 SSLConnection::ErrorCode getErrorState(); |
77 | 65 |
78 protected: | 66 protected: |
79 void run(); | 67 void run(); |
80 | 68 |
81 private: | 69 private: |
82 QUrl mUrl; | |
83 QByteArray mPinnedCert; | |
84 x509_crt mX509PinnedCert; | |
85 entropy_context mEntropy; | |
86 ctr_drbg_context mCtr_drbg; | |
87 ssl_context mSSL; | |
88 | |
89 QDateTime mLastModSW; | 70 QDateTime mLastModSW; |
90 QDateTime mLastModList; | 71 QDateTime mLastModList; |
91 | 72 |
92 /* Convienience to avoid having to parse all | 73 QString mResourceSW; |
93 * PolarSSL errors */ | 74 QString mResourceList; |
94 ErrorCode mErrorState; | |
95 | 75 |
96 bool mInitialized; | 76 SSLConnection mSSLConnection; |
97 bool mConnectionEstablished; | |
98 | |
99 int mServerFD; | |
100 | |
101 | |
102 /* @brief: Initialize polarssl structures | |
103 * | |
104 * This wraps polarssl initialization functions | |
105 * that can return an error. | |
106 * Sets the error state accordingly. | |
107 * | |
108 * @returns: 0 on success a polarssl error otherwise. | |
109 */ | |
110 int init(); | |
111 | |
112 /** @brief: Establish the ssl connection | |
113 * | |
114 * Modifies the error state. Before calling this the mServerFD should | |
115 * be set to a valid socket. | |
116 * | |
117 * @returns 0 on success otherwise a polarssl error or -1 is returned | |
118 */ | |
119 int establishSSLConnection(); | |
120 | 77 |
121 /** @brief get the last modified header of a resource. | 78 /** @brief get the last modified header of a resource. |
122 * | 79 * |
123 * Connection should be established beforehand. | 80 * Connection should be established beforehand. |
124 * Modifies the error state. | 81 * Modifies the error state. |
168 * @brief An error happened | 125 * @brief An error happened |
169 * | 126 * |
170 * @param[out] message: A message to show. Can be empty. | 127 * @param[out] message: A message to show. Can be empty. |
171 * @param[out] errorCode: ErrorCode of this error. | 128 * @param[out] errorCode: ErrorCode of this error. |
172 */ | 129 */ |
173 void error(const QString &message, Downloader::ErrorCode error); | 130 void error(const QString &message, SSLConnection::ErrorCode error); |
174 }; | 131 }; |
175 #endif | 132 #endif |