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) 2015 The Qt Company Ltd.-
4** Contact: http://www.qt.io/licensing/-
5**-
6** This file is part of the QtNetwork module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL21$-
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 http://www.qt.io/terms-conditions. For further-
15** information use the contact form at http://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 2.1 or version 3 as published by the Free-
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and-
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the-
22** following information to ensure the GNU Lesser General Public License-
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and-
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.-
25**-
26** As a special exception, The Qt Company gives you certain additional-
27** rights. These rights are described in The Qt Company LGPL Exception-
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.-
29**-
30** $QT_END_LICENSE$-
31**-
32****************************************************************************/-
33-
34-
35#include "qsslkey.h"-
36#include "qsslkey_p.h"-
37#include "qsslsocket_openssl_symbols_p.h"-
38#include "qsslsocket.h"-
39#include "qsslsocket_p.h"-
40-
41#include <QtCore/qatomic.h>-
42#include <QtCore/qbytearray.h>-
43#include <QtCore/qiodevice.h>-
44#ifndef QT_NO_DEBUG_STREAM-
45#include <QtCore/qdebug.h>-
46#endif-
47-
48QT_BEGIN_NAMESPACE-
49-
50void QSslKeyPrivate::clear(bool deep)-
51{-
52 isNull = true;-
53 if (!QSslSocket::supportsSsl())
!QSslSocket::supportsSsl()Description
TRUEnever evaluated
FALSEevaluated 15246 times by 26 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_qnetworkreply - 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
  • ...
0-15246
54 return;
never executed: return;
0
55 if (algorithm == QSsl::Rsa && rsa) {
algorithm == QSsl::RsaDescription
TRUEevaluated 756 times by 4 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
FALSEevaluated 14490 times by 26 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_qnetworkreply - 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
  • ...
rsaDescription
TRUEevaluated 372 times by 4 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
FALSEevaluated 384 times by 4 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
372-14490
56 if (deep)
deepDescription
TRUEevaluated 372 times by 4 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
FALSEnever evaluated
0-372
57 q_RSA_free(rsa);
executed 372 times by 4 tests: q_RSA_free(rsa);
Executed by:
  • tst_QNetworkReply
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
372
58 rsa = 0;-
59 }
executed 372 times by 4 tests: end of block
Executed by:
  • tst_QNetworkReply
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
372
60 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 14923 times by 26 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_qnetworkreply - 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
  • ...
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-14923
61 if (deep)
deepDescription
TRUEevaluated 162 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
FALSEnever evaluated
0-162
62 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
63 dsa = 0;-
64 }
executed 162 times by 2 tests: end of block
Executed by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
162
65#ifndef OPENSSL_NO_EC-
66 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 15003 times by 26 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_qnetworkreply - 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
  • ...
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-15003
67 if (deep)
deepDescription
TRUEevaluated 122 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
FALSEnever evaluated
0-122
68 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
69 ec = 0;-
70 }
executed 122 times by 2 tests: end of block
Executed by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
122
71#endif-
72 if (algorithm == QSsl::Opaque && opaque) {
algorithm == QSsl::OpaqueDescription
TRUEevaluated 13924 times by 26 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_qnetworkreply - 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
  • ...
FALSEevaluated 1322 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 13919 times by 26 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_qnetworkreply - 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
  • ...
5-13924
73 if (deep)
deepDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • tst_qsslsocket - unknown status
FALSEnever evaluated
0-5
74 q_EVP_PKEY_free(opaque);
executed 5 times by 1 test: q_EVP_PKEY_free(opaque);
Executed by:
  • tst_qsslsocket - unknown status
5
75 opaque = 0;-
76 }
executed 5 times by 1 test: end of block
Executed by:
  • tst_qsslsocket - unknown status
5
77}
executed 15246 times by 26 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_qnetworkreply - 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
  • ...
15246
78-
79bool QSslKeyPrivate::fromEVP_PKEY(EVP_PKEY *pkey)-
80{-
81 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
82 isNull = false;-
83 algorithm = QSsl::Rsa;-
84 type = QSsl::PrivateKey;-
85-
86 rsa = q_RSA_new();-
87 memcpy(rsa, q_EVP_PKEY_get1_RSA(pkey), sizeof(RSA));-
88-
89 return true;
executed 1 time by 1 test: return true;
Executed by:
  • tst_qsslcertificate - unknown status
1
90 }-
91 else if (pkey->type == EVP_PKEY_DSA) {
pkey->type == 116Description
TRUEnever evaluated
FALSEnever evaluated
0
92 isNull = false;-
93 algorithm = QSsl::Dsa;-
94 type = QSsl::PrivateKey;-
95-
96 dsa = q_DSA_new();-
97 memcpy(dsa, q_EVP_PKEY_get1_DSA(pkey), sizeof(DSA));-
98-
99 return true;
never executed: return true;
0
100 }-
101#ifndef OPENSSL_NO_EC-
102 else if (pkey->type == EVP_PKEY_EC) {
pkey->type == 408Description
TRUEnever evaluated
FALSEnever evaluated
0
103 isNull = false;-
104 algorithm = QSsl::Ec;-
105 type = QSsl::PrivateKey;-
106 ec = q_EC_KEY_dup(q_EVP_PKEY_get1_EC_KEY(pkey));-
107-
108 return true;
never executed: return true;
0
109 }-
110#endif-
111 else {-
112 // Unknown key type. This could be handled as opaque, but then-
113 // we'd eventually leak memory since we wouldn't be able to free-
114 // the underlying EVP_PKEY structure. For now, we won't support-
115 // this.-
116 }
never executed: end of block
0
117-
118 return false;
never executed: return false;
0
119}-
120-
121void QSslKeyPrivate::decodeDer(const QByteArray &der, bool deepClear)-
122{-
123 QMap<QByteArray, QByteArray> headers;-
124 decodePem(pemFromDer(der, headers), QByteArray(), deepClear);-
125}
executed 226 times by 2 tests: end of block
Executed by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
226
126-
127void QSslKeyPrivate::decodePem(const QByteArray &pem, const QByteArray &passPhrase,-
128 bool deepClear)-
129{-
130 if (pem.isEmpty())
pem.isEmpty()Description
TRUEnever evaluated
FALSEevaluated 657 times by 4 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
0-657
131 return;
never executed: return;
0
132-
133 clear(deepClear);-
134-
135 if (!QSslSocket::supportsSsl())
!QSslSocket::supportsSsl()Description
TRUEnever evaluated
FALSEevaluated 657 times by 4 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
0-657
136 return;
never executed: return;
0
137-
138 BIO *bio = q_BIO_new_mem_buf(const_cast<char *>(pem.data()), pem.size());-
139 if (!bio)
!bioDescription
TRUEnever evaluated
FALSEevaluated 657 times by 4 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
0-657
140 return;
never executed: return;
0
141-
142 void *phrase = const_cast<char *>(passPhrase.constData());-
143-
144 if (algorithm == QSsl::Rsa) {
algorithm == QSsl::RsaDescription
TRUEevaluated 375 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-375
145 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 259 times by 4 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
116-259
146 ? q_PEM_read_bio_RSA_PUBKEY(bio, &rsa, 0, phrase)-
147 : q_PEM_read_bio_RSAPrivateKey(bio, &rsa, 0, phrase);-
148 if (rsa && rsa == result)
rsaDescription
TRUEevaluated 366 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 366 times by 4 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
FALSEnever evaluated
0-366
149 isNull = false;
executed 366 times by 4 tests: isNull = false;
Executed by:
  • tst_QNetworkReply
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
366
150 } else if (algorithm == QSsl::Dsa) {
executed 375 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-375
151 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
152 ? q_PEM_read_bio_DSA_PUBKEY(bio, &dsa, 0, phrase)-
153 : q_PEM_read_bio_DSAPrivateKey(bio, &dsa, 0, phrase);-
154 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
155 isNull = false;
executed 161 times by 2 tests: isNull = false;
Executed by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
161
156#ifndef OPENSSL_NO_EC-
157 } 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
158 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
159 ? q_PEM_read_bio_EC_PUBKEY(bio, &ec, 0, phrase)-
160 : q_PEM_read_bio_ECPrivateKey(bio, &ec, 0, phrase);-
161 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
162 isNull = false;
executed 121 times by 2 tests: isNull = false;
Executed by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
121
163#endif-
164 }
executed 121 times by 2 tests: end of block
Executed by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
121
165-
166 q_BIO_free(bio);-
167}
executed 657 times by 4 tests: end of block
Executed by:
  • tst_QNetworkReply
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
657
168-
169int QSslKeyPrivate::length() const-
170{-
171 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
172 return -1;
executed 1 time by 1 test: return -1;
Executed by:
  • tst_qsslkey - unknown status
1
173-
174 switch (algorithm) {-
175 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
176 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
177#ifndef OPENSSL_NO_EC-
178 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
179#endif-
180 default: return -1;
never executed: return -1;
never executed: default:
0
181 }-
182}-
183-
184QByteArray QSslKeyPrivate::toPem(const QByteArray &passPhrase) const-
185{-
186 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
187 return QByteArray();
never executed: return QByteArray();
0
188-
189 BIO *bio = q_BIO_new(q_BIO_s_mem());-
190 if (!bio)
!bioDescription
TRUEnever evaluated
FALSEevaluated 1752 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
0-1752
191 return QByteArray();
never executed: return QByteArray();
0
192-
193 bool fail = false;-
194-
195 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
196 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
197 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
198 fail = true;
never executed: fail = true;
0
199 } else {
executed 416 times by 2 tests: end of block
Executed by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
416
200 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
201 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
202 // ### 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
203 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
204 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
205 fail = true;-
206 }
never executed: end of block
0
207 }
executed 464 times by 2 tests: end of block
Executed by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
464
208 } 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
209 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
210 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
211 fail = true;
never executed: fail = true;
0
212 } else {
executed 234 times by 2 tests: end of block
Executed by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
234
213 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
214 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
215 // ### 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
216 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
217 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
218 fail = true;-
219 }
never executed: end of block
0
220 }
executed 264 times by 1 test: end of block
Executed by:
  • tst_qsslkey - unknown status
264
221#ifndef OPENSSL_NO_EC-
222 } 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
223 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
224 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
225 fail = true;
never executed: fail = true;
0
226 } else {
executed 176 times by 2 tests: end of block
Executed by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
176
227 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
228 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
229 // ### 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
230 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
231 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
232 fail = true;-
233 }
never executed: end of block
0
234 }
executed 198 times by 1 test: end of block
Executed by:
  • tst_qsslkey - unknown status
198
235#endif-
236 } else {-
237 fail = true;-
238 }
never executed: end of block
0
239-
240 QByteArray pem;-
241 if (!fail) {
!failDescription
TRUEevaluated 1752 times by 2 tests
Evaluated by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
FALSEnever evaluated
0-1752
242 char *data;-
243 long size = q_BIO_get_mem_data(bio, &data);-
244 pem = QByteArray(data, size);-
245 }
executed 1752 times by 2 tests: end of block
Executed by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
1752
246 q_BIO_free(bio);-
247 return pem;
executed 1752 times by 2 tests: return pem;
Executed by:
  • tst_qsslcertificate - unknown status
  • tst_qsslkey - unknown status
1752
248}-
249-
250Qt::HANDLE QSslKeyPrivate::handle() const-
251{-
252 switch (algorithm) {-
253 case QSsl::Opaque:
executed 4 times by 1 test: case QSsl::Opaque:
Executed by:
  • tst_qsslsocket - unknown status
4
254 return Qt::HANDLE(opaque);
executed 4 times by 1 test: return Qt::HANDLE(opaque);
Executed by:
  • tst_qsslsocket - unknown status
4
255 case QSsl::Rsa:
executed 87 times by 2 tests: case QSsl::Rsa:
Executed by:
  • tst_QNetworkReply
  • tst_qsslsocket - unknown status
87
256 return Qt::HANDLE(rsa);
executed 87 times by 2 tests: return Qt::HANDLE(rsa);
Executed by:
  • tst_QNetworkReply
  • tst_qsslsocket - unknown status
87
257 case QSsl::Dsa:
never executed: case QSsl::Dsa:
0
258 return Qt::HANDLE(dsa);
never executed: return Qt::HANDLE(dsa);
0
259#ifndef OPENSSL_NO_EC-
260 case QSsl::Ec:
never executed: case QSsl::Ec:
0
261 return Qt::HANDLE(ec);
never executed: return Qt::HANDLE(ec);
0
262#endif-
263 default:
never executed: default:
0
264 return Qt::HANDLE(NULL);
never executed: return Qt::HANDLE(__null);
0
265 }-
266}-
267-
268static QByteArray doCrypt(QSslKeyPrivate::Cipher cipher, const QByteArray &data, const QByteArray &key, const QByteArray &iv, int enc)-
269{-
270 EVP_CIPHER_CTX ctx;-
271 const EVP_CIPHER* type = 0;-
272 int i = 0, len = 0;-
273-
274 switch (cipher) {-
275 case QSslKeyPrivate::DesCbc:
executed 18 times by 1 test: case QSslKeyPrivate::DesCbc:
Executed by:
  • tst_qsslkey - unknown status
18
276 type = q_EVP_des_cbc();-
277 break;
executed 18 times by 1 test: break;
Executed by:
  • tst_qsslkey - unknown status
18
278 case QSslKeyPrivate::DesEde3Cbc:
executed 4 times by 1 test: case QSslKeyPrivate::DesEde3Cbc:
Executed by:
  • tst_qsslkey - unknown status
4
279 type = q_EVP_des_ede3_cbc();-
280 break;
executed 4 times by 1 test: break;
Executed by:
  • tst_qsslkey - unknown status
4
281 case QSslKeyPrivate::Rc2Cbc:
executed 12 times by 1 test: case QSslKeyPrivate::Rc2Cbc:
Executed by:
  • tst_qsslkey - unknown status
12
282 type = q_EVP_rc2_cbc();-
283 break;
executed 12 times by 1 test: break;
Executed by:
  • tst_qsslkey - unknown status
12
284 }-
285-
286 QByteArray output;-
287 output.resize(data.size() + EVP_MAX_BLOCK_LENGTH);-
288 q_EVP_CIPHER_CTX_init(&ctx);-
289 q_EVP_CipherInit(&ctx, type, NULL, NULL, enc);-
290 q_EVP_CIPHER_CTX_set_key_length(&ctx, key.size());-
291 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
292 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
293 q_EVP_CipherInit(&ctx, NULL,-
294 reinterpret_cast<const unsigned char *>(key.constData()),-
295 reinterpret_cast<const unsigned char *>(iv.constData()), enc);-
296 q_EVP_CipherUpdate(&ctx,-
297 reinterpret_cast<unsigned char *>(output.data()), &len,-
298 reinterpret_cast<const unsigned char *>(data.constData()), data.size());-
299 q_EVP_CipherFinal(&ctx,-
300 reinterpret_cast<unsigned char *>(output.data()) + len, &i);-
301 len += i;-
302 q_EVP_CIPHER_CTX_cleanup(&ctx);-
303-
304 return output.left(len);
executed 34 times by 1 test: return output.left(len);
Executed by:
  • tst_qsslkey - unknown status
34
305}-
306-
307QByteArray QSslKeyPrivate::decrypt(Cipher cipher, const QByteArray &data, const QByteArray &key, const QByteArray &iv)-
308{-
309 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
310}-
311-
312QByteArray QSslKeyPrivate::encrypt(Cipher cipher, const QByteArray &data, const QByteArray &key, const QByteArray &iv)-
313{-
314 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
315}-
316-
317QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

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