Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/network/ssl/qsslcontext_openssl.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | - | |||||||||||||
3 | - | |||||||||||||
4 | - | |||||||||||||
5 | - | |||||||||||||
6 | extern int q_X509Callback(int ok, X509_STORE_CTX *ctx); | - | ||||||||||||
7 | extern QString getErrorsFromOpenSsl(); | - | ||||||||||||
8 | - | |||||||||||||
9 | static DH *get_dh1024() | - | ||||||||||||
10 | { | - | ||||||||||||
11 | - | |||||||||||||
12 | - | |||||||||||||
13 | - | |||||||||||||
14 | QByteArray params = QByteArray::fromBase64( | - | ||||||||||||
15 | ([]() -> QByteArray { enum { Size = sizeof("MIGHAoGBAP//////////yQ/aoiFowjTExmKLgNwc0SkCTgiKZ8x0Agu+pjsTmyJR" "Sgh5jjQE3e+VGbPNOkMbMCsKbfJfFDdP4TVtbVHCReSFtXZiXn7G9ExC6aY37WsL" "/1y29Aa37e44a/taiZ+lrp8kEXxLH+ZJKGZR7OZTgf//////////AgEC") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "MIGHAoGBAP//////////yQ/aoiFowjTExmKLgNwc0SkCTgiKZ8x0Agu+pjsTmyJR" "Sgh5jjQE3e+VGbPNOkMbMCsKbfJfFDdP4TVtbVHCReSFtXZiXn7G9ExC6aY37WsL" "/1y29Aa37e44a/taiZ+lrp8kEXxLH+ZJKGZR7OZTgf//////////AgEC" }; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return executed 446 times by 7 tests: ba;return ba; Executed by:
executed 446 times by 7 tests: }())return ba; Executed by:
| 446 | ||||||||||||
16 | - | |||||||||||||
17 | ); | - | ||||||||||||
18 | - | |||||||||||||
19 | const char *ptr = params.constData(); | - | ||||||||||||
20 | DH *dh = q_d2i_DHparams(__null, reinterpret_cast<const unsigned char **>(&ptr), params.length()); | - | ||||||||||||
21 | - | |||||||||||||
22 | return executed 446 times by 7 tests: dh;return dh; Executed by:
executed 446 times by 7 tests: return dh; Executed by:
| 446 | ||||||||||||
23 | } | - | ||||||||||||
24 | - | |||||||||||||
25 | QSslContext::QSslContext() | - | ||||||||||||
26 | : ctx(0), | - | ||||||||||||
27 | pkey(0), | - | ||||||||||||
28 | session(0), | - | ||||||||||||
29 | m_sessionTicketLifeTimeHint(-1) | - | ||||||||||||
30 | { | - | ||||||||||||
31 | } executed 454 times by 7 tests: end of block Executed by:
| 454 | ||||||||||||
32 | - | |||||||||||||
33 | QSslContext::~QSslContext() | - | ||||||||||||
34 | { | - | ||||||||||||
35 | if (ctx
| 0-453 | ||||||||||||
36 | - | |||||||||||||
37 | q_SSL_CTX_free(ctx); executed 453 times by 8 tests: q_SSL_CTX_free(ctx); Executed by:
| 453 | ||||||||||||
38 | - | |||||||||||||
39 | if (pkey
| 81-372 | ||||||||||||
40 | q_EVP_PKEY_free(pkey); executed 81 times by 2 tests: q_EVP_PKEY_free(pkey); Executed by:
| 81 | ||||||||||||
41 | - | |||||||||||||
42 | if (session
| 124-329 | ||||||||||||
43 | q_SSL_SESSION_free(session); executed 329 times by 8 tests: q_SSL_SESSION_free(session); Executed by:
| 329 | ||||||||||||
44 | } executed 453 times by 8 tests: end of block Executed by:
| 453 | ||||||||||||
45 | - | |||||||||||||
46 | static inline QString msgErrorSettingEllipticCurves(const QString &why) | - | ||||||||||||
47 | { | - | ||||||||||||
48 | return never executed: QSslSocket::tr("Error when setting the elliptic curves (%1)").arg(why);return QSslSocket::tr("Error when setting the elliptic curves (%1)").arg(why); never executed: return QSslSocket::tr("Error when setting the elliptic curves (%1)").arg(why); | 0 | ||||||||||||
49 | } | - | ||||||||||||
50 | - | |||||||||||||
51 | QSslContext* QSslContext::fromConfiguration(QSslSocket::SslMode mode, const QSslConfiguration &configuration, bool allowRootCertOnDemandLoading) | - | ||||||||||||
52 | { | - | ||||||||||||
53 | QSslContext *sslContext = new QSslContext(); | - | ||||||||||||
54 | sslContext->sslConfiguration = configuration; | - | ||||||||||||
55 | sslContext->errorCode = QSslError::NoError; | - | ||||||||||||
56 | - | |||||||||||||
57 | bool client = (mode == QSslSocket::SslClientMode); | - | ||||||||||||
58 | - | |||||||||||||
59 | bool reinitialized = false; | - | ||||||||||||
60 | bool unsupportedProtocol = false; | - | ||||||||||||
61 | init_context: code before this statement executed 454 times by 7 tests: init_context: Executed by:
| 454 | ||||||||||||
62 | switch (sslContext->sslConfiguration.protocol()) { | - | ||||||||||||
63 | case never executed: QSsl::SslV2:case QSsl::SslV2: never executed: case QSsl::SslV2: | 0 | ||||||||||||
64 | - | |||||||||||||
65 | - | |||||||||||||
66 | - | |||||||||||||
67 | - | |||||||||||||
68 | sslContext->ctx = 0; | - | ||||||||||||
69 | unsupportedProtocol = true; | - | ||||||||||||
70 | - | |||||||||||||
71 | break; never executed: break; | 0 | ||||||||||||
72 | case executed 19 times by 1 test: QSsl::SslV3:case QSsl::SslV3: Executed by:
executed 19 times by 1 test: case QSsl::SslV3: Executed by:
| 19 | ||||||||||||
73 | - | |||||||||||||
74 | sslContext->ctx = q_SSL_CTX_new(client ? q_SSLv3_client_method() : q_SSLv3_server_method()); | - | ||||||||||||
75 | - | |||||||||||||
76 | - | |||||||||||||
77 | - | |||||||||||||
78 | - | |||||||||||||
79 | - | |||||||||||||
80 | break; executed 19 times by 1 test: break; Executed by:
| 19 | ||||||||||||
81 | case executed 326 times by 7 tests: QSsl::SecureProtocols:case QSsl::SecureProtocols: Executed by:
executed 326 times by 7 tests: case QSsl::SecureProtocols: Executed by:
| 326 | ||||||||||||
82 | - | |||||||||||||
83 | - | |||||||||||||
84 | case executed 18 times by 1 test: QSsl::TlsV1SslV3:case QSsl::TlsV1SslV3: Executed by:
executed 18 times by 1 test: case QSsl::TlsV1SslV3: Executed by:
| 18 | ||||||||||||
85 | - | |||||||||||||
86 | case executed 24 times by 2 tests: QSsl::AnyProtocol:case QSsl::AnyProtocol: Executed by:
executed 24 times by 2 tests: case QSsl::AnyProtocol: Executed by:
| 24 | ||||||||||||
87 | default never executed: :default: never executed: default: | 0 | ||||||||||||
88 | sslContext->ctx = q_SSL_CTX_new(client ? q_SSLv23_client_method() : q_SSLv23_server_method()); | - | ||||||||||||
89 | break; executed 368 times by 7 tests: break; Executed by:
| 368 | ||||||||||||
90 | case executed 49 times by 1 test: QSsl::TlsV1_0:case QSsl::TlsV1_0: Executed by:
executed 49 times by 1 test: case QSsl::TlsV1_0: Executed by:
| 49 | ||||||||||||
91 | sslContext->ctx = q_SSL_CTX_new(client ? q_TLSv1_client_method() : q_TLSv1_server_method()); | - | ||||||||||||
92 | break; executed 49 times by 1 test: break; Executed by:
| 49 | ||||||||||||
93 | case executed 9 times by 1 test: QSsl::TlsV1_1:case QSsl::TlsV1_1: Executed by:
executed 9 times by 1 test: case QSsl::TlsV1_1: Executed by:
| 9 | ||||||||||||
94 | - | |||||||||||||
95 | sslContext->ctx = q_SSL_CTX_new(client ? q_TLSv1_1_client_method() : q_TLSv1_1_server_method()); | - | ||||||||||||
96 | - | |||||||||||||
97 | - | |||||||||||||
98 | - | |||||||||||||
99 | - | |||||||||||||
100 | - | |||||||||||||
101 | break; executed 9 times by 1 test: break; Executed by:
| 9 | ||||||||||||
102 | case executed 9 times by 1 test: QSsl::TlsV1_2:case QSsl::TlsV1_2: Executed by:
executed 9 times by 1 test: case QSsl::TlsV1_2: Executed by:
| 9 | ||||||||||||
103 | - | |||||||||||||
104 | sslContext->ctx = q_SSL_CTX_new(client ? q_TLSv1_2_client_method() : q_TLSv1_2_server_method()); | - | ||||||||||||
105 | - | |||||||||||||
106 | - | |||||||||||||
107 | - | |||||||||||||
108 | - | |||||||||||||
109 | - | |||||||||||||
110 | break; executed 9 times by 1 test: break; Executed by:
| 9 | ||||||||||||
111 | case never executed: QSsl::TlsV1_0OrLater:case QSsl::TlsV1_0OrLater: never executed: case QSsl::TlsV1_0OrLater: | 0 | ||||||||||||
112 | - | |||||||||||||
113 | sslContext->ctx = q_SSL_CTX_new(client ? q_SSLv23_client_method() : q_SSLv23_server_method()); | - | ||||||||||||
114 | break; never executed: break; | 0 | ||||||||||||
115 | case never executed: QSsl::TlsV1_1OrLater:case QSsl::TlsV1_1OrLater: never executed: case QSsl::TlsV1_1OrLater: | 0 | ||||||||||||
116 | case never executed: QSsl::TlsV1_2OrLater:case QSsl::TlsV1_2OrLater: never executed: case QSsl::TlsV1_2OrLater: | 0 | ||||||||||||
117 | - | |||||||||||||
118 | - | |||||||||||||
119 | sslContext->ctx = q_SSL_CTX_new(client ? q_SSLv23_client_method() : q_SSLv23_server_method()); | - | ||||||||||||
120 | - | |||||||||||||
121 | - | |||||||||||||
122 | - | |||||||||||||
123 | - | |||||||||||||
124 | - | |||||||||||||
125 | break; never executed: break; | 0 | ||||||||||||
126 | } | - | ||||||||||||
127 | - | |||||||||||||
128 | if (!sslContext->ctx
| 0-454 | ||||||||||||
129 | - | |||||||||||||
130 | - | |||||||||||||
131 | if (!reinitialized
| 0 | ||||||||||||
132 | reinitialized = true; | - | ||||||||||||
133 | if (q_SSL_library_init() == 1
| 0 | ||||||||||||
134 | goto never executed: init_context;goto init_context; never executed: goto init_context; | 0 | ||||||||||||
135 | } never executed: end of block | 0 | ||||||||||||
136 | - | |||||||||||||
137 | sslContext->errorStr = QSslSocket::tr("Error creating SSL context (%1)").arg( | - | ||||||||||||
138 | unsupportedProtocol ? QSslSocket::tr("unsupported protocol") : QSslSocketBackendPrivate::getErrorsFromOpenSsl() | - | ||||||||||||
139 | ); | - | ||||||||||||
140 | sslContext->errorCode = QSslError::UnspecifiedError; | - | ||||||||||||
141 | return never executed: sslContext;return sslContext; never executed: return sslContext; | 0 | ||||||||||||
142 | } | - | ||||||||||||
143 | - | |||||||||||||
144 | - | |||||||||||||
145 | long options = QSslSocketBackendPrivate::setupOpenSslOptions(configuration.protocol(), configuration.d->sslOptions); | - | ||||||||||||
146 | q_SSL_CTX_ctrl((sslContext->ctx),32,(options),__null); | - | ||||||||||||
147 | - | |||||||||||||
148 | - | |||||||||||||
149 | - | |||||||||||||
150 | - | |||||||||||||
151 | if (q_SSLeay() >= 0x10000000L
| 0-454 | ||||||||||||
152 | q_SSL_CTX_ctrl((sslContext->ctx),33,(0x00000010L),__null); executed 454 times by 7 tests: q_SSL_CTX_ctrl((sslContext->ctx),33,(0x00000010L),__null); Executed by:
| 454 | ||||||||||||
153 | - | |||||||||||||
154 | - | |||||||||||||
155 | - | |||||||||||||
156 | QByteArray cipherString; | - | ||||||||||||
157 | bool first = true; | - | ||||||||||||
158 | QList<QSslCipher> ciphers = sslContext->sslConfiguration.ciphers(); | - | ||||||||||||
159 | if (ciphers.isEmpty()
| 54-400 | ||||||||||||
160 | ciphers = QSslSocketPrivate::defaultCiphers(); executed 54 times by 4 tests: ciphers = QSslSocketPrivate::defaultCiphers(); Executed by:
| 54 | ||||||||||||
161 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(ciphers)>::type> _container_((ciphers)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (const QSslCipher &cipher = *_container_.i; _container_.control; _container_.control = 0) { | - | ||||||||||||
162 | if (first
| 447-28670 | ||||||||||||
163 | first = false; executed 447 times by 7 tests: first = false; Executed by:
| 447 | ||||||||||||
164 | else | - | ||||||||||||
165 | cipherString.append(':'); executed 28670 times by 7 tests: cipherString.append(':'); Executed by:
| 28670 | ||||||||||||
166 | cipherString.append(cipher.name().toLatin1()); | - | ||||||||||||
167 | } executed 29117 times by 7 tests: end of block Executed by:
| 29117 | ||||||||||||
168 | - | |||||||||||||
169 | if (!q_SSL_CTX_set_cipher_list(sslContext->ctx, cipherString.data())
| 7-447 | ||||||||||||
170 | sslContext->errorStr = QSslSocket::tr("Invalid or empty cipher list (%1)").arg(QSslSocketBackendPrivate::getErrorsFromOpenSsl()); | - | ||||||||||||
171 | sslContext->errorCode = QSslError::UnspecifiedError; | - | ||||||||||||
172 | return executed 7 times by 2 tests: sslContext;return sslContext; Executed by:
executed 7 times by 2 tests: return sslContext; Executed by:
| 7 | ||||||||||||
173 | } | - | ||||||||||||
174 | - | |||||||||||||
175 | const QDateTime now = QDateTime::currentDateTimeUtc(); | - | ||||||||||||
176 | - | |||||||||||||
177 | - | |||||||||||||
178 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(sslContext->sslConfiguration.caCertificates())>::type> _container_((sslContext->sslConfiguration.caCertificates())); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (const QSslCertificate &caCertificate = *_container_.i; _container_.control; _container_.control = 0) { | - | ||||||||||||
179 | if (caCertificate.expiryDate() >= now
| 3366-50176 | ||||||||||||
180 | q_X509_STORE_add_cert(q_SSL_CTX_get_cert_store(sslContext->ctx), (X509 *)caCertificate.handle()); | - | ||||||||||||
181 | } executed 50176 times by 3 tests: end of block Executed by:
| 50176 | ||||||||||||
182 | } executed 53542 times by 3 tests: end of block Executed by:
| 53542 | ||||||||||||
183 | - | |||||||||||||
184 | if (QSslSocketPrivate::s_loadRootCertsOnDemand
| 48-336 | ||||||||||||
185 | - | |||||||||||||
186 | QList<QByteArray> unixDirs = QSslSocketPrivate::unixRootCertDirectories(); | - | ||||||||||||
187 | for (int a = 0; a < unixDirs.count()
| 63-567 | ||||||||||||
188 | q_SSL_CTX_load_verify_locations(sslContext->ctx, 0, unixDirs.at(a).constData()); executed 567 times by 5 tests: q_SSL_CTX_load_verify_locations(sslContext->ctx, 0, unixDirs.at(a).constData()); Executed by:
| 567 | ||||||||||||
189 | } executed 63 times by 5 tests: end of block Executed by:
| 63 | ||||||||||||
190 | - | |||||||||||||
191 | if (!sslContext->sslConfiguration.localCertificate().isNull()
| 87-360 | ||||||||||||
192 | - | |||||||||||||
193 | if (sslContext->sslConfiguration.privateKey().isNull()
| 1-86 | ||||||||||||
194 | sslContext->errorStr = QSslSocket::tr("Cannot provide a certificate with no key, %1").arg(QSslSocketBackendPrivate::getErrorsFromOpenSsl()); | - | ||||||||||||
195 | sslContext->errorCode = QSslError::UnspecifiedError; | - | ||||||||||||
196 | return executed 1 time by 1 test: sslContext;return sslContext; Executed by:
executed 1 time by 1 test: return sslContext; Executed by:
| 1 | ||||||||||||
197 | } | - | ||||||||||||
198 | - | |||||||||||||
199 | - | |||||||||||||
200 | if (!q_SSL_CTX_use_certificate(sslContext->ctx, (X509 *)sslContext->sslConfiguration.localCertificate().handle())
| 0-86 | ||||||||||||
201 | sslContext->errorStr = QSslSocket::tr("Error loading local certificate, %1").arg(QSslSocketBackendPrivate::getErrorsFromOpenSsl()); | - | ||||||||||||
202 | sslContext->errorCode = QSslError::UnspecifiedError; | - | ||||||||||||
203 | return never executed: sslContext;return sslContext; never executed: return sslContext; | 0 | ||||||||||||
204 | } | - | ||||||||||||
205 | - | |||||||||||||
206 | if (configuration.d->privateKey.algorithm() == QSsl::Opaque
| 4-82 | ||||||||||||
207 | sslContext->pkey = reinterpret_cast<EVP_PKEY *>(configuration.d->privateKey.handle()); | - | ||||||||||||
208 | } executed 4 times by 1 test: else {end of block Executed by:
| 4 | ||||||||||||
209 | - | |||||||||||||
210 | sslContext->pkey = q_EVP_PKEY_new(); | - | ||||||||||||
211 | - | |||||||||||||
212 | - | |||||||||||||
213 | - | |||||||||||||
214 | if (configuration.d->privateKey.algorithm() == QSsl::Rsa
| 0-82 | ||||||||||||
215 | q_EVP_PKEY_set1_RSA(sslContext->pkey, reinterpret_cast<RSA *>(configuration.d->privateKey.handle())); executed 82 times by 2 tests: q_EVP_PKEY_set1_RSA(sslContext->pkey, reinterpret_cast<RSA *>(configuration.d->privateKey.handle())); Executed by:
| 82 | ||||||||||||
216 | else if (configuration.d->privateKey.algorithm() == QSsl::Dsa
| 0 | ||||||||||||
217 | q_EVP_PKEY_set1_DSA(sslContext->pkey, reinterpret_cast<DSA *>(configuration.d->privateKey.handle())); never executed: q_EVP_PKEY_set1_DSA(sslContext->pkey, reinterpret_cast<DSA *>(configuration.d->privateKey.handle())); | 0 | ||||||||||||
218 | - | |||||||||||||
219 | else if (configuration.d->privateKey.algorithm() == QSsl::Ec
| 0 | ||||||||||||
220 | q_EVP_PKEY_set1_EC_KEY(sslContext->pkey, reinterpret_cast<EC_KEY *>(configuration.d->privateKey.handle())); never executed: q_EVP_PKEY_set1_EC_KEY(sslContext->pkey, reinterpret_cast<EC_KEY *>(configuration.d->privateKey.handle())); | 0 | ||||||||||||
221 | - | |||||||||||||
222 | } executed 82 times by 2 tests: end of block Executed by:
| 82 | ||||||||||||
223 | - | |||||||||||||
224 | if (!q_SSL_CTX_use_PrivateKey(sslContext->ctx, sslContext->pkey)
| 0-86 | ||||||||||||
225 | sslContext->errorStr = QSslSocket::tr("Error loading private key, %1").arg(QSslSocketBackendPrivate::getErrorsFromOpenSsl()); | - | ||||||||||||
226 | sslContext->errorCode = QSslError::UnspecifiedError; | - | ||||||||||||
227 | return never executed: sslContext;return sslContext; never executed: return sslContext; | 0 | ||||||||||||
228 | } | - | ||||||||||||
229 | if (configuration.d->privateKey.algorithm() == QSsl::Opaque
| 4-82 | ||||||||||||
230 | sslContext->pkey = 0; executed 4 times by 1 test: sslContext->pkey = 0; Executed by:
| 4 | ||||||||||||
231 | - | |||||||||||||
232 | - | |||||||||||||
233 | if (!q_SSL_CTX_check_private_key(sslContext->ctx)
| 0-86 | ||||||||||||
234 | sslContext->errorStr = QSslSocket::tr("Private key does not certify public key, %1").arg(QSslSocketBackendPrivate::getErrorsFromOpenSsl()); | - | ||||||||||||
235 | sslContext->errorCode = QSslError::UnspecifiedError; | - | ||||||||||||
236 | return never executed: sslContext;return sslContext; never executed: return sslContext; | 0 | ||||||||||||
237 | } | - | ||||||||||||
238 | - | |||||||||||||
239 | - | |||||||||||||
240 | bool first = true; | - | ||||||||||||
241 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(configuration.d->localCertificateChain)>::type> _container_((configuration.d->localCertificateChain)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (const QSslCertificate &cert = *_container_.i; _container_.control; _container_.control = 0) { | - | ||||||||||||
242 | if (first
| 5-86 | ||||||||||||
243 | first = false; | - | ||||||||||||
244 | continue; executed 86 times by 2 tests: continue; Executed by:
| 86 | ||||||||||||
245 | } | - | ||||||||||||
246 | q_SSL_CTX_ctrl(sslContext->ctx, 14, 0, | - | ||||||||||||
247 | q_X509_dup(reinterpret_cast<X509 *>(cert.handle()))); | - | ||||||||||||
248 | } executed 5 times by 1 test: end of block Executed by:
| 5 | ||||||||||||
249 | } executed 86 times by 2 tests: end of block Executed by:
| 86 | ||||||||||||
250 | - | |||||||||||||
251 | - | |||||||||||||
252 | if (sslContext->sslConfiguration.peerVerifyMode() == QSslSocket::VerifyNone
| 7-439 | ||||||||||||
253 | q_SSL_CTX_set_verify(sslContext->ctx, 0x00, 0); | - | ||||||||||||
254 | } executed 7 times by 1 test: else {end of block Executed by:
| 7 | ||||||||||||
255 | q_SSL_CTX_set_verify(sslContext->ctx, 0x01, q_X509Callback); | - | ||||||||||||
256 | } executed 439 times by 7 tests: end of block Executed by:
| 439 | ||||||||||||
257 | - | |||||||||||||
258 | - | |||||||||||||
259 | if (sslContext->sslConfiguration.peerVerifyDepth() != 0
| 0-446 | ||||||||||||
260 | q_SSL_CTX_set_verify_depth(sslContext->ctx, sslContext->sslConfiguration.peerVerifyDepth()); never executed: q_SSL_CTX_set_verify_depth(sslContext->ctx, sslContext->sslConfiguration.peerVerifyDepth()); | 0 | ||||||||||||
261 | - | |||||||||||||
262 | - | |||||||||||||
263 | if (!configuration.sessionTicket().isEmpty()
| 1-445 | ||||||||||||
264 | sslContext->setSessionASN1(configuration.sessionTicket()); executed 1 time by 1 test: sslContext->setSessionASN1(configuration.sessionTicket()); Executed by:
| 1 | ||||||||||||
265 | - | |||||||||||||
266 | - | |||||||||||||
267 | DH *dh = 0; | - | ||||||||||||
268 | dh = get_dh1024(); | - | ||||||||||||
269 | q_SSL_CTX_ctrl((sslContext->ctx), 3, 0, (char *)dh); | - | ||||||||||||
270 | q_DH_free(dh); | - | ||||||||||||
271 | - | |||||||||||||
272 | - | |||||||||||||
273 | - | |||||||||||||
274 | - | |||||||||||||
275 | - | |||||||||||||
276 | - | |||||||||||||
277 | - | |||||||||||||
278 | { | - | ||||||||||||
279 | - | |||||||||||||
280 | EC_KEY *ecdh = 0; | - | ||||||||||||
281 | ecdh = q_EC_KEY_new_by_curve_name(415); | - | ||||||||||||
282 | q_SSL_CTX_ctrl((sslContext->ctx), 4, 0, (char *)ecdh); | - | ||||||||||||
283 | q_EC_KEY_free(ecdh); | - | ||||||||||||
284 | } | - | ||||||||||||
285 | - | |||||||||||||
286 | - | |||||||||||||
287 | const QVector<QSslEllipticCurve> qcurves = sslContext->sslConfiguration.ellipticCurves(); | - | ||||||||||||
288 | if (!qcurves.isEmpty()
| 0-446 | ||||||||||||
289 | { | - | ||||||||||||
290 | - | |||||||||||||
291 | sslContext->errorStr = msgErrorSettingEllipticCurves(QSslSocket::tr("OpenSSL version too old, need at least v1.0.2")); | - | ||||||||||||
292 | sslContext->errorCode = QSslError::UnspecifiedError; | - | ||||||||||||
293 | return never executed: sslContext;return sslContext; never executed: return sslContext; | 0 | ||||||||||||
294 | } | - | ||||||||||||
295 | } | - | ||||||||||||
296 | - | |||||||||||||
297 | return executed 446 times by 7 tests: sslContext;return sslContext; Executed by:
executed 446 times by 7 tests: return sslContext; Executed by:
| 446 | ||||||||||||
298 | } | - | ||||||||||||
299 | - | |||||||||||||
300 | - | |||||||||||||
301 | - | |||||||||||||
302 | static int next_proto_cb(SSL *, unsigned char **out, unsigned char *outlen, | - | ||||||||||||
303 | const unsigned char *in, unsigned int inlen, void *arg) | - | ||||||||||||
304 | { | - | ||||||||||||
305 | QSslContext::NPNContext *ctx = reinterpret_cast<QSslContext::NPNContext *>(arg); | - | ||||||||||||
306 | int proto = q_SSL_select_next_proto(out, outlen, in, inlen, ctx->data, ctx->len); | - | ||||||||||||
307 | switch (proto) { | - | ||||||||||||
308 | case never executed: 0:case 0: never executed: case 0: | 0 | ||||||||||||
309 | ctx->status = QSslConfiguration::NextProtocolNegotiationNone; | - | ||||||||||||
310 | break; never executed: break; | 0 | ||||||||||||
311 | case executed 7 times by 1 test: 1:case 1: Executed by:
executed 7 times by 1 test: case 1: Executed by:
| 7 | ||||||||||||
312 | ctx->status = QSslConfiguration::NextProtocolNegotiationNegotiated; | - | ||||||||||||
313 | break; executed 7 times by 1 test: break; Executed by:
| 7 | ||||||||||||
314 | case never executed: 2:case 2: never executed: case 2: | 0 | ||||||||||||
315 | ctx->status = QSslConfiguration::NextProtocolNegotiationUnsupported; | - | ||||||||||||
316 | break; never executed: break; | 0 | ||||||||||||
317 | default never executed: :default: never executed: default: | 0 | ||||||||||||
318 | for (bool qt_category_enabled = lcSsl().isWarningEnabled(); qt_category_enabled
never executed: QMessageLogger(__FILE__, 396, __PRETTY_FUNCTION__, lcSsl().categoryName()).warning("OpenSSL sent unknown NPN status"); | 0 | ||||||||||||
319 | } never executed: end of block | 0 | ||||||||||||
320 | - | |||||||||||||
321 | return executed 7 times by 1 test: 0;return 0; Executed by:
executed 7 times by 1 test: return 0; Executed by:
| 7 | ||||||||||||
322 | } | - | ||||||||||||
323 | - | |||||||||||||
324 | QSslContext::NPNContext QSslContext::npnContext() const | - | ||||||||||||
325 | { | - | ||||||||||||
326 | return executed 700 times by 7 tests: m_npnContext;return m_npnContext; Executed by:
executed 700 times by 7 tests: return m_npnContext; Executed by:
| 700 | ||||||||||||
327 | } | - | ||||||||||||
328 | - | |||||||||||||
329 | - | |||||||||||||
330 | - | |||||||||||||
331 | SSL* QSslContext::createSsl() | - | ||||||||||||
332 | { | - | ||||||||||||
333 | SSL* ssl = q_SSL_new(ctx); | - | ||||||||||||
334 | q_SSL_clear(ssl); | - | ||||||||||||
335 | - | |||||||||||||
336 | if (!session
| 1-456 | ||||||||||||
337 | && !sslConfiguration.testSslOption(QSsl::SslOptionDisableSessionPersistence)
| 0-1 | ||||||||||||
338 | const unsigned char *data = reinterpret_cast<const unsigned char *>(m_sessionASN1.constData()); | - | ||||||||||||
339 | session = q_d2i_SSL_SESSION(0, &data, m_sessionASN1.size()); | - | ||||||||||||
340 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||
341 | - | |||||||||||||
342 | if (session
| 16-455 | ||||||||||||
343 | - | |||||||||||||
344 | if (!q_SSL_set_session(ssl, session)
| 0-16 | ||||||||||||
345 | for (bool qt_category_enabled = lcSsl().isWarningEnabled(); qt_category_enabled
never executed: QMessageLogger(__FILE__, 423, __PRETTY_FUNCTION__, lcSsl().categoryName()).warning("could not set SSL session"); | 0 | ||||||||||||
346 | q_SSL_SESSION_free(session); | - | ||||||||||||
347 | session = 0; | - | ||||||||||||
348 | } never executed: end of block | 0 | ||||||||||||
349 | } executed 16 times by 1 test: end of block Executed by:
| 16 | ||||||||||||
350 | - | |||||||||||||
351 | - | |||||||||||||
352 | QList<QByteArray> protocols = sslConfiguration.d->nextAllowedProtocols; | - | ||||||||||||
353 | if (!protocols.isEmpty()
| 7-464 | ||||||||||||
354 | m_supportedNPNVersions.clear(); | - | ||||||||||||
355 | for (int a = 0; a < protocols.count()
| 7-14 | ||||||||||||
356 | if (protocols.at(a).size() > 255
| 0-14 | ||||||||||||
357 | for (bool qt_category_enabled = lcSsl().isWarningEnabled(); qt_category_enabled
never executed: QMessageLogger(__FILE__, 435, __PRETTY_FUNCTION__, lcSsl().categoryName()).warning() << "TLS NPN extension" << protocols.at(a) << "is too long and will be truncated to 255 characters."; | 0 | ||||||||||||
358 | << "is too long and will be truncated to 255 characters."; never executed: QMessageLogger(__FILE__, 435, __PRETTY_FUNCTION__, lcSsl().categoryName()).warning() << "TLS NPN extension" << protocols.at(a) << "is too long and will be truncated to 255 characters."; | 0 | ||||||||||||
359 | protocols[a] = protocols.at(a).left(255); | - | ||||||||||||
360 | } never executed: end of block | 0 | ||||||||||||
361 | m_supportedNPNVersions.append(protocols.at(a).size()).append(protocols.at(a)); | - | ||||||||||||
362 | } executed 14 times by 1 test: end of block Executed by:
| 14 | ||||||||||||
363 | m_npnContext.data = reinterpret_cast<unsigned char *>(m_supportedNPNVersions.data()); | - | ||||||||||||
364 | m_npnContext.len = m_supportedNPNVersions.count(); | - | ||||||||||||
365 | m_npnContext.status = QSslConfiguration::NextProtocolNegotiationNone; | - | ||||||||||||
366 | q_SSL_CTX_set_next_proto_select_cb(ctx, next_proto_cb, &m_npnContext); | - | ||||||||||||
367 | } executed 7 times by 1 test: end of block Executed by:
| 7 | ||||||||||||
368 | - | |||||||||||||
369 | - | |||||||||||||
370 | return executed 471 times by 7 tests: ssl;return ssl; Executed by:
executed 471 times by 7 tests: return ssl; Executed by:
| 471 | ||||||||||||
371 | } | - | ||||||||||||
372 | - | |||||||||||||
373 | - | |||||||||||||
374 | bool QSslContext::cacheSession(SSL* ssl) | - | ||||||||||||
375 | { | - | ||||||||||||
376 | - | |||||||||||||
377 | if (session
| 0-329 | ||||||||||||
378 | return executed 16 times by 1 test: true;return true; Executed by:
executed 16 times by 1 test: return true; Executed by:
| 16 | ||||||||||||
379 | - | |||||||||||||
380 | - | |||||||||||||
381 | - | |||||||||||||
382 | if (session
| 0-329 | ||||||||||||
383 | q_SSL_SESSION_free(session); never executed: q_SSL_SESSION_free(session); | 0 | ||||||||||||
384 | - | |||||||||||||
385 | - | |||||||||||||
386 | session = q_SSL_get1_session(ssl); | - | ||||||||||||
387 | - | |||||||||||||
388 | if (session
| 0-329 | ||||||||||||
389 | int sessionSize = q_i2d_SSL_SESSION(session, 0); | - | ||||||||||||
390 | if (sessionSize > 0
| 0-1 | ||||||||||||
391 | m_sessionASN1.resize(sessionSize); | - | ||||||||||||
392 | unsigned char *data = reinterpret_cast<unsigned char *>(m_sessionASN1.data()); | - | ||||||||||||
393 | if (!q_i2d_SSL_SESSION(session, &data)
| 0-1 | ||||||||||||
394 | for (bool qt_category_enabled = lcSsl().isWarningEnabled(); qt_category_enabled
never executed: QMessageLogger(__FILE__, 472, __PRETTY_FUNCTION__, lcSsl().categoryName()).warning("could not store persistent version of SSL session"); | 0 | ||||||||||||
395 | m_sessionTicketLifeTimeHint = session->tlsext_tick_lifetime_hint; | - | ||||||||||||
396 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||
397 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||
398 | - | |||||||||||||
399 | return executed 329 times by 7 tests: (session != 0);return (session != 0); Executed by:
executed 329 times by 7 tests: return (session != 0); Executed by:
| 329 | ||||||||||||
400 | } | - | ||||||||||||
401 | - | |||||||||||||
402 | QByteArray QSslContext::sessionASN1() const | - | ||||||||||||
403 | { | - | ||||||||||||
404 | return executed 460 times by 7 tests: m_sessionASN1;return m_sessionASN1; Executed by:
executed 460 times by 7 tests: return m_sessionASN1; Executed by:
| 460 | ||||||||||||
405 | } | - | ||||||||||||
406 | - | |||||||||||||
407 | void QSslContext::setSessionASN1(const QByteArray &session) | - | ||||||||||||
408 | { | - | ||||||||||||
409 | m_sessionASN1 = session; | - | ||||||||||||
410 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||
411 | - | |||||||||||||
412 | int QSslContext::sessionTicketLifeTimeHint() const | - | ||||||||||||
413 | { | - | ||||||||||||
414 | return executed 2 times by 1 test: m_sessionTicketLifeTimeHint;return m_sessionTicketLifeTimeHint; Executed by:
executed 2 times by 1 test: return m_sessionTicketLifeTimeHint; Executed by:
| 2 | ||||||||||||
415 | } | - | ||||||||||||
416 | - | |||||||||||||
417 | QSslError::SslError QSslContext::error() const | - | ||||||||||||
418 | { | - | ||||||||||||
419 | return executed 479 times by 7 tests: errorCode;return errorCode; Executed by:
executed 479 times by 7 tests: return errorCode; Executed by:
| 479 | ||||||||||||
420 | } | - | ||||||||||||
421 | - | |||||||||||||
422 | QString QSslContext::errorString() const | - | ||||||||||||
423 | { | - | ||||||||||||
424 | return executed 8 times by 2 tests: errorStr;return errorStr; Executed by:
executed 8 times by 2 tests: return errorStr; Executed by:
| 8 | ||||||||||||
425 | } | - | ||||||||||||
426 | - | |||||||||||||
427 | - | |||||||||||||
Switch to Source code | Preprocessed file |