Mercurial > trustbridge
comparison ui/sslconnection_bare.h @ 908:d1c951b3012d
Curl based implementation of sslconnection
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Wed, 13 Aug 2014 19:35:08 +0200 |
parents | |
children | eaed02defe6a |
comparison
equal
deleted
inserted
replaced
907:7bd75417e14e | 908:d1c951b3012d |
---|---|
1 #ifndef UI_SSLCONNECTION_BARE_H | |
2 #define UI_SSLCONNECTION_BARE_H | |
3 /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik | |
4 * Software engineering by Intevation GmbH | |
5 * | |
6 * This file is Free Software under the GNU GPL (v>=2) | |
7 * and comes with ABSOLUTELY NO WARRANTY! | |
8 * See LICENSE.txt for details. | |
9 */ | |
10 | |
11 #include "sslconnection.h" | |
12 | |
13 #include <polarssl/entropy.h> | |
14 #include <polarssl/net.h> | |
15 #include <polarssl/ssl.h> | |
16 #include <polarssl/ctr_drbg.h> | |
17 #include <polarssl/error.h> | |
18 #include <polarssl/certs.h> | |
19 | |
20 /** | |
21 * @file sslconnection_bare.h | |
22 * @brief SSLConnection doing bare SSL over PolarSSL | |
23 * */ | |
24 | |
25 class SSLConnectionBare : public SSLConnection | |
26 { | |
27 public: | |
28 SSLConnectionBare(const QString& url, | |
29 const QByteArray& certificate = QByteArray()); | |
30 | |
31 ~SSLConnectionBare(); | |
32 | |
33 /** @brief write */ | |
34 int write(const QByteArray& request); | |
35 | |
36 /** | |
37 * @brief read at most len bytes and reset the connection | |
38 * | |
39 * @param [in] len Amount of bytes to read. | |
40 * | |
41 * @returns a byte array containing the data or | |
42 * a NULL byte array on error*/ | |
43 QByteArray read(size_t len); | |
44 | |
45 /** @brief: Establish the connection | |
46 * | |
47 * @returns 0 on success otherwise an error or -1 is returned | |
48 */ | |
49 int connect(); | |
50 | |
51 private: | |
52 x509_crt mX509PinnedCert; | |
53 entropy_context mEntropy; | |
54 ctr_drbg_context mCtr_drbg; | |
55 ssl_context mSSL; | |
56 ssl_session mSavedSession; | |
57 | |
58 /* @brief: Initialize polarssl structures | |
59 * | |
60 * This wraps polarssl initialization functions | |
61 * that can return an error. | |
62 * Sets the error state accordingly. | |
63 * | |
64 * @returns: 0 on success a polarssl error otherwise. | |
65 */ | |
66 int init(); | |
67 | |
68 /* @brief Reset the connection. | |
69 * | |
70 * Resets the https connection and does another handshake. | |
71 * | |
72 * @returns: 0 on success a polarssl error or -1 otherwise. */ | |
73 int reset(); | |
74 | |
75 /* @brief validates that the certificate matches the pinned one. | |
76 * | |
77 * Checks the peer certificate of mSSL and validates that the | |
78 * certificate matches mPinnedCertificate. | |
79 * | |
80 * @returns: 0 on success a polarssl error or -1 otherwise. */ | |
81 int validateCertificate(); | |
82 | |
83 /* @brief disconnects the connection */ | |
84 void disconnect(); | |
85 }; | |
86 | |
87 #endif // UI_SSLCONNECTION_BARE_H |