Prevent data loss when an ssl socket is closed by remote
[profile/ivi/qtbase.git] / src / network / ssl / qsslsocket_openssl_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtNetwork module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42
43 #ifndef QSSLSOCKET_OPENSSL_P_H
44 #define QSSLSOCKET_OPENSSL_P_H
45
46 //
47 //  W A R N I N G
48 //  -------------
49 //
50 // This file is not part of the Qt API.  It exists for the convenience
51 // of the QLibrary class.  This header file may change from
52 // version to version without notice, or even be removed.
53 //
54 // We mean it.
55 //
56
57 #include "qsslsocket_p.h"
58
59 #ifdef Q_OS_WIN
60 #include <qt_windows.h>
61 #if defined(OCSP_RESPONSE)
62 #undef OCSP_RESPONSE
63 #endif
64 #endif
65
66 #include <openssl/asn1.h>
67 #include <openssl/bio.h>
68 #include <openssl/bn.h>
69 #include <openssl/err.h>
70 #include <openssl/evp.h>
71 #include <openssl/pem.h>
72 #include <openssl/pkcs12.h>
73 #include <openssl/pkcs7.h>
74 #include <openssl/rand.h>
75 #include <openssl/ssl.h>
76 #include <openssl/stack.h>
77 #include <openssl/x509.h>
78 #include <openssl/x509v3.h>
79 #include <openssl/x509_vfy.h>
80 #include <openssl/dsa.h>
81 #include <openssl/rsa.h>
82 #include <openssl/crypto.h>
83 #if OPENSSL_VERSION_NUMBER >= 0x0090806fL && !defined(OPENSSL_NO_TLSEXT)
84 #include <openssl/tls1.h>
85 #endif
86
87 #if OPENSSL_VERSION_NUMBER >= 0x10000000L
88 typedef _STACK STACK;
89 #endif
90
91 QT_BEGIN_NAMESPACE
92
93 class QSslSocketBackendPrivate : public QSslSocketPrivate
94 {
95     Q_DECLARE_PUBLIC(QSslSocket)
96 public:
97     QSslSocketBackendPrivate();
98     virtual ~QSslSocketBackendPrivate();
99
100     // SSL context
101     bool initSslContext();
102     void destroySslContext();
103     SSL *ssl;
104     SSL_CTX *ctx;
105     EVP_PKEY *pkey;
106     BIO *readBio;
107     BIO *writeBio;
108     SSL_SESSION *session;
109     QList<QPair<int, int> > errorList;
110
111     // Platform specific functions
112     void startClientEncryption();
113     void startServerEncryption();
114     void transmit();
115     bool startHandshake();
116     void disconnectFromHost();
117     void disconnected();
118     QSslCipher sessionCipher() const;
119     void continueHandshake();
120
121     Q_AUTOTEST_EXPORT static long setupOpenSslOptions(QSsl::SslProtocol protocol, QSsl::SslOptions sslOptions);
122     static QSslCipher QSslCipher_from_SSL_CIPHER(SSL_CIPHER *cipher);
123     static QList<QSslCertificate> STACKOFX509_to_QSslCertificates(STACK_OF(X509) *x509);
124     static bool isMatchingHostname(const QSslCertificate &cert, const QString &peerName);
125     Q_AUTOTEST_EXPORT static bool isMatchingHostname(const QString &cn, const QString &hostname);
126     static QList<QSslError> verify(QList<QSslCertificate> certificateChain, const QString &hostName);
127     static QString getErrorsFromOpenSsl();
128 };
129
130 QT_END_NAMESPACE
131
132 #endif