OpenCoverage

qsslkey_openssl.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/network/ssl/qsslkey_openssl.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtNetwork module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40-
41#include "qsslkey.h"-
42#include "qsslkey_p.h"-
43#include "qsslsocket_openssl_symbols_p.h"-
44#include "qsslsocket.h"-
45#include "qsslsocket_p.h"-
46-
47#include <QtCore/qatomic.h>-
48#include <QtCore/qbytearray.h>-
49#include <QtCore/qiodevice.h>-
50#ifndef QT_NO_DEBUG_STREAM-
51#include <QtCore/qdebug.h>-
52#endif-
53-
54QT_BEGIN_NAMESPACE-
55-
56void QSslKeyPrivate::clear(bool deep)-
57{-
58 isNull = true;-
59 if (!QSslSocket::supportsSsl())
!QSslSocket::supportsSsl()Description
TRUEnever evaluated
FALSEevaluated 28524 times by 25 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkDiskCache
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QXmlInputSource
  • tst_Spdy
  • tst_networkselftest - unknown status
  • tst_qabstractnetworkcache - unknown status
  • tst_qhttpnetworkconnection - unknown status
  • tst_qnetworkaccessmanager_and_qprogressdialog - unknown status
  • tst_qnetworkdiskcache - unknown status
  • tst_qnetworkproxyfactory - unknown status
  • tst_qsslcertificate - unknown status
  • tst_qsslellipticcurve - unknown status
  • tst_qsslerror - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
  • tst_qxmlinputsource - unknown status
  • tst_spdy - unknown status
0-28524
60 return;
never executed: return;
0
61 if (algorithm == QSsl::Rsa && rsa) {
algorithm == QSsl::RsaDescription
TRUEevaluated 760 times by 4 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
FALSEevaluated 27764 times by 25 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkDiskCache
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QXmlInputSource
  • tst_Spdy
  • tst_networkselftest - unknown status
  • tst_qabstractnetworkcache - unknown status
  • tst_qhttpnetworkconnection - unknown status
  • tst_qnetworkaccessmanager_and_qprogressdialog - unknown status
  • tst_qnetworkdiskcache - unknown status
  • tst_qnetworkproxyfactory - unknown status
  • tst_qsslcertificate - unknown status
  • tst_qsslellipticcurve - unknown status
  • tst_qsslerror - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
  • tst_qxmlinputsource - unknown status
  • tst_spdy - unknown status
rsaDescription
TRUEevaluated 374 times by 4 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
FALSEevaluated 386 times by 4 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
374-27764
62 if (deep)
deepDescription
TRUEevaluated 374 times by 4 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
FALSEnever evaluated
0-374
63 q_RSA_free(rsa);
executed 374 times by 4 tests: q_RSA_free(rsa);
Executed by:
  • tst_QNetworkReply
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
374
64 rsa = 0;-
65 }
executed 374 times by 4 tests: end of block
Executed by:
  • tst_QNetworkReply
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
374
66 if (algorithm == QSsl::Dsa && dsa) {
algorithm == QSsl::DsaDescription
TRUEevaluated 323 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
FALSEevaluated 28201 times by 25 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkDiskCache
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QXmlInputSource
  • tst_Spdy
  • tst_networkselftest - unknown status
  • tst_qabstractnetworkcache - unknown status
  • tst_qhttpnetworkconnection - unknown status
  • tst_qnetworkaccessmanager_and_qprogressdialog - unknown status
  • tst_qnetworkdiskcache - unknown status
  • tst_qnetworkproxyfactory - unknown status
  • tst_qsslcertificate - unknown status
  • tst_qsslellipticcurve - unknown status
  • tst_qsslerror - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
  • tst_qxmlinputsource - unknown status
  • tst_spdy - unknown status
dsaDescription
TRUEevaluated 162 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
FALSEevaluated 161 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
161-28201
67 if (deep)
deepDescription
TRUEevaluated 162 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
FALSEnever evaluated
0-162
68 q_DSA_free(dsa);
executed 162 times by 2 tests: q_DSA_free(dsa);
Executed by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
162
69 dsa = 0;-
70 }
executed 162 times by 2 tests: end of block
Executed by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
162
71#ifndef OPENSSL_NO_EC-
72 if (algorithm == QSsl::Ec && ec) {
algorithm == QSsl::EcDescription
TRUEevaluated 243 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
FALSEevaluated 28281 times by 25 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkDiskCache
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QXmlInputSource
  • tst_Spdy
  • tst_networkselftest - unknown status
  • tst_qabstractnetworkcache - unknown status
  • tst_qhttpnetworkconnection - unknown status
  • tst_qnetworkaccessmanager_and_qprogressdialog - unknown status
  • tst_qnetworkdiskcache - unknown status
  • tst_qnetworkproxyfactory - unknown status
  • tst_qsslcertificate - unknown status
  • tst_qsslellipticcurve - unknown status
  • tst_qsslerror - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
  • tst_qxmlinputsource - unknown status
  • tst_spdy - unknown status
ecDescription
TRUEevaluated 122 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
FALSEevaluated 121 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
121-28281
73 if (deep)
deepDescription
TRUEevaluated 122 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
FALSEnever evaluated
0-122
74 q_EC_KEY_free(ec);
executed 122 times by 2 tests: q_EC_KEY_free(ec);
Executed by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
122
75 ec = 0;-
76 }
executed 122 times by 2 tests: end of block
Executed by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
122
77#endif-
78 if (algorithm == QSsl::Opaque && opaque) {
algorithm == QSsl::OpaqueDescription
TRUEevaluated 27198 times by 25 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkDiskCache
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QXmlInputSource
  • tst_Spdy
  • tst_networkselftest - unknown status
  • tst_qabstractnetworkcache - unknown status
  • tst_qhttpnetworkconnection - unknown status
  • tst_qnetworkaccessmanager_and_qprogressdialog - unknown status
  • tst_qnetworkdiskcache - unknown status
  • tst_qnetworkproxyfactory - unknown status
  • tst_qsslcertificate - unknown status
  • tst_qsslellipticcurve - unknown status
  • tst_qsslerror - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
  • tst_qxmlinputsource - unknown status
  • tst_spdy - unknown status
FALSEevaluated 1326 times by 4 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
opaqueDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • tst_qsslsocket - unknown status
FALSEevaluated 27193 times by 25 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkDiskCache
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QXmlInputSource
  • tst_Spdy
  • tst_networkselftest - unknown status
  • tst_qabstractnetworkcache - unknown status
  • tst_qhttpnetworkconnection - unknown status
  • tst_qnetworkaccessmanager_and_qprogressdialog - unknown status
  • tst_qnetworkdiskcache - unknown status
  • tst_qnetworkproxyfactory - unknown status
  • tst_qsslcertificate - unknown status
  • tst_qsslellipticcurve - unknown status
  • tst_qsslerror - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
  • tst_qxmlinputsource - unknown status
  • tst_spdy - unknown status
5-27198
79 if (deep)
deepDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • tst_qsslsocket - unknown status
FALSEnever evaluated
0-5
80 q_EVP_PKEY_free(opaque);
executed 5 times by 1 test: q_EVP_PKEY_free(opaque);
Executed by:
  • tst_qsslsocket - unknown status
5
81 opaque = 0;-
82 }
executed 5 times by 1 test: end of block
Executed by:
  • tst_qsslsocket - unknown status
5
83}
executed 28524 times by 25 tests: end of block
Executed by:
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkDiskCache
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QXmlInputSource
  • tst_Spdy
  • tst_networkselftest - unknown status
  • tst_qabstractnetworkcache - unknown status
  • tst_qhttpnetworkconnection - unknown status
  • tst_qnetworkaccessmanager_and_qprogressdialog - unknown status
  • tst_qnetworkdiskcache - unknown status
  • tst_qnetworkproxyfactory - unknown status
  • tst_qsslcertificate - unknown status
  • tst_qsslellipticcurve - unknown status
  • tst_qsslerror - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
  • tst_qxmlinputsource - unknown status
  • tst_spdy - unknown status
28524
84-
85bool QSslKeyPrivate::fromEVP_PKEY(EVP_PKEY *pkey)-
86{-
87 if (pkey->type == EVP_PKEY_RSA) {
pkey->type == 6Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_qsslcertificate - unknown status
FALSEnever evaluated
0-1
88 isNull = false;-
89 algorithm = QSsl::Rsa;-
90 type = QSsl::PrivateKey;-
91-
92 rsa = q_RSA_new();-
93 memcpy(rsa, q_EVP_PKEY_get1_RSA(pkey), sizeof(RSA));-
94-
95 return true;
executed 1 time by 1 test: return true;
Executed by:
  • tst_qsslcertificate - unknown status
1
96 }-
97 else if (pkey->type == EVP_PKEY_DSA) {
pkey->type == 116Description
TRUEnever evaluated
FALSEnever evaluated
0
98 isNull = false;-
99 algorithm = QSsl::Dsa;-
100 type = QSsl::PrivateKey;-
101-
102 dsa = q_DSA_new();-
103 memcpy(dsa, q_EVP_PKEY_get1_DSA(pkey), sizeof(DSA));-
104-
105 return true;
never executed: return true;
0
106 }-
107#ifndef OPENSSL_NO_EC-
108 else if (pkey->type == EVP_PKEY_EC) {
pkey->type == 408Description
TRUEnever evaluated
FALSEnever evaluated
0
109 isNull = false;-
110 algorithm = QSsl::Ec;-
111 type = QSsl::PrivateKey;-
112 ec = q_EC_KEY_dup(q_EVP_PKEY_get1_EC_KEY(pkey));-
113-
114 return true;
never executed: return true;
0
115 }-
116#endif-
117 else {-
118 // Unknown key type. This could be handled as opaque, but then-
119 // we'd eventually leak memory since we wouldn't be able to free-
120 // the underlying EVP_PKEY structure. For now, we won't support-
121 // this.-
122 }
never executed: end of block
0
123-
124 return false;
never executed: return false;
0
125}-
126-
127void QSslKeyPrivate::decodeDer(const QByteArray &der, bool deepClear)-
128{-
129 QMap<QByteArray, QByteArray> headers;-
130 decodePem(pemFromDer(der, headers), QByteArray(), deepClear);-
131}
executed 226 times by 2 tests: end of block
Executed by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
226
132-
133void QSslKeyPrivate::decodePem(const QByteArray &pem, const QByteArray &passPhrase,-
134 bool deepClear)-
135{-
136 if (pem.isEmpty())
pem.isEmpty()Description
TRUEnever evaluated
FALSEevaluated 659 times by 4 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
0-659
137 return;
never executed: return;
0
138-
139 clear(deepClear);-
140-
141 if (!QSslSocket::supportsSsl())
!QSslSocket::supportsSsl()Description
TRUEnever evaluated
FALSEevaluated 659 times by 4 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
0-659
142 return;
never executed: return;
0
143-
144 BIO *bio = q_BIO_new_mem_buf(const_cast<char *>(pem.data()), pem.size());-
145 if (!bio)
!bioDescription
TRUEnever evaluated
FALSEevaluated 659 times by 4 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
0-659
146 return;
never executed: return;
0
147-
148 void *phrase = const_cast<char *>(passPhrase.constData());-
149-
150 if (algorithm == QSsl::Rsa) {
algorithm == QSsl::RsaDescription
TRUEevaluated 377 times by 4 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
FALSEevaluated 282 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
282-377
151 RSA *result = (type == QSsl::PublicKey)
(type == QSsl::PublicKey)Description
TRUEevaluated 116 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
FALSEevaluated 261 times by 4 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
116-261
152 ? q_PEM_read_bio_RSA_PUBKEY(bio, &rsa, 0, phrase)-
153 : q_PEM_read_bio_RSAPrivateKey(bio, &rsa, 0, phrase);-
154 if (rsa && rsa == result)
rsaDescription
TRUEevaluated 368 times by 4 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
FALSEevaluated 9 times by 1 test
Evaluated by:
  • tst_qsslkey - unknown status
rsa == resultDescription
TRUEevaluated 368 times by 4 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
FALSEnever evaluated
0-368
155 isNull = false;
executed 368 times by 4 tests: isNull = false;
Executed by:
  • tst_QNetworkReply
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
368
156 } else if (algorithm == QSsl::Dsa) {
executed 377 times by 4 tests: end of block
Executed by:
  • tst_QNetworkReply
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
algorithm == QSsl::DsaDescription
TRUEevaluated 161 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
FALSEevaluated 121 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
121-377
157 DSA *result = (type == QSsl::PublicKey)
(type == QSsl::PublicKey)Description
TRUEevaluated 65 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
FALSEevaluated 96 times by 1 test
Evaluated by:
  • tst_qsslkey - unknown status
65-96
158 ? q_PEM_read_bio_DSA_PUBKEY(bio, &dsa, 0, phrase)-
159 : q_PEM_read_bio_DSAPrivateKey(bio, &dsa, 0, phrase);-
160 if (dsa && dsa == result)
dsaDescription
TRUEevaluated 161 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
FALSEnever evaluated
dsa == resultDescription
TRUEevaluated 161 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
FALSEnever evaluated
0-161
161 isNull = false;
executed 161 times by 2 tests: isNull = false;
Executed by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
161
162#ifndef OPENSSL_NO_EC-
163 } else if (algorithm == QSsl::Ec) {
executed 161 times by 2 tests: end of block
Executed by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
algorithm == QSsl::EcDescription
TRUEevaluated 121 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
FALSEnever evaluated
0-161
164 EC_KEY *result = (type == QSsl::PublicKey)
(type == QSsl::PublicKey)Description
TRUEevaluated 49 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
FALSEevaluated 72 times by 1 test
Evaluated by:
  • tst_qsslkey - unknown status
49-72
165 ? q_PEM_read_bio_EC_PUBKEY(bio, &ec, 0, phrase)-
166 : q_PEM_read_bio_ECPrivateKey(bio, &ec, 0, phrase);-
167 if (ec && ec == result)
ecDescription
TRUEevaluated 121 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
FALSEnever evaluated
ec == resultDescription
TRUEevaluated 121 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
FALSEnever evaluated
0-121
168 isNull = false;
executed 121 times by 2 tests: isNull = false;
Executed by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
121
169#endif-
170 }
executed 121 times by 2 tests: end of block
Executed by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
121
171-
172 q_BIO_free(bio);-
173}
executed 659 times by 4 tests: end of block
Executed by:
  • tst_QNetworkReply
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
659
174-
175int QSslKeyPrivate::length() const-
176{-
177 if (isNull || algorithm == QSsl::Opaque)
isNullDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_qsslkey - unknown status
FALSEevaluated 744 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
algorithm == QSsl::OpaqueDescription
TRUEnever evaluated
FALSEevaluated 744 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
0-744
178 return -1;
executed 1 time by 1 test: return -1;
Executed by:
  • tst_qsslkey - unknown status
1
179-
180 switch (algorithm) {-
181 case QSsl::Rsa: return q_BN_num_bits(rsa->n);
executed 376 times by 2 tests: return q_BN_num_bits(rsa->n);
Executed by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
executed 376 times by 2 tests: case QSsl::Rsa:
Executed by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
376
182 case QSsl::Dsa: return q_BN_num_bits(dsa->p);
executed 210 times by 2 tests: return q_BN_num_bits(dsa->p);
Executed by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
executed 210 times by 2 tests: case QSsl::Dsa:
Executed by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
210
183#ifndef OPENSSL_NO_EC-
184 case QSsl::Ec: return q_EC_GROUP_get_degree(q_EC_KEY_get0_group(ec));
executed 158 times by 2 tests: return q_EC_GROUP_get_degree(q_EC_KEY_get0_group(ec));
Executed by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
executed 158 times by 2 tests: case QSsl::Ec:
Executed by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
158
185#endif-
186 default: return -1;
never executed: return -1;
never executed: default:
0
187 }-
188}-
189-
190QByteArray QSslKeyPrivate::toPem(const QByteArray &passPhrase) const-
191{-
192 if (!QSslSocket::supportsSsl() || isNull || algorithm == QSsl::Opaque)
!QSslSocket::supportsSsl()Description
TRUEnever evaluated
FALSEevaluated 1752 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
isNullDescription
TRUEnever evaluated
FALSEevaluated 1752 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
algorithm == QSsl::OpaqueDescription
TRUEnever evaluated
FALSEevaluated 1752 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
0-1752
193 return QByteArray();
never executed: return QByteArray();
0
194-
195 BIO *bio = q_BIO_new(q_BIO_s_mem());-
196 if (!bio)
!bioDescription
TRUEnever evaluated
FALSEevaluated 1752 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
0-1752
197 return QByteArray();
never executed: return QByteArray();
0
198-
199 bool fail = false;-
200-
201 if (algorithm == QSsl::Rsa) {
algorithm == QSsl::RsaDescription
TRUEevaluated 880 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
FALSEevaluated 872 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
872-880
202 if (type == QSsl::PublicKey) {
type == QSsl::PublicKeyDescription
TRUEevaluated 416 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
FALSEevaluated 464 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
416-464
203 if (!q_PEM_write_bio_RSA_PUBKEY(bio, rsa))
!q_PEM_write_b...BKEY(bio, rsa)Description
TRUEnever evaluated
FALSEevaluated 416 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
0-416
204 fail = true;
never executed: fail = true;
0
205 } else {
executed 416 times by 2 tests: end of block
Executed by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
416
206 if (!q_PEM_write_bio_RSAPrivateKey(
!q_PEM_write_b....size(), 0, 0)Description
TRUEnever evaluated
FALSEevaluated 464 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
0-464
207 bio, rsa,
!q_PEM_write_b....size(), 0, 0)Description
TRUEnever evaluated
FALSEevaluated 464 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
0-464
208 // ### the cipher should be selectable in the API:
!q_PEM_write_b....size(), 0, 0)Description
TRUEnever evaluated
FALSEevaluated 464 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
0-464
209 passPhrase.isEmpty() ? (const EVP_CIPHER *)0 : q_EVP_des_ede3_cbc(),
!q_PEM_write_b....size(), 0, 0)Description
TRUEnever evaluated
FALSEevaluated 464 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
0-464
210 const_cast<uchar *>((const uchar *)passPhrase.data()), passPhrase.size(), 0, 0)) {
!q_PEM_write_b....size(), 0, 0)Description
TRUEnever evaluated
FALSEevaluated 464 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
0-464
211 fail = true;-
212 }
never executed: end of block
0
213 }
executed 464 times by 2 tests: end of block
Executed by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
464
214 } else if (algorithm == QSsl::Dsa) {
algorithm == QSsl::DsaDescription
TRUEevaluated 498 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
FALSEevaluated 374 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
374-498
215 if (type == QSsl::PublicKey) {
type == QSsl::PublicKeyDescription
TRUEevaluated 234 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
FALSEevaluated 264 times by 1 test
Evaluated by:
  • tst_qsslkey - unknown status
234-264
216 if (!q_PEM_write_bio_DSA_PUBKEY(bio, dsa))
!q_PEM_write_b...BKEY(bio, dsa)Description
TRUEnever evaluated
FALSEevaluated 234 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
0-234
217 fail = true;
never executed: fail = true;
0
218 } else {
executed 234 times by 2 tests: end of block
Executed by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
234
219 if (!q_PEM_write_bio_DSAPrivateKey(
!q_PEM_write_b....size(), 0, 0)Description
TRUEnever evaluated
FALSEevaluated 264 times by 1 test
Evaluated by:
  • tst_qsslkey - unknown status
0-264
220 bio, dsa,
!q_PEM_write_b....size(), 0, 0)Description
TRUEnever evaluated
FALSEevaluated 264 times by 1 test
Evaluated by:
  • tst_qsslkey - unknown status
0-264
221 // ### the cipher should be selectable in the API:
!q_PEM_write_b....size(), 0, 0)Description
TRUEnever evaluated
FALSEevaluated 264 times by 1 test
Evaluated by:
  • tst_qsslkey - unknown status
0-264
222 passPhrase.isEmpty() ? (const EVP_CIPHER *)0 : q_EVP_des_ede3_cbc(),
!q_PEM_write_b....size(), 0, 0)Description
TRUEnever evaluated
FALSEevaluated 264 times by 1 test
Evaluated by:
  • tst_qsslkey - unknown status
0-264
223 const_cast<uchar *>((const uchar *)passPhrase.data()), passPhrase.size(), 0, 0)) {
!q_PEM_write_b....size(), 0, 0)Description
TRUEnever evaluated
FALSEevaluated 264 times by 1 test
Evaluated by:
  • tst_qsslkey - unknown status
0-264
224 fail = true;-
225 }
never executed: end of block
0
226 }
executed 264 times by 1 test: end of block
Executed by:
  • tst_qsslkey - unknown status
264
227#ifndef OPENSSL_NO_EC-
228 } else if (algorithm == QSsl::Ec) {
algorithm == QSsl::EcDescription
TRUEevaluated 374 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
FALSEnever evaluated
0-374
229 if (type == QSsl::PublicKey) {
type == QSsl::PublicKeyDescription
TRUEevaluated 176 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
FALSEevaluated 198 times by 1 test
Evaluated by:
  • tst_qsslkey - unknown status
176-198
230 if (!q_PEM_write_bio_EC_PUBKEY(bio, ec))
!q_PEM_write_b...UBKEY(bio, ec)Description
TRUEnever evaluated
FALSEevaluated 176 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
0-176
231 fail = true;
never executed: fail = true;
0
232 } else {
executed 176 times by 2 tests: end of block
Executed by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
176
233 if (!q_PEM_write_bio_ECPrivateKey(
!q_PEM_write_b....size(), 0, 0)Description
TRUEnever evaluated
FALSEevaluated 198 times by 1 test
Evaluated by:
  • tst_qsslkey - unknown status
0-198
234 bio, ec,
!q_PEM_write_b....size(), 0, 0)Description
TRUEnever evaluated
FALSEevaluated 198 times by 1 test
Evaluated by:
  • tst_qsslkey - unknown status
0-198
235 // ### the cipher should be selectable in the API:
!q_PEM_write_b....size(), 0, 0)Description
TRUEnever evaluated
FALSEevaluated 198 times by 1 test
Evaluated by:
  • tst_qsslkey - unknown status
0-198
236 passPhrase.isEmpty() ? (const EVP_CIPHER *)0 : q_EVP_des_ede3_cbc(),
!q_PEM_write_b....size(), 0, 0)Description
TRUEnever evaluated
FALSEevaluated 198 times by 1 test
Evaluated by:
  • tst_qsslkey - unknown status
0-198
237 const_cast<uchar *>((const uchar *)passPhrase.data()), passPhrase.size(), 0, 0)) {
!q_PEM_write_b....size(), 0, 0)Description
TRUEnever evaluated
FALSEevaluated 198 times by 1 test
Evaluated by:
  • tst_qsslkey - unknown status
0-198
238 fail = true;-
239 }
never executed: end of block
0
240 }
executed 198 times by 1 test: end of block
Executed by:
  • tst_qsslkey - unknown status
198
241#endif-
242 } else {-
243 fail = true;-
244 }
never executed: end of block
0
245-
246 QByteArray pem;-
247 if (!fail) {
!failDescription
TRUEevaluated 1752 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
FALSEnever evaluated
0-1752
248 char *data;-
249 long size = q_BIO_get_mem_data(bio, &data);-
250 pem = QByteArray(data, size);-
251 }
executed 1752 times by 2 tests: end of block
Executed by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
1752
252 q_BIO_free(bio);-
253 return pem;
executed 1752 times by 2 tests: return pem;
Executed by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
1752
254}-
255-
256Qt::HANDLE QSslKeyPrivate::handle() const-
257{-
258 switch (algorithm) {-
259 case QSsl::Opaque:
executed 4 times by 1 test: case QSsl::Opaque:
Executed by:
  • tst_qsslsocket - unknown status
4
260 return Qt::HANDLE(opaque);
executed 4 times by 1 test: return Qt::HANDLE(opaque);
Executed by:
  • tst_qsslsocket - unknown status
4
261 case QSsl::Rsa:
executed 89 times by 2 tests: case QSsl::Rsa:
Executed by:
  • tst_QNetworkReply
  • tst_qsslsocket - unknown status
89
262 return Qt::HANDLE(rsa);
executed 89 times by 2 tests: return Qt::HANDLE(rsa);
Executed by:
  • tst_QNetworkReply
  • tst_qsslsocket - unknown status
89
263 case QSsl::Dsa:
never executed: case QSsl::Dsa:
0
264 return Qt::HANDLE(dsa);
never executed: return Qt::HANDLE(dsa);
0
265#ifndef OPENSSL_NO_EC-
266 case QSsl::Ec:
never executed: case QSsl::Ec:
0
267 return Qt::HANDLE(ec);
never executed: return Qt::HANDLE(ec);
0
268#endif-
269 default:
never executed: default:
0
270 return Qt::HANDLE(NULL);
never executed: return Qt::HANDLE(__null);
0
271 }-
272}-
273-
274static QByteArray doCrypt(QSslKeyPrivate::Cipher cipher, const QByteArray &data, const QByteArray &key, const QByteArray &iv, int enc)-
275{-
276 EVP_CIPHER_CTX ctx;-
277 const EVP_CIPHER* type = 0;-
278 int i = 0, len = 0;-
279-
280 switch (cipher) {-
281 case QSslKeyPrivate::DesCbc:
executed 18 times by 1 test: case QSslKeyPrivate::DesCbc:
Executed by:
  • tst_qsslkey - unknown status
18
282 type = q_EVP_des_cbc();-
283 break;
executed 18 times by 1 test: break;
Executed by:
  • tst_qsslkey - unknown status
18
284 case QSslKeyPrivate::DesEde3Cbc:
executed 4 times by 1 test: case QSslKeyPrivate::DesEde3Cbc:
Executed by:
  • tst_qsslkey - unknown status
4
285 type = q_EVP_des_ede3_cbc();-
286 break;
executed 4 times by 1 test: break;
Executed by:
  • tst_qsslkey - unknown status
4
287 case QSslKeyPrivate::Rc2Cbc:
executed 12 times by 1 test: case QSslKeyPrivate::Rc2Cbc:
Executed by:
  • tst_qsslkey - unknown status
12
288 type = q_EVP_rc2_cbc();-
289 break;
executed 12 times by 1 test: break;
Executed by:
  • tst_qsslkey - unknown status
12
290 }-
291-
292 QByteArray output;-
293 output.resize(data.size() + EVP_MAX_BLOCK_LENGTH);-
294 q_EVP_CIPHER_CTX_init(&ctx);-
295 q_EVP_CipherInit(&ctx, type, NULL, NULL, enc);-
296 q_EVP_CIPHER_CTX_set_key_length(&ctx, key.size());-
297 if (cipher == QSslKeyPrivate::Rc2Cbc)
cipher == QSsl...rivate::Rc2CbcDescription
TRUEevaluated 12 times by 1 test
Evaluated by:
  • tst_qsslkey - unknown status
FALSEevaluated 22 times by 1 test
Evaluated by:
  • tst_qsslkey - unknown status
12-22
298 q_EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_SET_RC2_KEY_BITS, 8 * key.size(), NULL);
executed 12 times by 1 test: q_EVP_CIPHER_CTX_ctrl(&ctx, 0x3, 8 * key.size(), __null);
Executed by:
  • tst_qsslkey - unknown status
12
299 q_EVP_CipherInit(&ctx, NULL,-
300 reinterpret_cast<const unsigned char *>(key.constData()),-
301 reinterpret_cast<const unsigned char *>(iv.constData()), enc);-
302 q_EVP_CipherUpdate(&ctx,-
303 reinterpret_cast<unsigned char *>(output.data()), &len,-
304 reinterpret_cast<const unsigned char *>(data.constData()), data.size());-
305 q_EVP_CipherFinal(&ctx,-
306 reinterpret_cast<unsigned char *>(output.data()) + len, &i);-
307 len += i;-
308 q_EVP_CIPHER_CTX_cleanup(&ctx);-
309-
310 return output.left(len);
executed 34 times by 1 test: return output.left(len);
Executed by:
  • tst_qsslkey - unknown status
34
311}-
312-
313QByteArray QSslKeyPrivate::decrypt(Cipher cipher, const QByteArray &data, const QByteArray &key, const QByteArray &iv)-
314{-
315 return doCrypt(cipher, data, key, iv, 0);
executed 17 times by 1 test: return doCrypt(cipher, data, key, iv, 0);
Executed by:
  • tst_qsslkey - unknown status
17
316}-
317-
318QByteArray QSslKeyPrivate::encrypt(Cipher cipher, const QByteArray &data, const QByteArray &key, const QByteArray &iv)-
319{-
320 return doCrypt(cipher, data, key, iv, 1);
executed 17 times by 1 test: return doCrypt(cipher, data, key, iv, 1);
Executed by:
  • tst_qsslkey - unknown status
17
321}-
322-
323QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9