author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Wed, 21 Apr 2010 20:15:53 +0300 | |
branch | RCL_3 |
changeset 13 | c0432d11811c |
parent 7 | 3f74d0d4af4c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
||
43 |
#include <QtCore/qthread.h> |
|
44 |
#include <QtNetwork/qhostaddress.h> |
|
45 |
#include <QtNetwork/qhostinfo.h> |
|
46 |
#include <QtNetwork/qnetworkproxy.h> |
|
47 |
#include <QtNetwork/qsslcipher.h> |
|
48 |
#include <QtNetwork/qsslconfiguration.h> |
|
49 |
#include <QtNetwork/qsslkey.h> |
|
50 |
#include <QtNetwork/qsslsocket.h> |
|
51 |
#include <QtNetwork/qtcpserver.h> |
|
52 |
#include <QtTest/QtTest> |
|
53 |
||
54 |
#include <QNetworkProxy> |
|
55 |
#include <QAuthenticator> |
|
56 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
57 |
#include "private/qhostinfo_p.h" |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
58 |
|
0 | 59 |
#include "../network-settings.h" |
60 |
||
61 |
Q_DECLARE_METATYPE(QAbstractSocket::SocketState) |
|
62 |
Q_DECLARE_METATYPE(QAbstractSocket::SocketError) |
|
63 |
#ifndef QT_NO_OPENSSL |
|
64 |
Q_DECLARE_METATYPE(QSslSocket::SslMode) |
|
65 |
typedef QList<QSslError::SslError> SslErrorList; |
|
66 |
Q_DECLARE_METATYPE(SslErrorList) |
|
67 |
Q_DECLARE_METATYPE(QSslError) |
|
68 |
#endif |
|
69 |
||
70 |
#if defined Q_OS_HPUX && defined Q_CC_GNU |
|
71 |
// This error is delivered every time we try to use the fluke CA |
|
72 |
// certificate. For now we work around this bug. Task 202317. |
|
73 |
#define QSSLSOCKET_CERTUNTRUSTED_WORKAROUND |
|
74 |
#endif |
|
75 |
||
76 |
#ifdef Q_OS_SYMBIAN |
|
77 |
#define SRCDIR "" |
|
78 |
#endif |
|
79 |
||
80 |
#ifndef QT_NO_OPENSSL |
|
81 |
class QSslSocketPtr: public QSharedPointer<QSslSocket> |
|
82 |
{ |
|
83 |
public: |
|
84 |
inline QSslSocketPtr(QSslSocket *ptr = 0) |
|
85 |
: QSharedPointer<QSslSocket>(ptr) |
|
86 |
{ } |
|
87 |
||
88 |
inline operator QSslSocket *() const { return data(); } |
|
89 |
}; |
|
90 |
#endif |
|
91 |
||
92 |
class tst_QSslSocket : public QObject |
|
93 |
{ |
|
94 |
Q_OBJECT |
|
95 |
||
96 |
int proxyAuthCalled; |
|
97 |
||
98 |
public: |
|
99 |
tst_QSslSocket(); |
|
100 |
virtual ~tst_QSslSocket(); |
|
101 |
||
102 |
static void enterLoop(int secs) |
|
103 |
{ |
|
104 |
++loopLevel; |
|
105 |
QTestEventLoop::instance().enterLoop(secs); |
|
106 |
} |
|
107 |
||
108 |
static bool timeout() |
|
109 |
{ |
|
110 |
return QTestEventLoop::instance().timeout(); |
|
111 |
} |
|
112 |
||
113 |
#ifndef QT_NO_OPENSSL |
|
114 |
QSslSocketPtr newSocket(); |
|
115 |
#endif |
|
116 |
||
117 |
public slots: |
|
118 |
void initTestCase_data(); |
|
119 |
void init(); |
|
120 |
void cleanup(); |
|
121 |
void proxyAuthenticationRequired(const QNetworkProxy &, QAuthenticator *auth); |
|
122 |
||
123 |
#ifndef QT_NO_OPENSSL |
|
124 |
private slots: |
|
125 |
void constructing(); |
|
126 |
void simpleConnect(); |
|
127 |
void simpleConnectWithIgnore(); |
|
128 |
||
129 |
// API tests |
|
130 |
void sslErrors_data(); |
|
131 |
void sslErrors(); |
|
132 |
void addCaCertificate(); |
|
133 |
void addCaCertificates(); |
|
134 |
void addCaCertificates2(); |
|
135 |
void ciphers(); |
|
136 |
void connectToHostEncrypted(); |
|
137 |
void connectToHostEncryptedWithVerificationPeerName(); |
|
138 |
void sessionCipher(); |
|
139 |
void flush(); |
|
140 |
void isEncrypted(); |
|
141 |
void localCertificate(); |
|
142 |
void mode(); |
|
143 |
void peerCertificate(); |
|
144 |
void peerCertificateChain(); |
|
145 |
void privateKey(); |
|
146 |
void protocol(); |
|
147 |
void setCaCertificates(); |
|
148 |
void setLocalCertificate(); |
|
149 |
void setPrivateKey(); |
|
150 |
void setProtocol(); |
|
151 |
void setSocketDescriptor(); |
|
152 |
void waitForEncrypted(); |
|
153 |
void waitForConnectedEncryptedReadyRead(); |
|
154 |
void startClientEncryption(); |
|
155 |
void startServerEncryption(); |
|
156 |
void addDefaultCaCertificate(); |
|
157 |
void addDefaultCaCertificates(); |
|
158 |
void addDefaultCaCertificates2(); |
|
159 |
void defaultCaCertificates(); |
|
160 |
void defaultCiphers(); |
|
161 |
void resetDefaultCiphers(); |
|
162 |
void setDefaultCaCertificates(); |
|
163 |
void setDefaultCiphers(); |
|
164 |
void supportedCiphers(); |
|
165 |
void systemCaCertificates(); |
|
166 |
void wildcard(); |
|
167 |
void setEmptyKey(); |
|
168 |
void spontaneousWrite(); |
|
169 |
void setReadBufferSize(); |
|
170 |
void setReadBufferSize_task_250027(); |
|
171 |
void waitForMinusOne(); |
|
172 |
void verifyMode(); |
|
173 |
void verifyDepth(); |
|
174 |
void peerVerifyError(); |
|
175 |
void disconnectFromHostWhenConnecting(); |
|
176 |
void disconnectFromHostWhenConnected(); |
|
177 |
void resetProxy(); |
|
178 |
void ignoreSslErrorsList_data(); |
|
179 |
void ignoreSslErrorsList(); |
|
180 |
void ignoreSslErrorsListWithSlot_data(); |
|
181 |
void ignoreSslErrorsListWithSlot(); |
|
182 |
void readFromClosedSocket(); |
|
183 |
void writeBigChunk(); |
|
184 |
||
185 |
static void exitLoop() |
|
186 |
{ |
|
187 |
// Safe exit - if we aren't in an event loop, don't |
|
188 |
// exit one. |
|
189 |
if (loopLevel > 0) { |
|
190 |
--loopLevel; |
|
191 |
QTestEventLoop::instance().exitLoop(); |
|
192 |
} |
|
193 |
} |
|
194 |
||
195 |
protected slots: |
|
196 |
void ignoreErrorSlot() |
|
197 |
{ |
|
198 |
socket->ignoreSslErrors(); |
|
199 |
} |
|
200 |
void untrustedWorkaroundSlot(const QList<QSslError> &errors) |
|
201 |
{ |
|
202 |
if (errors.size() == 1 && |
|
203 |
(errors.first().error() == QSslError::CertificateUntrusted || |
|
204 |
errors.first().error() == QSslError::SelfSignedCertificate)) |
|
205 |
socket->ignoreSslErrors(); |
|
206 |
} |
|
207 |
void ignoreErrorListSlot(const QList<QSslError> &errors); |
|
208 |
||
209 |
private: |
|
210 |
QSslSocket *socket; |
|
211 |
QList<QSslError> storedExpectedSslErrors; |
|
212 |
#endif // QT_NO_OPENSSL |
|
213 |
private: |
|
214 |
static int loopLevel; |
|
215 |
}; |
|
216 |
||
217 |
int tst_QSslSocket::loopLevel = 0; |
|
218 |
||
219 |
tst_QSslSocket::tst_QSslSocket() |
|
220 |
{ |
|
221 |
#ifndef QT_NO_OPENSSL |
|
222 |
qRegisterMetaType<QList<QSslError> >("QList<QSslError>"); |
|
223 |
qRegisterMetaType<QSslError>("QSslError"); |
|
224 |
qRegisterMetaType<QAbstractSocket::SocketState>("QAbstractSocket::SocketState"); |
|
225 |
qRegisterMetaType<QAbstractSocket::SocketError>("QAbstractSocket::SocketError"); |
|
226 |
qRegisterMetaType<QAbstractSocket::SocketState>("QSslSocket::SslMode"); |
|
227 |
#endif |
|
228 |
Q_SET_DEFAULT_IAP |
|
229 |
} |
|
230 |
||
231 |
tst_QSslSocket::~tst_QSslSocket() |
|
232 |
{ |
|
233 |
} |
|
234 |
||
235 |
enum ProxyTests { |
|
236 |
NoProxy = 0x00, |
|
237 |
Socks5Proxy = 0x01, |
|
238 |
HttpProxy = 0x02, |
|
239 |
TypeMask = 0x0f, |
|
240 |
||
241 |
NoAuth = 0x00, |
|
242 |
AuthBasic = 0x10, |
|
243 |
AuthNtlm = 0x20, |
|
244 |
AuthMask = 0xf0 |
|
245 |
}; |
|
246 |
||
247 |
void tst_QSslSocket::initTestCase_data() |
|
248 |
{ |
|
249 |
QTest::addColumn<bool>("setProxy"); |
|
250 |
QTest::addColumn<int>("proxyType"); |
|
251 |
||
252 |
QTest::newRow("WithoutProxy") << false << 0; |
|
253 |
QTest::newRow("WithSocks5Proxy") << true << int(Socks5Proxy); |
|
254 |
QTest::newRow("WithSocks5ProxyAuth") << true << int(Socks5Proxy | AuthBasic); |
|
255 |
||
256 |
QTest::newRow("WithHttpProxy") << true << int(HttpProxy); |
|
257 |
QTest::newRow("WithHttpProxyBasicAuth") << true << int(HttpProxy | AuthBasic); |
|
258 |
// uncomment the line below when NTLM works |
|
259 |
// QTest::newRow("WithHttpProxyNtlmAuth") << true << int(HttpProxy | AuthNtlm); |
|
260 |
} |
|
261 |
||
262 |
void tst_QSslSocket::init() |
|
263 |
{ |
|
264 |
QFETCH_GLOBAL(bool, setProxy); |
|
265 |
if (setProxy) { |
|
266 |
QFETCH_GLOBAL(int, proxyType); |
|
267 |
QString fluke = QHostInfo::fromName(QtNetworkSettings::serverName()).addresses().first().toString(); |
|
268 |
QNetworkProxy proxy; |
|
269 |
||
270 |
switch (proxyType) { |
|
271 |
case Socks5Proxy: |
|
272 |
proxy = QNetworkProxy(QNetworkProxy::Socks5Proxy, fluke, 1080); |
|
273 |
break; |
|
274 |
||
275 |
case Socks5Proxy | AuthBasic: |
|
276 |
proxy = QNetworkProxy(QNetworkProxy::Socks5Proxy, fluke, 1081); |
|
277 |
break; |
|
278 |
||
279 |
case HttpProxy | NoAuth: |
|
280 |
proxy = QNetworkProxy(QNetworkProxy::HttpProxy, fluke, 3128); |
|
281 |
break; |
|
282 |
||
283 |
case HttpProxy | AuthBasic: |
|
284 |
proxy = QNetworkProxy(QNetworkProxy::HttpProxy, fluke, 3129); |
|
285 |
break; |
|
286 |
||
287 |
case HttpProxy | AuthNtlm: |
|
288 |
proxy = QNetworkProxy(QNetworkProxy::HttpProxy, fluke, 3130); |
|
289 |
break; |
|
290 |
} |
|
291 |
QNetworkProxy::setApplicationProxy(proxy); |
|
292 |
} |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
293 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
294 |
qt_qhostinfo_clear_cache(); |
0 | 295 |
} |
296 |
||
297 |
void tst_QSslSocket::cleanup() |
|
298 |
{ |
|
299 |
QNetworkProxy::setApplicationProxy(QNetworkProxy::DefaultProxy); |
|
300 |
} |
|
301 |
||
302 |
#ifndef QT_NO_OPENSSL |
|
303 |
QSslSocketPtr tst_QSslSocket::newSocket() |
|
304 |
{ |
|
305 |
QSslSocket *socket = new QSslSocket; |
|
306 |
||
307 |
proxyAuthCalled = 0; |
|
308 |
connect(socket, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), |
|
309 |
SLOT(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), |
|
310 |
Qt::DirectConnection); |
|
311 |
||
312 |
return QSslSocketPtr(socket); |
|
313 |
} |
|
314 |
#endif |
|
315 |
||
316 |
void tst_QSslSocket::proxyAuthenticationRequired(const QNetworkProxy &, QAuthenticator *auth) |
|
317 |
{ |
|
318 |
++proxyAuthCalled; |
|
319 |
auth->setUser("qsockstest"); |
|
320 |
auth->setPassword("password"); |
|
321 |
} |
|
322 |
||
323 |
#ifndef QT_NO_OPENSSL |
|
324 |
||
325 |
void tst_QSslSocket::constructing() |
|
326 |
{ |
|
327 |
if (!QSslSocket::supportsSsl()) |
|
328 |
return; |
|
329 |
||
330 |
QSslSocket socket; |
|
331 |
||
332 |
QCOMPARE(socket.state(), QSslSocket::UnconnectedState); |
|
333 |
QCOMPARE(socket.mode(), QSslSocket::UnencryptedMode); |
|
334 |
QVERIFY(!socket.isEncrypted()); |
|
335 |
QCOMPARE(socket.bytesAvailable(), qint64(0)); |
|
336 |
QCOMPARE(socket.bytesToWrite(), qint64(0)); |
|
337 |
QVERIFY(!socket.canReadLine()); |
|
338 |
QVERIFY(socket.atEnd()); |
|
339 |
QCOMPARE(socket.localCertificate(), QSslCertificate()); |
|
340 |
QCOMPARE(socket.sslConfiguration(), QSslConfiguration::defaultConfiguration()); |
|
341 |
QCOMPARE(socket.errorString(), QString("Unknown error")); |
|
342 |
char c = '\0'; |
|
343 |
QVERIFY(!socket.getChar(&c)); |
|
344 |
QCOMPARE(c, '\0'); |
|
345 |
QVERIFY(!socket.isOpen()); |
|
346 |
QVERIFY(!socket.isReadable()); |
|
347 |
QVERIFY(socket.isSequential()); |
|
348 |
QVERIFY(!socket.isTextModeEnabled()); |
|
349 |
QVERIFY(!socket.isWritable()); |
|
350 |
QCOMPARE(socket.openMode(), QIODevice::NotOpen); |
|
351 |
QVERIFY(socket.peek(2).isEmpty()); |
|
352 |
QCOMPARE(socket.pos(), qint64(0)); |
|
353 |
QVERIFY(!socket.putChar('c')); |
|
354 |
QVERIFY(socket.read(2).isEmpty()); |
|
355 |
QCOMPARE(socket.read(0, 0), qint64(-1)); |
|
356 |
QVERIFY(socket.readAll().isEmpty()); |
|
357 |
QTest::ignoreMessage(QtWarningMsg, "QIODevice::readLine: Called with maxSize < 2"); |
|
358 |
QCOMPARE(socket.readLine(0, 0), qint64(-1)); |
|
359 |
char buf[10]; |
|
360 |
QCOMPARE(socket.readLine(buf, sizeof(buf)), qint64(-1)); |
|
361 |
QTest::ignoreMessage(QtWarningMsg, "QIODevice::seek: The device is not open"); |
|
362 |
QVERIFY(!socket.reset()); |
|
363 |
QTest::ignoreMessage(QtWarningMsg, "QIODevice::seek: The device is not open"); |
|
364 |
QVERIFY(!socket.seek(2)); |
|
365 |
QCOMPARE(socket.size(), qint64(0)); |
|
366 |
QVERIFY(!socket.waitForBytesWritten(10)); |
|
367 |
QVERIFY(!socket.waitForReadyRead(10)); |
|
368 |
QCOMPARE(socket.write(0, 0), qint64(-1)); |
|
369 |
QCOMPARE(socket.write(QByteArray()), qint64(-1)); |
|
370 |
QCOMPARE(socket.error(), QAbstractSocket::UnknownSocketError); |
|
371 |
QVERIFY(!socket.flush()); |
|
372 |
QVERIFY(!socket.isValid()); |
|
373 |
QCOMPARE(socket.localAddress(), QHostAddress()); |
|
374 |
QCOMPARE(socket.localPort(), quint16(0)); |
|
375 |
QCOMPARE(socket.peerAddress(), QHostAddress()); |
|
376 |
QVERIFY(socket.peerName().isEmpty()); |
|
377 |
QCOMPARE(socket.peerPort(), quint16(0)); |
|
378 |
QCOMPARE(socket.proxy().type(), QNetworkProxy::DefaultProxy); |
|
379 |
QCOMPARE(socket.readBufferSize(), qint64(0)); |
|
380 |
QCOMPARE(socket.socketDescriptor(), -1); |
|
381 |
QCOMPARE(socket.socketType(), QAbstractSocket::TcpSocket); |
|
382 |
QVERIFY(!socket.waitForConnected(10)); |
|
383 |
QTest::ignoreMessage(QtWarningMsg, "QSslSocket::waitForDisconnected() is not allowed in UnconnectedState"); |
|
384 |
QVERIFY(!socket.waitForDisconnected(10)); |
|
385 |
QCOMPARE(socket.protocol(), QSsl::SslV3); |
|
386 |
||
387 |
QSslConfiguration savedDefault = QSslConfiguration::defaultConfiguration(); |
|
388 |
||
389 |
// verify that changing the default config doesn't affect this socket |
|
390 |
QSslSocket::setDefaultCaCertificates(QList<QSslCertificate>()); |
|
391 |
QSslSocket::setDefaultCiphers(QList<QSslCipher>()); |
|
392 |
QVERIFY(!socket.caCertificates().isEmpty()); |
|
393 |
QVERIFY(!socket.ciphers().isEmpty()); |
|
394 |
||
395 |
// verify the default as well: |
|
396 |
QVERIFY(QSslConfiguration::defaultConfiguration().caCertificates().isEmpty()); |
|
397 |
QVERIFY(QSslConfiguration::defaultConfiguration().ciphers().isEmpty()); |
|
398 |
||
399 |
QSslConfiguration::setDefaultConfiguration(savedDefault); |
|
400 |
} |
|
401 |
||
402 |
void tst_QSslSocket::simpleConnect() |
|
403 |
{ |
|
404 |
if (!QSslSocket::supportsSsl()) |
|
405 |
return; |
|
406 |
||
407 |
QFETCH_GLOBAL(bool, setProxy); |
|
408 |
if (setProxy) |
|
409 |
return; |
|
410 |
||
411 |
QSslSocket socket; |
|
412 |
QSignalSpy connectedSpy(&socket, SIGNAL(connected())); |
|
413 |
QSignalSpy hostFoundSpy(&socket, SIGNAL(hostFound())); |
|
414 |
QSignalSpy disconnectedSpy(&socket, SIGNAL(disconnected())); |
|
415 |
QSignalSpy connectionEncryptedSpy(&socket, SIGNAL(encrypted())); |
|
416 |
QSignalSpy sslErrorsSpy(&socket, SIGNAL(sslErrors(const QList<QSslError> &))); |
|
417 |
||
418 |
connect(&socket, SIGNAL(connected()), this, SLOT(exitLoop())); |
|
419 |
connect(&socket, SIGNAL(disconnected()), this, SLOT(exitLoop())); |
|
420 |
connect(&socket, SIGNAL(modeChanged(QSslSocket::SslMode)), this, SLOT(exitLoop())); |
|
421 |
connect(&socket, SIGNAL(encrypted()), this, SLOT(exitLoop())); |
|
422 |
connect(&socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(exitLoop())); |
|
423 |
connect(&socket, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(exitLoop())); |
|
424 |
||
425 |
// Start connecting |
|
426 |
socket.connectToHost(QtNetworkSettings::serverName(), 993); |
|
427 |
QCOMPARE(socket.state(), QAbstractSocket::HostLookupState); |
|
428 |
enterLoop(10); |
|
429 |
||
430 |
// Entered connecting state |
|
431 |
#ifndef Q_OS_SYMBIAN |
|
432 |
QCOMPARE(socket.state(), QAbstractSocket::ConnectingState); |
|
433 |
QCOMPARE(connectedSpy.count(), 0); |
|
434 |
#endif |
|
435 |
QCOMPARE(hostFoundSpy.count(), 1); |
|
436 |
QCOMPARE(disconnectedSpy.count(), 0); |
|
437 |
enterLoop(10); |
|
438 |
||
439 |
// Entered connected state |
|
440 |
QCOMPARE(socket.state(), QAbstractSocket::ConnectedState); |
|
441 |
QCOMPARE(socket.mode(), QSslSocket::UnencryptedMode); |
|
442 |
QVERIFY(!socket.isEncrypted()); |
|
443 |
QCOMPARE(connectedSpy.count(), 1); |
|
444 |
QCOMPARE(hostFoundSpy.count(), 1); |
|
445 |
QCOMPARE(disconnectedSpy.count(), 0); |
|
446 |
||
447 |
// Enter encrypted mode |
|
448 |
socket.startClientEncryption(); |
|
449 |
QCOMPARE(socket.mode(), QSslSocket::SslClientMode); |
|
450 |
QVERIFY(!socket.isEncrypted()); |
|
451 |
QCOMPARE(connectionEncryptedSpy.count(), 0); |
|
452 |
QCOMPARE(sslErrorsSpy.count(), 0); |
|
453 |
||
454 |
// Starting handshake |
|
455 |
enterLoop(10); |
|
456 |
QCOMPARE(sslErrorsSpy.count(), 1); |
|
457 |
QCOMPARE(connectionEncryptedSpy.count(), 0); |
|
458 |
QVERIFY(!socket.isEncrypted()); |
|
459 |
QCOMPARE(socket.state(), QAbstractSocket::UnconnectedState); |
|
460 |
} |
|
461 |
||
462 |
void tst_QSslSocket::simpleConnectWithIgnore() |
|
463 |
{ |
|
464 |
if (!QSslSocket::supportsSsl()) |
|
465 |
return; |
|
466 |
||
467 |
QFETCH_GLOBAL(bool, setProxy); |
|
468 |
if (setProxy) |
|
469 |
return; |
|
470 |
||
471 |
QSslSocket socket; |
|
472 |
this->socket = &socket; |
|
473 |
QSignalSpy encryptedSpy(&socket, SIGNAL(encrypted())); |
|
474 |
QSignalSpy sslErrorsSpy(&socket, SIGNAL(sslErrors(const QList<QSslError> &))); |
|
475 |
||
476 |
connect(&socket, SIGNAL(readyRead()), this, SLOT(exitLoop())); |
|
477 |
connect(&socket, SIGNAL(encrypted()), this, SLOT(exitLoop())); |
|
478 |
connect(&socket, SIGNAL(connected()), this, SLOT(exitLoop())); |
|
479 |
connect(&socket, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(ignoreErrorSlot())); |
|
480 |
connect(&socket, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(exitLoop())); |
|
481 |
||
482 |
// Start connecting |
|
483 |
socket.connectToHost(QtNetworkSettings::serverName(), 993); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
484 |
QVERIFY(socket.state() != QAbstractSocket::UnconnectedState); // something must be in progress |
0 | 485 |
enterLoop(10); |
486 |
||
487 |
// Start handshake |
|
488 |
QCOMPARE(socket.state(), QAbstractSocket::ConnectedState); |
|
489 |
socket.startClientEncryption(); |
|
490 |
enterLoop(10); |
|
491 |
||
492 |
// Done; encryption should be enabled. |
|
493 |
QCOMPARE(sslErrorsSpy.count(), 1); |
|
494 |
QVERIFY(socket.isEncrypted()); |
|
495 |
QCOMPARE(socket.state(), QAbstractSocket::ConnectedState); |
|
496 |
QCOMPARE(encryptedSpy.count(), 1); |
|
497 |
||
498 |
// Wait for incoming data |
|
499 |
if (!socket.canReadLine()) |
|
500 |
enterLoop(10); |
|
501 |
||
502 |
QCOMPARE(socket.readAll(), QtNetworkSettings::expectedReplySSL()); |
|
503 |
socket.disconnectFromHost(); |
|
504 |
} |
|
505 |
||
506 |
void tst_QSslSocket::sslErrors_data() |
|
507 |
{ |
|
508 |
QTest::addColumn<QString>("host"); |
|
509 |
QTest::addColumn<int>("port"); |
|
510 |
QTest::addColumn<SslErrorList>("expected"); |
|
511 |
||
512 |
QTest::newRow(qPrintable(QtNetworkSettings::serverLocalName())) |
|
513 |
<< QtNetworkSettings::serverLocalName() |
|
514 |
<< 993 |
|
515 |
<< (SslErrorList() << QSslError::HostNameMismatch |
|
516 |
<< QSslError::SelfSignedCertificate); |
|
517 |
||
518 |
QTest::newRow("imap.trolltech.com") |
|
519 |
<< "imap.trolltech.com" |
|
520 |
<< 993 |
|
521 |
<< (SslErrorList() << QSslError::SelfSignedCertificateInChain); |
|
522 |
} |
|
523 |
||
524 |
void tst_QSslSocket::sslErrors() |
|
525 |
{ |
|
526 |
QFETCH(QString, host); |
|
527 |
QFETCH(int, port); |
|
528 |
QFETCH(SslErrorList, expected); |
|
529 |
||
530 |
QSslSocketPtr socket = newSocket(); |
|
531 |
socket->connectToHostEncrypted(host, port); |
|
532 |
socket->waitForEncrypted(5000); |
|
533 |
||
534 |
SslErrorList output; |
|
535 |
foreach (QSslError error, socket->sslErrors()) { |
|
536 |
output << error.error(); |
|
537 |
} |
|
538 |
||
539 |
#ifdef QSSLSOCKET_CERTUNTRUSTED_WORKAROUND |
|
540 |
if (output.last() == QSslError::CertificateUntrusted) |
|
541 |
output.takeLast(); |
|
542 |
#endif |
|
543 |
QCOMPARE(output, expected); |
|
544 |
} |
|
545 |
||
546 |
void tst_QSslSocket::addCaCertificate() |
|
547 |
{ |
|
548 |
if (!QSslSocket::supportsSsl()) |
|
549 |
return; |
|
550 |
} |
|
551 |
||
552 |
void tst_QSslSocket::addCaCertificates() |
|
553 |
{ |
|
554 |
if (!QSslSocket::supportsSsl()) |
|
555 |
return; |
|
556 |
} |
|
557 |
||
558 |
void tst_QSslSocket::addCaCertificates2() |
|
559 |
{ |
|
560 |
if (!QSslSocket::supportsSsl()) |
|
561 |
return; |
|
562 |
} |
|
563 |
||
564 |
void tst_QSslSocket::ciphers() |
|
565 |
{ |
|
566 |
if (!QSslSocket::supportsSsl()) |
|
567 |
return; |
|
568 |
||
569 |
QSslSocket socket; |
|
570 |
QCOMPARE(socket.ciphers(), QSslSocket::supportedCiphers()); |
|
571 |
socket.setCiphers(QList<QSslCipher>()); |
|
572 |
QVERIFY(socket.ciphers().isEmpty()); |
|
573 |
socket.setCiphers(socket.defaultCiphers()); |
|
574 |
QCOMPARE(socket.ciphers(), QSslSocket::supportedCiphers()); |
|
575 |
socket.setCiphers(socket.defaultCiphers()); |
|
576 |
QCOMPARE(socket.ciphers(), QSslSocket::supportedCiphers()); |
|
577 |
||
578 |
// Task 164356 |
|
579 |
socket.setCiphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH"); |
|
580 |
} |
|
581 |
||
582 |
void tst_QSslSocket::connectToHostEncrypted() |
|
583 |
{ |
|
584 |
if (!QSslSocket::supportsSsl()) |
|
585 |
return; |
|
586 |
||
587 |
QSslSocketPtr socket = newSocket(); |
|
588 |
this->socket = socket; |
|
589 |
QVERIFY(socket->addCaCertificates(QLatin1String(SRCDIR "certs/qt-test-server-cacert.pem"))); |
|
590 |
#ifdef QSSLSOCKET_CERTUNTRUSTED_WORKAROUND |
|
591 |
connect(socket, SIGNAL(sslErrors(QList<QSslError>)), |
|
592 |
this, SLOT(untrustedWorkaroundSlot(QList<QSslError>))); |
|
593 |
#endif |
|
594 |
||
595 |
socket->connectToHostEncrypted(QtNetworkSettings::serverName(), 443); |
|
596 |
||
597 |
// This should pass unconditionally when using fluke's CA certificate. |
|
598 |
// or use untrusted certificate workaround |
|
599 |
QVERIFY2(socket->waitForEncrypted(10000), qPrintable(socket->errorString())); |
|
600 |
||
601 |
socket->disconnectFromHost(); |
|
602 |
QVERIFY(socket->waitForDisconnected()); |
|
603 |
||
604 |
QCOMPARE(socket->mode(), QSslSocket::SslClientMode); |
|
605 |
||
606 |
socket->connectToHost(QtNetworkSettings::serverName(), 13); |
|
607 |
||
608 |
QCOMPARE(socket->mode(), QSslSocket::UnencryptedMode); |
|
609 |
||
610 |
QVERIFY(socket->waitForDisconnected()); |
|
611 |
} |
|
612 |
||
613 |
void tst_QSslSocket::connectToHostEncryptedWithVerificationPeerName() |
|
614 |
{ |
|
615 |
if (!QSslSocket::supportsSsl()) |
|
616 |
return; |
|
617 |
||
618 |
QSslSocketPtr socket = newSocket(); |
|
619 |
this->socket = socket; |
|
620 |
||
621 |
socket->addCaCertificates(QLatin1String(SRCDIR "certs/qt-test-server-cacert.pem")); |
|
622 |
#ifdef QSSLSOCKET_CERTUNTRUSTED_WORKAROUND |
|
623 |
connect(socket, SIGNAL(sslErrors(QList<QSslError>)), |
|
624 |
this, SLOT(untrustedWorkaroundSlot(QList<QSslError>))); |
|
625 |
#endif |
|
626 |
||
627 |
// connect to the server with its local name, but use the full name for verification. |
|
628 |
socket->connectToHostEncrypted(QtNetworkSettings::serverLocalName(), 443, QtNetworkSettings::serverName()); |
|
629 |
||
630 |
// This should pass unconditionally when using fluke's CA certificate. |
|
631 |
QVERIFY2(socket->waitForEncrypted(10000), qPrintable(socket->errorString())); |
|
632 |
||
633 |
socket->disconnectFromHost(); |
|
634 |
QVERIFY(socket->waitForDisconnected()); |
|
635 |
||
636 |
QCOMPARE(socket->mode(), QSslSocket::SslClientMode); |
|
637 |
} |
|
638 |
||
639 |
void tst_QSslSocket::sessionCipher() |
|
640 |
{ |
|
641 |
if (!QSslSocket::supportsSsl()) |
|
642 |
return; |
|
643 |
||
644 |
QSslSocketPtr socket = newSocket(); |
|
645 |
this->socket = socket; |
|
646 |
connect(socket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(ignoreErrorSlot())); |
|
647 |
QVERIFY(socket->sessionCipher().isNull()); |
|
648 |
socket->connectToHost(QtNetworkSettings::serverName(), 443 /* https */); |
|
649 |
QVERIFY(socket->waitForConnected(5000)); |
|
650 |
QVERIFY(socket->sessionCipher().isNull()); |
|
651 |
socket->startClientEncryption(); |
|
652 |
QVERIFY(socket->waitForEncrypted(5000)); |
|
653 |
QVERIFY(!socket->sessionCipher().isNull()); |
|
654 |
QVERIFY(QSslSocket::supportedCiphers().contains(socket->sessionCipher())); |
|
655 |
socket->disconnectFromHost(); |
|
656 |
QVERIFY(socket->waitForDisconnected()); |
|
657 |
} |
|
658 |
||
659 |
void tst_QSslSocket::flush() |
|
660 |
{ |
|
661 |
} |
|
662 |
||
663 |
void tst_QSslSocket::isEncrypted() |
|
664 |
{ |
|
665 |
} |
|
666 |
||
667 |
void tst_QSslSocket::localCertificate() |
|
668 |
{ |
|
669 |
} |
|
670 |
||
671 |
void tst_QSslSocket::mode() |
|
672 |
{ |
|
673 |
} |
|
674 |
||
675 |
void tst_QSslSocket::peerCertificate() |
|
676 |
{ |
|
677 |
} |
|
678 |
||
679 |
void tst_QSslSocket::peerCertificateChain() |
|
680 |
{ |
|
681 |
if (!QSslSocket::supportsSsl()) |
|
682 |
return; |
|
683 |
||
684 |
QSslSocketPtr socket = newSocket(); |
|
685 |
this->socket = socket; |
|
686 |
||
687 |
QList<QSslCertificate> caCertificates = QSslCertificate::fromPath(QLatin1String(SRCDIR "certs/qt-test-server-cacert.pem")); |
|
688 |
QVERIFY(caCertificates.count() == 1); |
|
689 |
socket->addCaCertificates(caCertificates); |
|
690 |
#ifdef QSSLSOCKET_CERTUNTRUSTED_WORKAROUND |
|
691 |
connect(socket, SIGNAL(sslErrors(QList<QSslError>)), |
|
692 |
this, SLOT(untrustedWorkaroundSlot(QList<QSslError>))); |
|
693 |
#endif |
|
694 |
||
695 |
socket->connectToHostEncrypted(QtNetworkSettings::serverName(), 443); |
|
696 |
QCOMPARE(socket->mode(), QSslSocket::UnencryptedMode); |
|
697 |
QVERIFY(socket->peerCertificateChain().isEmpty()); |
|
698 |
QVERIFY2(socket->waitForEncrypted(10000), qPrintable(socket->errorString())); |
|
699 |
||
700 |
QList<QSslCertificate> certChain = socket->peerCertificateChain(); |
|
701 |
QVERIFY(certChain.count() > 0); |
|
702 |
QCOMPARE(certChain.first(), socket->peerCertificate()); |
|
703 |
||
704 |
socket->disconnectFromHost(); |
|
705 |
QVERIFY(socket->waitForDisconnected()); |
|
706 |
||
707 |
// connect again to a different server |
|
708 |
socket->connectToHostEncrypted("trolltech.com", 443); |
|
709 |
socket->ignoreSslErrors(); |
|
710 |
QCOMPARE(socket->mode(), QSslSocket::UnencryptedMode); |
|
711 |
QVERIFY(socket->peerCertificateChain().isEmpty()); |
|
712 |
QVERIFY2(socket->waitForEncrypted(10000), qPrintable(socket->errorString())); |
|
713 |
||
714 |
QCOMPARE(socket->peerCertificateChain().first(), socket->peerCertificate()); |
|
715 |
QVERIFY(socket->peerCertificateChain() != certChain); |
|
716 |
||
717 |
socket->disconnectFromHost(); |
|
718 |
QVERIFY(socket->waitForDisconnected()); |
|
719 |
||
720 |
// now do it again back to the original server |
|
721 |
socket->connectToHost(QtNetworkSettings::serverName(), 443); |
|
722 |
QCOMPARE(socket->mode(), QSslSocket::UnencryptedMode); |
|
723 |
QVERIFY(socket->peerCertificateChain().isEmpty()); |
|
724 |
QVERIFY2(socket->waitForConnected(10000), "Network timeout"); |
|
725 |
||
726 |
socket->startClientEncryption(); |
|
727 |
QVERIFY2(socket->waitForEncrypted(10000), qPrintable(socket->errorString())); |
|
728 |
||
729 |
QCOMPARE(socket->peerCertificateChain().first(), socket->peerCertificate()); |
|
730 |
QVERIFY(socket->peerCertificateChain() == certChain); |
|
731 |
||
732 |
socket->disconnectFromHost(); |
|
733 |
QVERIFY(socket->waitForDisconnected()); |
|
734 |
} |
|
735 |
||
736 |
void tst_QSslSocket::privateKey() |
|
737 |
{ |
|
738 |
} |
|
739 |
||
740 |
void tst_QSslSocket::protocol() |
|
741 |
{ |
|
742 |
if (!QSslSocket::supportsSsl()) |
|
743 |
return; |
|
744 |
||
745 |
QSslSocketPtr socket = newSocket(); |
|
746 |
this->socket = socket; |
|
747 |
QList<QSslCertificate> certs = QSslCertificate::fromPath(SRCDIR "certs/qt-test-server-cacert.pem"); |
|
748 |
||
749 |
// qDebug() << "certs:" << certs.at(0).issuerInfo(QSslCertificate::CommonName); |
|
750 |
socket->setCaCertificates(certs); |
|
751 |
#ifdef QSSLSOCKET_CERTUNTRUSTED_WORKAROUND |
|
752 |
connect(socket, SIGNAL(sslErrors(QList<QSslError>)), |
|
753 |
this, SLOT(untrustedWorkaroundSlot(QList<QSslError>))); |
|
754 |
#endif |
|
755 |
||
756 |
// qDebug() << "socket cert:" << socket->caCertificates().at(0).issuerInfo(QSslCertificate::CommonName); |
|
757 |
QCOMPARE(socket->protocol(), QSsl::SslV3); |
|
758 |
{ |
|
759 |
// Fluke allows SSLv3. |
|
760 |
socket->setProtocol(QSsl::SslV3); |
|
761 |
QCOMPARE(socket->protocol(), QSsl::SslV3); |
|
762 |
socket->connectToHostEncrypted(QtNetworkSettings::serverName(), 443); |
|
763 |
QVERIFY2(socket->waitForEncrypted(), qPrintable(socket->errorString())); |
|
764 |
QCOMPARE(socket->protocol(), QSsl::SslV3); |
|
765 |
socket->abort(); |
|
766 |
QCOMPARE(socket->protocol(), QSsl::SslV3); |
|
767 |
socket->connectToHost(QtNetworkSettings::serverName(), 443); |
|
768 |
QVERIFY2(socket->waitForConnected(), qPrintable(socket->errorString())); |
|
769 |
socket->startClientEncryption(); |
|
770 |
QVERIFY2(socket->waitForEncrypted(), qPrintable(socket->errorString())); |
|
771 |
QCOMPARE(socket->protocol(), QSsl::SslV3); |
|
772 |
socket->abort(); |
|
773 |
} |
|
774 |
{ |
|
775 |
// Fluke allows TLSV1. |
|
776 |
socket->setProtocol(QSsl::TlsV1); |
|
777 |
QCOMPARE(socket->protocol(), QSsl::TlsV1); |
|
778 |
socket->connectToHostEncrypted(QtNetworkSettings::serverName(), 443); |
|
779 |
QVERIFY2(socket->waitForEncrypted(), qPrintable(socket->errorString())); |
|
780 |
QCOMPARE(socket->protocol(), QSsl::TlsV1); |
|
781 |
socket->abort(); |
|
782 |
QCOMPARE(socket->protocol(), QSsl::TlsV1); |
|
783 |
socket->connectToHost(QtNetworkSettings::serverName(), 443); |
|
784 |
QVERIFY2(socket->waitForConnected(), qPrintable(socket->errorString())); |
|
785 |
socket->startClientEncryption(); |
|
786 |
QVERIFY2(socket->waitForEncrypted(), qPrintable(socket->errorString())); |
|
787 |
QCOMPARE(socket->protocol(), QSsl::TlsV1); |
|
788 |
socket->abort(); |
|
789 |
} |
|
790 |
{ |
|
791 |
// Fluke allows SSLV2. |
|
792 |
socket->setProtocol(QSsl::SslV2); |
|
793 |
QCOMPARE(socket->protocol(), QSsl::SslV2); |
|
794 |
socket->connectToHostEncrypted(QtNetworkSettings::serverName(), 443); |
|
795 |
QVERIFY(socket->waitForEncrypted()); |
|
796 |
QCOMPARE(socket->protocol(), QSsl::SslV2); |
|
797 |
socket->abort(); |
|
798 |
QCOMPARE(socket->protocol(), QSsl::SslV2); |
|
799 |
socket->connectToHost(QtNetworkSettings::serverName(), 443); |
|
800 |
QVERIFY2(socket->waitForConnected(), qPrintable(socket->errorString())); |
|
801 |
socket->startClientEncryption(); |
|
802 |
QVERIFY2(socket->waitForEncrypted(), qPrintable(socket->errorString())); |
|
803 |
socket->abort(); |
|
804 |
} |
|
805 |
{ |
|
806 |
// Fluke allows SSLV3, so it allows AnyProtocol. |
|
807 |
socket->setProtocol(QSsl::AnyProtocol); |
|
808 |
QCOMPARE(socket->protocol(), QSsl::AnyProtocol); |
|
809 |
socket->connectToHostEncrypted(QtNetworkSettings::serverName(), 443); |
|
810 |
QVERIFY(socket->waitForEncrypted()); |
|
811 |
QCOMPARE(socket->protocol(), QSsl::AnyProtocol); |
|
812 |
socket->abort(); |
|
813 |
QCOMPARE(socket->protocol(), QSsl::AnyProtocol); |
|
814 |
socket->connectToHost(QtNetworkSettings::serverName(), 443); |
|
815 |
QVERIFY2(socket->waitForConnected(), qPrintable(socket->errorString())); |
|
816 |
socket->startClientEncryption(); |
|
817 |
QVERIFY2(socket->waitForEncrypted(), qPrintable(socket->errorString())); |
|
818 |
QCOMPARE(socket->protocol(), QSsl::AnyProtocol); |
|
819 |
socket->abort(); |
|
820 |
} |
|
821 |
} |
|
822 |
||
823 |
void tst_QSslSocket::setCaCertificates() |
|
824 |
{ |
|
825 |
if (!QSslSocket::supportsSsl()) |
|
826 |
return; |
|
827 |
||
828 |
QSslSocket socket; |
|
829 |
QCOMPARE(socket.caCertificates(), QSslSocket::defaultCaCertificates()); |
|
830 |
socket.setCaCertificates(QSslCertificate::fromPath(SRCDIR "certs/qt-test-server-cacert.pem")); |
|
831 |
QCOMPARE(socket.caCertificates().size(), 1); |
|
832 |
socket.setCaCertificates(socket.defaultCaCertificates()); |
|
833 |
QCOMPARE(socket.caCertificates(), QSslSocket::defaultCaCertificates()); |
|
834 |
} |
|
835 |
||
836 |
void tst_QSslSocket::setLocalCertificate() |
|
837 |
{ |
|
838 |
} |
|
839 |
||
840 |
void tst_QSslSocket::setPrivateKey() |
|
841 |
{ |
|
842 |
} |
|
843 |
||
844 |
void tst_QSslSocket::setProtocol() |
|
845 |
{ |
|
846 |
} |
|
847 |
||
848 |
class SslServer : public QTcpServer |
|
849 |
{ |
|
850 |
Q_OBJECT |
|
851 |
public: |
|
852 |
SslServer() : socket(0) { } |
|
853 |
QSslSocket *socket; |
|
854 |
||
855 |
protected: |
|
856 |
void incomingConnection(int socketDescriptor) |
|
857 |
{ |
|
858 |
socket = new QSslSocket(this); |
|
859 |
connect(socket, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(ignoreErrorSlot())); |
|
860 |
||
861 |
QFile file(SRCDIR "certs/fluke.key"); |
|
862 |
QVERIFY(file.open(QIODevice::ReadOnly)); |
|
863 |
QSslKey key(file.readAll(), QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey); |
|
864 |
QVERIFY(!key.isNull()); |
|
865 |
socket->setPrivateKey(key); |
|
866 |
||
867 |
QList<QSslCertificate> localCert = QSslCertificate::fromPath(SRCDIR "certs/fluke.cert"); |
|
868 |
QVERIFY(!localCert.isEmpty()); |
|
869 |
QVERIFY(localCert.first().handle()); |
|
870 |
socket->setLocalCertificate(localCert.first()); |
|
871 |
||
872 |
QVERIFY(socket->setSocketDescriptor(socketDescriptor, QAbstractSocket::ConnectedState)); |
|
873 |
QVERIFY(!socket->peerAddress().isNull()); |
|
874 |
QVERIFY(socket->peerPort() != 0); |
|
875 |
QVERIFY(!socket->localAddress().isNull()); |
|
876 |
QVERIFY(socket->localPort() != 0); |
|
877 |
||
878 |
socket->startServerEncryption(); |
|
879 |
} |
|
880 |
||
881 |
protected slots: |
|
882 |
void ignoreErrorSlot() |
|
883 |
{ |
|
884 |
socket->ignoreSslErrors(); |
|
885 |
} |
|
886 |
}; |
|
887 |
||
888 |
void tst_QSslSocket::setSocketDescriptor() |
|
889 |
{ |
|
890 |
if (!QSslSocket::supportsSsl()) |
|
891 |
return; |
|
892 |
||
893 |
QFETCH_GLOBAL(bool, setProxy); |
|
894 |
if (setProxy) |
|
895 |
return; |
|
896 |
||
897 |
SslServer server; |
|
898 |
QVERIFY(server.listen()); |
|
899 |
||
900 |
QEventLoop loop; |
|
901 |
QTimer::singleShot(5000, &loop, SLOT(quit())); |
|
902 |
||
903 |
QSslSocketPtr client = new QSslSocket; |
|
904 |
socket = client; |
|
905 |
connect(socket, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(ignoreErrorSlot())); |
|
906 |
connect(client, SIGNAL(encrypted()), &loop, SLOT(quit())); |
|
907 |
||
908 |
client->connectToHostEncrypted(QHostAddress(QHostAddress::LocalHost).toString(), server.serverPort()); |
|
909 |
||
910 |
loop.exec(); |
|
911 |
||
912 |
QCOMPARE(client->state(), QAbstractSocket::ConnectedState); |
|
913 |
QVERIFY(client->isEncrypted()); |
|
914 |
QVERIFY(!client->peerAddress().isNull()); |
|
915 |
QVERIFY(client->peerPort() != 0); |
|
916 |
QVERIFY(!client->localAddress().isNull()); |
|
917 |
QVERIFY(client->localPort() != 0); |
|
918 |
} |
|
919 |
||
920 |
void tst_QSslSocket::waitForEncrypted() |
|
921 |
{ |
|
922 |
if (!QSslSocket::supportsSsl()) |
|
923 |
return; |
|
924 |
||
925 |
QSslSocketPtr socket = newSocket(); |
|
926 |
this->socket = socket; |
|
927 |
||
928 |
connect(socket, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(ignoreErrorSlot())); |
|
929 |
socket->connectToHostEncrypted(QtNetworkSettings::serverName(), 443); |
|
930 |
||
931 |
QVERIFY(socket->waitForEncrypted(10000)); |
|
932 |
} |
|
933 |
||
934 |
void tst_QSslSocket::waitForConnectedEncryptedReadyRead() |
|
935 |
{ |
|
936 |
if (!QSslSocket::supportsSsl()) |
|
937 |
return; |
|
938 |
||
939 |
QSslSocketPtr socket = newSocket(); |
|
940 |
this->socket = socket; |
|
941 |
||
942 |
connect(socket, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(ignoreErrorSlot())); |
|
943 |
socket->connectToHostEncrypted(QtNetworkSettings::serverName(), 993); |
|
944 |
||
945 |
#ifdef Q_OS_SYMBIAN |
|
946 |
QVERIFY(socket->waitForConnected(10000)); |
|
947 |
QVERIFY(socket->waitForEncrypted(10000)); |
|
948 |
||
949 |
// dont forget to login |
|
950 |
QCOMPARE((int) socket->write("USER ftptest\r\n"), 14); |
|
951 |
QCOMPARE((int) socket->write("PASS ftP2Ptf\r\n"), 14); |
|
952 |
||
953 |
QVERIFY(socket->waitForReadyRead(10000)); |
|
954 |
QVERIFY(!socket->peerCertificate().isNull()); |
|
955 |
QVERIFY(!socket->peerCertificateChain().isEmpty()); |
|
956 |
#else |
|
957 |
QVERIFY(socket->waitForConnected(10000)); |
|
958 |
QVERIFY(socket->waitForEncrypted(10000)); |
|
959 |
QVERIFY(socket->waitForReadyRead(10000)); |
|
960 |
QVERIFY(!socket->peerCertificate().isNull()); |
|
961 |
QVERIFY(!socket->peerCertificateChain().isEmpty()); |
|
962 |
#endif |
|
963 |
} |
|
964 |
||
965 |
void tst_QSslSocket::startClientEncryption() |
|
966 |
{ |
|
967 |
} |
|
968 |
||
969 |
void tst_QSslSocket::startServerEncryption() |
|
970 |
{ |
|
971 |
} |
|
972 |
||
973 |
void tst_QSslSocket::addDefaultCaCertificate() |
|
974 |
{ |
|
975 |
if (!QSslSocket::supportsSsl()) |
|
976 |
return; |
|
977 |
||
978 |
// Reset the global CA chain |
|
979 |
QSslSocket::setDefaultCaCertificates(QSslSocket::systemCaCertificates()); |
|
980 |
||
981 |
QList<QSslCertificate> flukeCerts = QSslCertificate::fromPath(SRCDIR "certs/qt-test-server-cacert.pem"); |
|
982 |
QCOMPARE(flukeCerts.size(), 1); |
|
983 |
QList<QSslCertificate> globalCerts = QSslSocket::defaultCaCertificates(); |
|
984 |
QVERIFY(!globalCerts.contains(flukeCerts.first())); |
|
985 |
QSslSocket::addDefaultCaCertificate(flukeCerts.first()); |
|
986 |
QCOMPARE(QSslSocket::defaultCaCertificates().size(), globalCerts.size() + 1); |
|
987 |
QVERIFY(QSslSocket::defaultCaCertificates().contains(flukeCerts.first())); |
|
988 |
||
989 |
// Restore the global CA chain |
|
990 |
QSslSocket::setDefaultCaCertificates(QSslSocket::systemCaCertificates()); |
|
991 |
} |
|
992 |
||
993 |
void tst_QSslSocket::addDefaultCaCertificates() |
|
994 |
{ |
|
995 |
} |
|
996 |
||
997 |
void tst_QSslSocket::addDefaultCaCertificates2() |
|
998 |
{ |
|
999 |
} |
|
1000 |
||
1001 |
void tst_QSslSocket::defaultCaCertificates() |
|
1002 |
{ |
|
1003 |
if (!QSslSocket::supportsSsl()) |
|
1004 |
return; |
|
1005 |
||
1006 |
QList<QSslCertificate> certs = QSslSocket::defaultCaCertificates(); |
|
1007 |
QVERIFY(certs.size() > 1); |
|
1008 |
QCOMPARE(certs, QSslSocket::systemCaCertificates()); |
|
1009 |
} |
|
1010 |
||
1011 |
void tst_QSslSocket::defaultCiphers() |
|
1012 |
{ |
|
1013 |
} |
|
1014 |
||
1015 |
void tst_QSslSocket::resetDefaultCiphers() |
|
1016 |
{ |
|
1017 |
} |
|
1018 |
||
1019 |
void tst_QSslSocket::setDefaultCaCertificates() |
|
1020 |
{ |
|
1021 |
} |
|
1022 |
||
1023 |
void tst_QSslSocket::setDefaultCiphers() |
|
1024 |
{ |
|
1025 |
} |
|
1026 |
||
1027 |
void tst_QSslSocket::supportedCiphers() |
|
1028 |
{ |
|
1029 |
if (!QSslSocket::supportsSsl()) |
|
1030 |
return; |
|
1031 |
||
1032 |
QList<QSslCipher> ciphers = QSslSocket::supportedCiphers(); |
|
1033 |
QVERIFY(ciphers.size() > 1); |
|
1034 |
||
1035 |
QSslSocket socket; |
|
1036 |
QCOMPARE(socket.supportedCiphers(), ciphers); |
|
1037 |
QCOMPARE(socket.defaultCiphers(), ciphers); |
|
1038 |
QCOMPARE(socket.ciphers(), ciphers); |
|
1039 |
} |
|
1040 |
||
1041 |
void tst_QSslSocket::systemCaCertificates() |
|
1042 |
{ |
|
1043 |
if (!QSslSocket::supportsSsl()) |
|
1044 |
return; |
|
1045 |
||
1046 |
QList<QSslCertificate> certs = QSslSocket::systemCaCertificates(); |
|
1047 |
QVERIFY(certs.size() > 1); |
|
1048 |
QCOMPARE(certs, QSslSocket::defaultCaCertificates()); |
|
1049 |
} |
|
1050 |
||
1051 |
void tst_QSslSocket::wildcard() |
|
1052 |
{ |
|
1053 |
QSKIP("TODO: solve wildcard problem", SkipAll); |
|
1054 |
||
1055 |
if (!QSslSocket::supportsSsl()) |
|
1056 |
return; |
|
1057 |
||
1058 |
// Fluke runs an apache server listening on port 4443, serving the |
|
1059 |
// wildcard fluke.*.troll.no. The DNS entry for |
|
1060 |
// fluke.wildcard.dev.troll.no, served by ares (root for dev.troll.no), |
|
1061 |
// returns the CNAME fluke.troll.no for this domain. The web server |
|
1062 |
// responds with the wildcard, and QSslSocket should accept that as a |
|
1063 |
// valid connection. This was broken in 4.3.0. |
|
1064 |
QSslSocketPtr socket = newSocket(); |
|
1065 |
socket->addCaCertificates(QLatin1String("certs/aspiriniks.ca.crt")); |
|
1066 |
this->socket = socket; |
|
1067 |
#ifdef QSSLSOCKET_CERTUNTRUSTED_WORKAROUND |
|
1068 |
connect(socket, SIGNAL(sslErrors(QList<QSslError>)), |
|
1069 |
this, SLOT(untrustedWorkaroundSlot(QList<QSslError>))); |
|
1070 |
#endif |
|
1071 |
socket->connectToHostEncrypted(QtNetworkSettings::wildcardServerName(), 4443); |
|
1072 |
||
1073 |
QVERIFY2(socket->waitForEncrypted(3000), qPrintable(socket->errorString())); |
|
1074 |
||
1075 |
QSslCertificate certificate = socket->peerCertificate(); |
|
1076 |
QCOMPARE(certificate.subjectInfo(QSslCertificate::CommonName), QString(QtNetworkSettings::serverLocalName() + ".*." + QtNetworkSettings::serverDomainName())); |
|
1077 |
QCOMPARE(certificate.issuerInfo(QSslCertificate::CommonName), QtNetworkSettings::serverName()); |
|
1078 |
||
1079 |
socket->close(); |
|
1080 |
} |
|
1081 |
||
1082 |
class SslServer2 : public QTcpServer |
|
1083 |
{ |
|
1084 |
protected: |
|
1085 |
void incomingConnection(int socketDescriptor) |
|
1086 |
{ |
|
1087 |
QSslSocket *socket = new QSslSocket(this); |
|
1088 |
socket->ignoreSslErrors(); |
|
1089 |
||
1090 |
// Only set the certificate |
|
1091 |
QList<QSslCertificate> localCert = QSslCertificate::fromPath(SRCDIR "certs/fluke.cert"); |
|
1092 |
QVERIFY(!localCert.isEmpty()); |
|
1093 |
QVERIFY(localCert.first().handle()); |
|
1094 |
socket->setLocalCertificate(localCert.first()); |
|
1095 |
||
1096 |
QVERIFY(socket->setSocketDescriptor(socketDescriptor, QAbstractSocket::ConnectedState)); |
|
1097 |
||
1098 |
socket->startServerEncryption(); |
|
1099 |
} |
|
1100 |
}; |
|
1101 |
||
1102 |
void tst_QSslSocket::setEmptyKey() |
|
1103 |
{ |
|
1104 |
if (!QSslSocket::supportsSsl()) |
|
1105 |
return; |
|
1106 |
||
1107 |
QFETCH_GLOBAL(bool, setProxy); |
|
1108 |
if (setProxy) |
|
1109 |
return; |
|
1110 |
||
1111 |
SslServer2 server; |
|
1112 |
server.listen(); |
|
1113 |
||
1114 |
QSslSocket socket; |
|
1115 |
socket.connectToHostEncrypted("127.0.0.1", server.serverPort()); |
|
1116 |
||
1117 |
QTestEventLoop::instance().enterLoop(2); |
|
1118 |
||
1119 |
QCOMPARE(socket.state(), QAbstractSocket::ConnectedState); |
|
1120 |
QCOMPARE(socket.error(), QAbstractSocket::UnknownSocketError); |
|
1121 |
} |
|
1122 |
||
1123 |
void tst_QSslSocket::spontaneousWrite() |
|
1124 |
{ |
|
1125 |
QFETCH_GLOBAL(bool, setProxy); |
|
1126 |
if (setProxy) |
|
1127 |
return; |
|
1128 |
||
1129 |
SslServer server; |
|
1130 |
QSslSocket *receiver = new QSslSocket(this); |
|
1131 |
connect(receiver, SIGNAL(readyRead()), SLOT(exitLoop())); |
|
1132 |
||
1133 |
// connect two sockets to each other: |
|
1134 |
QVERIFY(server.listen(QHostAddress::LocalHost)); |
|
1135 |
receiver->connectToHost("127.0.0.1", server.serverPort()); |
|
1136 |
QVERIFY(receiver->waitForConnected(5000)); |
|
1137 |
QVERIFY(server.waitForNewConnection(0)); |
|
1138 |
||
1139 |
QSslSocket *sender = server.socket; |
|
1140 |
QVERIFY(sender); |
|
1141 |
QVERIFY(sender->state() == QAbstractSocket::ConnectedState); |
|
1142 |
receiver->setObjectName("receiver"); |
|
1143 |
sender->setObjectName("sender"); |
|
1144 |
receiver->ignoreSslErrors(); |
|
1145 |
receiver->startClientEncryption(); |
|
1146 |
||
1147 |
// SSL handshake: |
|
1148 |
connect(receiver, SIGNAL(encrypted()), SLOT(exitLoop())); |
|
1149 |
enterLoop(1); |
|
1150 |
QVERIFY(!timeout()); |
|
1151 |
QVERIFY(sender->isEncrypted()); |
|
1152 |
QVERIFY(receiver->isEncrypted()); |
|
1153 |
||
1154 |
// make sure there's nothing to be received on the sender: |
|
1155 |
while (sender->waitForReadyRead(10) || receiver->waitForBytesWritten(10)) {} |
|
1156 |
||
1157 |
// spontaneously write something: |
|
1158 |
QByteArray data("Hello World"); |
|
1159 |
sender->write(data); |
|
1160 |
||
1161 |
// check if the other side receives it: |
|
1162 |
enterLoop(1); |
|
1163 |
QVERIFY(!timeout()); |
|
1164 |
QCOMPARE(receiver->bytesAvailable(), qint64(data.size())); |
|
1165 |
QCOMPARE(receiver->readAll(), data); |
|
1166 |
} |
|
1167 |
||
1168 |
void tst_QSslSocket::setReadBufferSize() |
|
1169 |
{ |
|
1170 |
QFETCH_GLOBAL(bool, setProxy); |
|
1171 |
if (setProxy) |
|
1172 |
return; |
|
1173 |
||
1174 |
SslServer server; |
|
1175 |
QSslSocket *receiver = new QSslSocket(this); |
|
1176 |
connect(receiver, SIGNAL(readyRead()), SLOT(exitLoop())); |
|
1177 |
||
1178 |
// connect two sockets to each other: |
|
1179 |
QVERIFY(server.listen(QHostAddress::LocalHost)); |
|
1180 |
receiver->connectToHost("127.0.0.1", server.serverPort()); |
|
1181 |
QVERIFY(receiver->waitForConnected(5000)); |
|
1182 |
QVERIFY(server.waitForNewConnection(0)); |
|
1183 |
||
1184 |
QSslSocket *sender = server.socket; |
|
1185 |
QVERIFY(sender); |
|
1186 |
QVERIFY(sender->state() == QAbstractSocket::ConnectedState); |
|
1187 |
receiver->setObjectName("receiver"); |
|
1188 |
sender->setObjectName("sender"); |
|
1189 |
receiver->ignoreSslErrors(); |
|
1190 |
receiver->startClientEncryption(); |
|
1191 |
||
1192 |
// SSL handshake: |
|
1193 |
connect(receiver, SIGNAL(encrypted()), SLOT(exitLoop())); |
|
1194 |
enterLoop(1); |
|
1195 |
QVERIFY(!timeout()); |
|
1196 |
QVERIFY(sender->isEncrypted()); |
|
1197 |
QVERIFY(receiver->isEncrypted()); |
|
1198 |
||
1199 |
QByteArray data(2048, 'b'); |
|
1200 |
receiver->setReadBufferSize(39 * 1024); // make it a non-multiple of the data.size() |
|
1201 |
||
1202 |
// saturate the incoming buffer |
|
1203 |
while (sender->state() == QAbstractSocket::ConnectedState && |
|
1204 |
receiver->state() == QAbstractSocket::ConnectedState && |
|
1205 |
receiver->bytesAvailable() < receiver->readBufferSize()) { |
|
1206 |
sender->write(data); |
|
1207 |
//qDebug() << receiver->bytesAvailable() << "<" << receiver->readBufferSize() << (receiver->bytesAvailable() < receiver->readBufferSize()); |
|
1208 |
||
1209 |
while (sender->bytesToWrite()) |
|
1210 |
QVERIFY(sender->waitForBytesWritten(10)); |
|
1211 |
||
1212 |
// drain it: |
|
1213 |
while (receiver->bytesAvailable() < receiver->readBufferSize() && |
|
1214 |
receiver->waitForReadyRead(10)) {} |
|
1215 |
} |
|
1216 |
||
1217 |
//qDebug() << sender->bytesToWrite() << "bytes to write"; |
|
1218 |
//qDebug() << receiver->bytesAvailable() << "bytes available"; |
|
1219 |
||
1220 |
// send a bit more |
|
1221 |
sender->write(data); |
|
1222 |
sender->write(data); |
|
1223 |
sender->write(data); |
|
1224 |
sender->write(data); |
|
1225 |
QVERIFY(sender->waitForBytesWritten(10)); |
|
1226 |
||
1227 |
qint64 oldBytesAvailable = receiver->bytesAvailable(); |
|
1228 |
||
1229 |
// now unset the read buffer limit and iterate |
|
1230 |
receiver->setReadBufferSize(0); |
|
1231 |
enterLoop(1); |
|
1232 |
QVERIFY(!timeout()); |
|
1233 |
||
1234 |
QVERIFY(receiver->bytesAvailable() > oldBytesAvailable); |
|
1235 |
} |
|
1236 |
||
1237 |
class SetReadBufferSize_task_250027_handler : public QObject { |
|
1238 |
Q_OBJECT |
|
1239 |
public slots: |
|
1240 |
void readyReadSlot() { |
|
1241 |
QTestEventLoop::instance().exitLoop(); |
|
1242 |
} |
|
1243 |
void waitSomeMore(QSslSocket *socket) { |
|
1244 |
QTime t; |
|
1245 |
t.start(); |
|
1246 |
while (!socket->encryptedBytesAvailable()) { |
|
1247 |
QCoreApplication::processEvents(QEventLoop::AllEvents | QEventLoop::WaitForMoreEvents, 250); |
|
1248 |
if (t.elapsed() > 1000 || socket->state() != QAbstractSocket::ConnectedState) |
|
1249 |
return; |
|
1250 |
} |
|
1251 |
} |
|
1252 |
}; |
|
1253 |
||
1254 |
void tst_QSslSocket::setReadBufferSize_task_250027() |
|
1255 |
{ |
|
1256 |
// do not execute this when a proxy is set. |
|
1257 |
QFETCH_GLOBAL(bool, setProxy); |
|
1258 |
if (setProxy) |
|
1259 |
return; |
|
1260 |
||
1261 |
QSslSocketPtr socket = newSocket(); |
|
1262 |
socket->setReadBufferSize(1000); // limit to 1 kb/sec |
|
1263 |
socket->ignoreSslErrors(); |
|
1264 |
socket->connectToHostEncrypted(QtNetworkSettings::serverName(), 443); |
|
1265 |
socket->ignoreSslErrors(); |
|
1266 |
QVERIFY(socket->waitForConnected(10*1000)); |
|
1267 |
QVERIFY(socket->waitForEncrypted(10*1000)); |
|
1268 |
||
1269 |
// exit the event loop as soon as we receive a readyRead() |
|
1270 |
SetReadBufferSize_task_250027_handler setReadBufferSize_task_250027_handler; |
|
1271 |
connect(socket, SIGNAL(readyRead()), &setReadBufferSize_task_250027_handler, SLOT(readyReadSlot())); |
|
1272 |
||
1273 |
// provoke a response by sending a request |
|
13
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
1274 |
socket->write("GET /qtest/fluke.gif HTTP/1.0\n"); // this file is 27 KB |
0 | 1275 |
socket->write("Host: "); |
1276 |
socket->write(QtNetworkSettings::serverName().toLocal8Bit().constData()); |
|
1277 |
socket->write("\n"); |
|
1278 |
socket->write("Connection: close\n"); |
|
1279 |
socket->write("\n"); |
|
1280 |
socket->flush(); |
|
1281 |
||
1282 |
QTestEventLoop::instance().enterLoop(10); |
|
1283 |
setReadBufferSize_task_250027_handler.waitSomeMore(socket); |
|
1284 |
QByteArray firstRead = socket->readAll(); |
|
1285 |
// First read should be some data, but not the whole file |
|
1286 |
QVERIFY(firstRead.size() > 0 && firstRead.size() < 20*1024); |
|
1287 |
||
1288 |
QTestEventLoop::instance().enterLoop(10); |
|
1289 |
setReadBufferSize_task_250027_handler.waitSomeMore(socket); |
|
1290 |
QByteArray secondRead = socket->readAll(); |
|
1291 |
// second read should be some more data |
|
1292 |
QVERIFY(secondRead.size() > 0); |
|
1293 |
||
1294 |
socket->close(); |
|
1295 |
} |
|
1296 |
||
1297 |
class SslServer3 : public QTcpServer |
|
1298 |
{ |
|
1299 |
Q_OBJECT |
|
1300 |
public: |
|
1301 |
SslServer3() : socket(0) { } |
|
1302 |
QSslSocket *socket; |
|
1303 |
||
1304 |
protected: |
|
1305 |
void incomingConnection(int socketDescriptor) |
|
1306 |
{ |
|
1307 |
socket = new QSslSocket(this); |
|
1308 |
connect(socket, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(ignoreErrorSlot())); |
|
1309 |
||
1310 |
QFile file(SRCDIR "certs/fluke.key"); |
|
1311 |
QVERIFY(file.open(QIODevice::ReadOnly)); |
|
1312 |
QSslKey key(file.readAll(), QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey); |
|
1313 |
QVERIFY(!key.isNull()); |
|
1314 |
socket->setPrivateKey(key); |
|
1315 |
||
1316 |
QList<QSslCertificate> localCert = QSslCertificate::fromPath(SRCDIR "certs/fluke.cert"); |
|
1317 |
QVERIFY(!localCert.isEmpty()); |
|
1318 |
QVERIFY(localCert.first().handle()); |
|
1319 |
socket->setLocalCertificate(localCert.first()); |
|
1320 |
||
1321 |
QVERIFY(socket->setSocketDescriptor(socketDescriptor, QAbstractSocket::ConnectedState)); |
|
1322 |
QVERIFY(!socket->peerAddress().isNull()); |
|
1323 |
QVERIFY(socket->peerPort() != 0); |
|
1324 |
QVERIFY(!socket->localAddress().isNull()); |
|
1325 |
QVERIFY(socket->localPort() != 0); |
|
1326 |
} |
|
1327 |
||
1328 |
protected slots: |
|
1329 |
void ignoreErrorSlot() |
|
1330 |
{ |
|
1331 |
socket->ignoreSslErrors(); |
|
1332 |
} |
|
1333 |
}; |
|
1334 |
||
1335 |
class ThreadedSslServer: public QThread |
|
1336 |
{ |
|
1337 |
Q_OBJECT |
|
1338 |
public: |
|
1339 |
QSemaphore dataReadSemaphore; |
|
1340 |
int serverPort; |
|
1341 |
bool ok; |
|
1342 |
||
1343 |
ThreadedSslServer() : serverPort(-1), ok(false) |
|
1344 |
{ } |
|
1345 |
||
1346 |
~ThreadedSslServer() |
|
1347 |
{ |
|
1348 |
if (isRunning()) wait(2000); |
|
1349 |
QVERIFY(ok); |
|
1350 |
} |
|
1351 |
||
1352 |
signals: |
|
1353 |
void listening(); |
|
1354 |
||
1355 |
protected: |
|
1356 |
void run() |
|
1357 |
{ |
|
1358 |
// if all goes well (no timeouts), this thread will sleep for a total of 500 ms |
|
1359 |
// (i.e., 5 times 100 ms, one sleep for each operation) |
|
1360 |
||
1361 |
SslServer3 server; |
|
1362 |
server.listen(QHostAddress::LocalHost); |
|
1363 |
serverPort = server.serverPort(); |
|
1364 |
emit listening(); |
|
1365 |
||
1366 |
// delayed acceptance: |
|
1367 |
QTest::qSleep(100); |
|
1368 |
#ifndef Q_OS_SYMBIAN |
|
1369 |
bool ret = server.waitForNewConnection(2000); |
|
1370 |
#else |
|
1371 |
bool ret = server.waitForNewConnection(20000); |
|
1372 |
#endif |
|
1373 |
||
1374 |
// delayed start of encryption |
|
1375 |
QTest::qSleep(100); |
|
1376 |
QSslSocket *socket = server.socket; |
|
1377 |
Q_ASSERT(socket); |
|
1378 |
Q_ASSERT(socket->isValid()); |
|
1379 |
socket->ignoreSslErrors(); |
|
1380 |
socket->startServerEncryption(); |
|
1381 |
if (!socket->waitForEncrypted(2000)) |
|
1382 |
return; // error |
|
1383 |
||
1384 |
// delayed reading data |
|
1385 |
QTest::qSleep(100); |
|
1386 |
if (!socket->waitForReadyRead(2000)) |
|
1387 |
return; // error |
|
1388 |
socket->readAll(); |
|
1389 |
dataReadSemaphore.release(); |
|
1390 |
||
1391 |
// delayed sending data |
|
1392 |
QTest::qSleep(100); |
|
1393 |
socket->write("Hello, World"); |
|
1394 |
while (socket->bytesToWrite()) |
|
1395 |
if (!socket->waitForBytesWritten(2000)) |
|
1396 |
return; // error |
|
1397 |
||
1398 |
// delayed replying (reading then sending) |
|
1399 |
QTest::qSleep(100); |
|
1400 |
if (!socket->waitForReadyRead(2000)) |
|
1401 |
return; // error |
|
1402 |
socket->write("Hello, World"); |
|
1403 |
while (socket->bytesToWrite()) |
|
1404 |
if (!socket->waitForBytesWritten(2000)) |
|
1405 |
return; // error |
|
1406 |
||
1407 |
// delayed disconnection: |
|
1408 |
QTest::qSleep(100); |
|
1409 |
socket->disconnectFromHost(); |
|
1410 |
if (!socket->waitForDisconnected(2000)) |
|
1411 |
return; // error |
|
1412 |
||
1413 |
delete socket; |
|
1414 |
ok = true; |
|
1415 |
} |
|
1416 |
}; |
|
1417 |
||
1418 |
void tst_QSslSocket::waitForMinusOne() |
|
1419 |
{ |
|
1420 |
QFETCH_GLOBAL(bool, setProxy); |
|
1421 |
if (setProxy) |
|
1422 |
return; |
|
1423 |
||
1424 |
ThreadedSslServer server; |
|
1425 |
connect(&server, SIGNAL(listening()), SLOT(exitLoop())); |
|
1426 |
||
1427 |
// start the thread and wait for it to be ready |
|
1428 |
server.start(); |
|
1429 |
enterLoop(1); |
|
1430 |
QVERIFY(!timeout()); |
|
1431 |
||
1432 |
// connect to the server |
|
1433 |
QSslSocket socket; |
|
1434 |
QTest::qSleep(100); |
|
1435 |
socket.connectToHost("127.0.0.1", server.serverPort); |
|
1436 |
QVERIFY(socket.waitForConnected(-1)); |
|
1437 |
socket.ignoreSslErrors(); |
|
1438 |
socket.startClientEncryption(); |
|
1439 |
||
1440 |
// first verification: this waiting should take 200 ms |
|
1441 |
QVERIFY2(socket.waitForEncrypted(-1), qPrintable(socket.errorString())); |
|
1442 |
QVERIFY(socket.isEncrypted()); |
|
1443 |
QCOMPARE(socket.state(), QAbstractSocket::ConnectedState); |
|
1444 |
QCOMPARE(socket.bytesAvailable(), Q_INT64_C(0)); |
|
1445 |
||
1446 |
// second verification: write and make sure the other side got it (100 ms) |
|
1447 |
socket.write("How are you doing?"); |
|
1448 |
QVERIFY(socket.bytesToWrite() != 0); |
|
1449 |
QVERIFY(socket.waitForBytesWritten(-1)); |
|
1450 |
QVERIFY(server.dataReadSemaphore.tryAcquire(1, 2000)); |
|
1451 |
||
1452 |
// third verification: it should wait for 100 ms: |
|
1453 |
QVERIFY(socket.waitForReadyRead(-1)); |
|
1454 |
QVERIFY(socket.isEncrypted()); |
|
1455 |
QCOMPARE(socket.state(), QAbstractSocket::ConnectedState); |
|
1456 |
QVERIFY(socket.bytesAvailable() != 0); |
|
1457 |
||
1458 |
// fourth verification: deadlock prevention: |
|
1459 |
// we write and then wait for reading; the other side needs to receive before |
|
1460 |
// replying (100 ms delay) |
|
1461 |
socket.write("I'm doing just fine!"); |
|
1462 |
QVERIFY(socket.bytesToWrite() != 0); |
|
1463 |
QVERIFY(socket.waitForReadyRead(-1)); |
|
1464 |
||
1465 |
// fifth verification: it should wait for 200 ms more |
|
1466 |
QVERIFY(socket.waitForDisconnected(-1)); |
|
1467 |
} |
|
1468 |
||
1469 |
class VerifyServer : public QTcpServer |
|
1470 |
{ |
|
1471 |
Q_OBJECT |
|
1472 |
public: |
|
1473 |
VerifyServer() : socket(0) { } |
|
1474 |
QSslSocket *socket; |
|
1475 |
||
1476 |
protected: |
|
1477 |
void incomingConnection(int socketDescriptor) |
|
1478 |
{ |
|
1479 |
socket = new QSslSocket(this); |
|
1480 |
||
1481 |
socket->setPrivateKey(SRCDIR "certs/fluke.key"); |
|
1482 |
socket->setLocalCertificate(SRCDIR "certs/fluke.cert"); |
|
1483 |
socket->setSocketDescriptor(socketDescriptor); |
|
1484 |
socket->startServerEncryption(); |
|
1485 |
} |
|
1486 |
}; |
|
1487 |
||
1488 |
void tst_QSslSocket::verifyMode() |
|
1489 |
{ |
|
1490 |
QFETCH_GLOBAL(bool, setProxy); |
|
1491 |
if (setProxy) |
|
1492 |
return; |
|
1493 |
||
1494 |
QSslSocket socket; |
|
1495 |
QCOMPARE(socket.peerVerifyMode(), QSslSocket::AutoVerifyPeer); |
|
1496 |
socket.setPeerVerifyMode(QSslSocket::VerifyNone); |
|
1497 |
QCOMPARE(socket.peerVerifyMode(), QSslSocket::VerifyNone); |
|
1498 |
socket.setPeerVerifyMode(QSslSocket::VerifyNone); |
|
1499 |
socket.setPeerVerifyMode(QSslSocket::VerifyPeer); |
|
1500 |
QCOMPARE(socket.peerVerifyMode(), QSslSocket::VerifyPeer); |
|
1501 |
||
1502 |
socket.connectToHostEncrypted(QtNetworkSettings::serverName(), 443); |
|
1503 |
QVERIFY(!socket.waitForEncrypted()); |
|
1504 |
||
1505 |
QList<QSslError> expectedErrors = QList<QSslError>() |
|
1506 |
<< QSslError(QSslError::SelfSignedCertificate, socket.peerCertificate()); |
|
1507 |
QCOMPARE(socket.sslErrors(), expectedErrors); |
|
1508 |
socket.abort(); |
|
1509 |
||
1510 |
VerifyServer server; |
|
1511 |
server.listen(); |
|
1512 |
||
1513 |
QSslSocket clientSocket; |
|
1514 |
clientSocket.connectToHostEncrypted("127.0.0.1", server.serverPort()); |
|
1515 |
clientSocket.ignoreSslErrors(); |
|
1516 |
||
1517 |
QEventLoop loop; |
|
1518 |
QTimer::singleShot(5000, &loop, SLOT(quit())); |
|
1519 |
connect(&clientSocket, SIGNAL(encrypted()), &loop, SLOT(quit())); |
|
1520 |
loop.exec(); |
|
1521 |
||
1522 |
QVERIFY(clientSocket.isEncrypted()); |
|
1523 |
QVERIFY(server.socket->sslErrors().isEmpty()); |
|
1524 |
} |
|
1525 |
||
1526 |
void tst_QSslSocket::verifyDepth() |
|
1527 |
{ |
|
1528 |
QSslSocket socket; |
|
1529 |
QCOMPARE(socket.peerVerifyDepth(), 0); |
|
1530 |
socket.setPeerVerifyDepth(1); |
|
1531 |
QCOMPARE(socket.peerVerifyDepth(), 1); |
|
1532 |
QTest::ignoreMessage(QtWarningMsg, "QSslSocket::setPeerVerifyDepth: cannot set negative depth of -1"); |
|
1533 |
socket.setPeerVerifyDepth(-1); |
|
1534 |
QCOMPARE(socket.peerVerifyDepth(), 1); |
|
1535 |
} |
|
1536 |
||
1537 |
void tst_QSslSocket::peerVerifyError() |
|
1538 |
{ |
|
1539 |
QSslSocketPtr socket = newSocket(); |
|
1540 |
QSignalSpy sslErrorsSpy(socket, SIGNAL(sslErrors(QList<QSslError>))); |
|
1541 |
QSignalSpy peerVerifyErrorSpy(socket, SIGNAL(peerVerifyError(QSslError))); |
|
1542 |
||
1543 |
socket->connectToHostEncrypted(QHostInfo::fromName(QtNetworkSettings::serverName()).addresses().first().toString(), 443); |
|
1544 |
QVERIFY(!socket->waitForEncrypted(10000)); |
|
1545 |
QVERIFY(!peerVerifyErrorSpy.isEmpty()); |
|
1546 |
QVERIFY(!sslErrorsSpy.isEmpty()); |
|
1547 |
QCOMPARE(qVariantValue<QSslError>(peerVerifyErrorSpy.last().at(0)).error(), QSslError::HostNameMismatch); |
|
1548 |
QCOMPARE(qVariantValue<QList<QSslError> >(sslErrorsSpy.at(0).at(0)).size(), peerVerifyErrorSpy.size()); |
|
1549 |
} |
|
1550 |
||
1551 |
void tst_QSslSocket::disconnectFromHostWhenConnecting() |
|
1552 |
{ |
|
1553 |
QSslSocketPtr socket = newSocket(); |
|
1554 |
socket->connectToHostEncrypted(QtNetworkSettings::serverName(), 993); |
|
1555 |
socket->ignoreSslErrors(); |
|
1556 |
socket->write("XXXX LOGOUT\r\n"); |
|
1557 |
QAbstractSocket::SocketState state = socket->state(); |
|
1558 |
// without proxy, the state will be HostLookupState; |
|
1559 |
// with proxy, the state will be ConnectingState. |
|
1560 |
QVERIFY(socket->state() == QAbstractSocket::HostLookupState || |
|
1561 |
socket->state() == QAbstractSocket::ConnectingState); |
|
1562 |
socket->disconnectFromHost(); |
|
1563 |
// the state of the socket must be the same before and after calling |
|
1564 |
// disconnectFromHost() |
|
1565 |
QCOMPARE(state, socket->state()); |
|
1566 |
QVERIFY(socket->state() == QAbstractSocket::HostLookupState || |
|
1567 |
socket->state() == QAbstractSocket::ConnectingState); |
|
1568 |
QVERIFY(socket->waitForDisconnected(5000)); |
|
1569 |
QCOMPARE(socket->state(), QAbstractSocket::UnconnectedState); |
|
1570 |
// we did not call close, so the socket must be still open |
|
1571 |
QVERIFY(socket->isOpen()); |
|
1572 |
QCOMPARE(socket->bytesToWrite(), qint64(0)); |
|
1573 |
||
1574 |
// dont forget to login |
|
1575 |
QCOMPARE((int) socket->write("USER ftptest\r\n"), 14); |
|
1576 |
||
1577 |
} |
|
1578 |
||
1579 |
void tst_QSslSocket::disconnectFromHostWhenConnected() |
|
1580 |
{ |
|
1581 |
QSslSocketPtr socket = newSocket(); |
|
1582 |
socket->connectToHostEncrypted(QtNetworkSettings::serverName(), 993); |
|
1583 |
socket->ignoreSslErrors(); |
|
1584 |
#ifndef Q_OS_SYMBIAN |
|
1585 |
QVERIFY(socket->waitForEncrypted(5000)); |
|
1586 |
#else |
|
1587 |
QVERIFY(socket->waitForEncrypted(10000)); |
|
1588 |
#endif |
|
1589 |
socket->write("XXXX LOGOUT\r\n"); |
|
1590 |
QCOMPARE(socket->state(), QAbstractSocket::ConnectedState); |
|
1591 |
socket->disconnectFromHost(); |
|
1592 |
QCOMPARE(socket->state(), QAbstractSocket::ClosingState); |
|
1593 |
#ifdef Q_OS_SYMBIAN |
|
1594 |
// I don't understand how socket->waitForDisconnected can work on other platforms |
|
1595 |
// since socket->write will end to: |
|
1596 |
// QMetaObject::invokeMethod(this, "_q_flushWriteBuffer", Qt::QueuedConnection); |
|
1597 |
// In order that _q_flushWriteBuffer will be called the eventloop need to run |
|
1598 |
// If we just call waitForDisconnected, which blocks the whole thread how that can happen? |
|
1599 |
connect(socket, SIGNAL(disconnected()), this, SLOT(exitLoop())); |
|
1600 |
enterLoop(5); |
|
1601 |
QVERIFY(!timeout()); |
|
1602 |
#else |
|
1603 |
QVERIFY(socket->waitForDisconnected(5000)); |
|
1604 |
#endif |
|
1605 |
QCOMPARE(socket->bytesToWrite(), qint64(0)); |
|
1606 |
} |
|
1607 |
||
1608 |
void tst_QSslSocket::resetProxy() |
|
1609 |
{ |
|
1610 |
QFETCH_GLOBAL(bool, setProxy); |
|
1611 |
if (setProxy) |
|
1612 |
return; |
|
1613 |
||
1614 |
// check fix for bug 199941 |
|
1615 |
||
1616 |
QNetworkProxy goodProxy(QNetworkProxy::NoProxy); |
|
1617 |
QNetworkProxy badProxy(QNetworkProxy::HttpProxy, "thisCannotWorkAbsolutelyNotForSure", 333); |
|
1618 |
||
1619 |
// make sure the connection works, and then set a nonsense proxy, and then |
|
1620 |
// make sure it does not work anymore |
|
1621 |
QSslSocket socket; |
|
1622 |
socket.addCaCertificates(QLatin1String(SRCDIR "certs/qt-test-server-cacert.pem")); |
|
1623 |
socket.setProxy(goodProxy); |
|
1624 |
socket.connectToHostEncrypted(QtNetworkSettings::serverName(), 443); |
|
1625 |
QVERIFY2(socket.waitForConnected(10000), qPrintable(socket.errorString())); |
|
1626 |
socket.abort(); |
|
1627 |
socket.setProxy(badProxy); |
|
1628 |
socket.connectToHostEncrypted(QtNetworkSettings::serverName(), 443); |
|
1629 |
QVERIFY(! socket.waitForConnected(10000)); |
|
1630 |
||
1631 |
// dont forget to login |
|
1632 |
QCOMPARE((int) socket.write("USER ftptest\r\n"), 14); |
|
1633 |
QCOMPARE((int) socket.write("PASS password\r\n"), 15); |
|
1634 |
||
1635 |
enterLoop(10); |
|
1636 |
||
1637 |
// now the other way round: |
|
1638 |
// set the nonsense proxy and make sure the connection does not work, |
|
1639 |
// and then set the right proxy and make sure it works |
|
1640 |
QSslSocket socket2; |
|
1641 |
socket2.addCaCertificates(QLatin1String(SRCDIR "certs/qt-test-server-cacert.pem")); |
|
1642 |
socket2.setProxy(badProxy); |
|
1643 |
socket2.connectToHostEncrypted(QtNetworkSettings::serverName(), 443); |
|
1644 |
QVERIFY(! socket2.waitForConnected(10000)); |
|
1645 |
socket2.abort(); |
|
1646 |
socket2.setProxy(goodProxy); |
|
1647 |
socket2.connectToHostEncrypted(QtNetworkSettings::serverName(), 443); |
|
1648 |
QVERIFY2(socket2.waitForConnected(10000), qPrintable(socket.errorString())); |
|
1649 |
} |
|
1650 |
||
1651 |
void tst_QSslSocket::ignoreSslErrorsList_data() |
|
1652 |
{ |
|
1653 |
QTest::addColumn<QList<QSslError> >("expectedSslErrors"); |
|
1654 |
QTest::addColumn<int>("expectedSslErrorSignalCount"); |
|
1655 |
||
1656 |
// construct the list of errors that we will get with the SSL handshake and that we will ignore |
|
1657 |
QList<QSslError> expectedSslErrors; |
|
1658 |
// fromPath gives us a list of certs, but it actually only contains one |
|
1659 |
QList<QSslCertificate> certs = QSslCertificate::fromPath(QLatin1String(SRCDIR "certs/qt-test-server-cacert.pem")); |
|
1660 |
QSslError rightError(QSslError::SelfSignedCertificate, certs.at(0)); |
|
1661 |
QSslError wrongError(QSslError::SelfSignedCertificate); |
|
1662 |
||
1663 |
||
1664 |
QTest::newRow("SSL-failure-empty-list") << expectedSslErrors << 1; |
|
1665 |
expectedSslErrors.append(wrongError); |
|
1666 |
QTest::newRow("SSL-failure-wrong-error") << expectedSslErrors << 1; |
|
1667 |
expectedSslErrors.append(rightError); |
|
1668 |
QTest::newRow("allErrorsInExpectedList1") << expectedSslErrors << 0; |
|
1669 |
expectedSslErrors.removeAll(wrongError); |
|
1670 |
QTest::newRow("allErrorsInExpectedList2") << expectedSslErrors << 0; |
|
1671 |
expectedSslErrors.removeAll(rightError); |
|
1672 |
QTest::newRow("SSL-failure-empty-list-again") << expectedSslErrors << 1; |
|
1673 |
} |
|
1674 |
||
1675 |
void tst_QSslSocket::ignoreSslErrorsList() |
|
1676 |
{ |
|
1677 |
QSslSocket socket; |
|
1678 |
connect(&socket, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), |
|
1679 |
this, SLOT(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*))); |
|
1680 |
||
1681 |
// this->socket = &socket; |
|
1682 |
QSslCertificate cert; |
|
1683 |
||
1684 |
QFETCH(QList<QSslError>, expectedSslErrors); |
|
1685 |
socket.ignoreSslErrors(expectedSslErrors); |
|
1686 |
||
1687 |
QFETCH(int, expectedSslErrorSignalCount); |
|
1688 |
QSignalSpy sslErrorsSpy(&socket, SIGNAL(error(QAbstractSocket::SocketError))); |
|
1689 |
||
1690 |
socket.connectToHostEncrypted(QtNetworkSettings::serverName(), 443); |
|
1691 |
||
1692 |
bool expectEncryptionSuccess = (expectedSslErrorSignalCount == 0); |
|
1693 |
QCOMPARE(socket.waitForEncrypted(10000), expectEncryptionSuccess); |
|
1694 |
QCOMPARE(sslErrorsSpy.count(), expectedSslErrorSignalCount); |
|
1695 |
} |
|
1696 |
||
1697 |
void tst_QSslSocket::ignoreSslErrorsListWithSlot_data() |
|
1698 |
{ |
|
1699 |
ignoreSslErrorsList_data(); |
|
1700 |
} |
|
1701 |
||
1702 |
// this is not a test, just a slot called in the test below |
|
1703 |
void tst_QSslSocket::ignoreErrorListSlot(const QList<QSslError> &) |
|
1704 |
{ |
|
1705 |
socket->ignoreSslErrors(storedExpectedSslErrors); |
|
1706 |
} |
|
1707 |
||
1708 |
void tst_QSslSocket::ignoreSslErrorsListWithSlot() |
|
1709 |
{ |
|
1710 |
QSslSocket socket; |
|
1711 |
this->socket = &socket; |
|
1712 |
||
1713 |
QFETCH(QList<QSslError>, expectedSslErrors); |
|
1714 |
// store the errors to ignore them later in the slot connected below |
|
1715 |
storedExpectedSslErrors = expectedSslErrors; |
|
1716 |
connect(&socket, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), |
|
1717 |
this, SLOT(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*))); |
|
1718 |
connect(&socket, SIGNAL(sslErrors(const QList<QSslError> &)), |
|
1719 |
this, SLOT(ignoreErrorListSlot(const QList<QSslError> &))); |
|
1720 |
socket.connectToHostEncrypted(QtNetworkSettings::serverName(), 443); |
|
1721 |
||
1722 |
QFETCH(int, expectedSslErrorSignalCount); |
|
1723 |
bool expectEncryptionSuccess = (expectedSslErrorSignalCount == 0); |
|
1724 |
QCOMPARE(socket.waitForEncrypted(10000), expectEncryptionSuccess); |
|
1725 |
} |
|
1726 |
||
1727 |
// make sure a closed socket has no bytesAvailable() |
|
1728 |
// related to https://bugs.webkit.org/show_bug.cgi?id=28016 |
|
1729 |
void tst_QSslSocket::readFromClosedSocket() |
|
1730 |
{ |
|
1731 |
QSslSocketPtr socket = newSocket(); |
|
1732 |
socket->ignoreSslErrors(); |
|
1733 |
socket->connectToHostEncrypted(QtNetworkSettings::serverName(), 443); |
|
1734 |
socket->ignoreSslErrors(); |
|
1735 |
socket->waitForConnected(); |
|
1736 |
socket->waitForEncrypted(); |
|
1737 |
// provoke a response by sending a request |
|
13
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
1738 |
socket->write("GET /qtest/fluke.gif HTTP/1.1\n"); |
0 | 1739 |
socket->write("Host: "); |
1740 |
socket->write(QtNetworkSettings::serverName().toLocal8Bit().constData()); |
|
1741 |
socket->write("\n"); |
|
1742 |
socket->write("\n"); |
|
1743 |
socket->waitForBytesWritten(); |
|
1744 |
socket->waitForReadyRead(); |
|
1745 |
QVERIFY(socket->state() == QAbstractSocket::ConnectedState); |
|
1746 |
QVERIFY(socket->bytesAvailable()); |
|
1747 |
socket->close(); |
|
1748 |
QVERIFY(!socket->bytesAvailable()); |
|
1749 |
QVERIFY(!socket->bytesToWrite()); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1750 |
QVERIFY(socket->state() == QAbstractSocket::UnconnectedState); |
0 | 1751 |
} |
1752 |
||
1753 |
void tst_QSslSocket::writeBigChunk() |
|
1754 |
{ |
|
1755 |
if (!QSslSocket::supportsSsl()) |
|
1756 |
return; |
|
1757 |
||
1758 |
QSslSocketPtr socket = newSocket(); |
|
1759 |
this->socket = socket; |
|
1760 |
||
1761 |
connect(socket, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(ignoreErrorSlot())); |
|
1762 |
socket->connectToHostEncrypted(QtNetworkSettings::serverName(), 443); |
|
1763 |
||
1764 |
QByteArray data; |
|
1765 |
data.resize(1024*1024*10); // 10 MB |
|
1766 |
// init with garbage. needed so ssl cannot compress it in an efficient way. |
|
1767 |
for (int i = 0; i < data.size() / sizeof(int); i++) { |
|
1768 |
int r = qrand(); |
|
1769 |
data.data()[i*sizeof(int)] = r; |
|
1770 |
} |
|
1771 |
||
1772 |
QVERIFY(socket->waitForEncrypted(10000)); |
|
1773 |
QString errorBefore = socket->errorString(); |
|
1774 |
||
1775 |
int ret = socket->write(data.constData(), data.size()); |
|
1776 |
QVERIFY(data.size() == ret); |
|
1777 |
||
1778 |
// spin the event loop once so QSslSocket::transmit() gets called |
|
1779 |
QCoreApplication::processEvents(); |
|
1780 |
QString errorAfter = socket->errorString(); |
|
1781 |
||
1782 |
// no better way to do this right now since the error is the same as the default error. |
|
1783 |
if (socket->errorString().startsWith(QLatin1String("Unable to write data"))) |
|
1784 |
{ |
|
1785 |
qWarning() << socket->error() << socket->errorString(); |
|
1786 |
QFAIL("Error while writing! Check if the OpenSSL BIO size is limited?!"); |
|
1787 |
} |
|
1788 |
// also check the error string. If another error (than UnknownError) occured, it should be different than before |
|
1789 |
QVERIFY(errorBefore == errorAfter); |
|
1790 |
||
1791 |
// check that everything has been written to OpenSSL |
|
1792 |
QVERIFY(socket->bytesToWrite() == 0); |
|
1793 |
||
1794 |
socket->close(); |
|
1795 |
} |
|
1796 |
||
1797 |
#endif // QT_NO_OPENSSL |
|
1798 |
||
1799 |
QTEST_MAIN(tst_QSslSocket) |
|
1800 |
#include "tst_qsslsocket.moc" |