| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/network/ssl/qsslkey_openssl.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 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 | - | |||||||||||||||||||
| 54 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 55 | - | |||||||||||||||||||
| 56 | void QSslKeyPrivate::clear(bool deep) | - | ||||||||||||||||||
| 57 | { | - | ||||||||||||||||||
| 58 | isNull = true; | - | ||||||||||||||||||
| 59 | if (!QSslSocket::supportsSsl())
| 0-28524 | ||||||||||||||||||
| 60 | return; never executed: return; | 0 | ||||||||||||||||||
| 61 | if (algorithm == QSsl::Rsa && rsa) {
| 374-27764 | ||||||||||||||||||
| 62 | if (deep)
| 0-374 | ||||||||||||||||||
| 63 | q_RSA_free(rsa); executed 374 times by 4 tests: q_RSA_free(rsa);Executed by:
| 374 | ||||||||||||||||||
| 64 | rsa = 0; | - | ||||||||||||||||||
| 65 | } executed 374 times by 4 tests: end of blockExecuted by:
| 374 | ||||||||||||||||||
| 66 | if (algorithm == QSsl::Dsa && dsa) {
| 161-28201 | ||||||||||||||||||
| 67 | if (deep)
| 0-162 | ||||||||||||||||||
| 68 | q_DSA_free(dsa); executed 162 times by 2 tests: q_DSA_free(dsa);Executed by:
| 162 | ||||||||||||||||||
| 69 | dsa = 0; | - | ||||||||||||||||||
| 70 | } executed 162 times by 2 tests: end of blockExecuted by:
| 162 | ||||||||||||||||||
| 71 | #ifndef OPENSSL_NO_EC | - | ||||||||||||||||||
| 72 | if (algorithm == QSsl::Ec && ec) {
| 121-28281 | ||||||||||||||||||
| 73 | if (deep)
| 0-122 | ||||||||||||||||||
| 74 | q_EC_KEY_free(ec); executed 122 times by 2 tests: q_EC_KEY_free(ec);Executed by:
| 122 | ||||||||||||||||||
| 75 | ec = 0; | - | ||||||||||||||||||
| 76 | } executed 122 times by 2 tests: end of blockExecuted by:
| 122 | ||||||||||||||||||
| 77 | #endif | - | ||||||||||||||||||
| 78 | if (algorithm == QSsl::Opaque && opaque) {
| 5-27198 | ||||||||||||||||||
| 79 | if (deep)
| 0-5 | ||||||||||||||||||
| 80 | q_EVP_PKEY_free(opaque); executed 5 times by 1 test: q_EVP_PKEY_free(opaque);Executed by:
| 5 | ||||||||||||||||||
| 81 | opaque = 0; | - | ||||||||||||||||||
| 82 | } executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||||||||
| 83 | } executed 28524 times by 25 tests: end of blockExecuted by:
| 28524 | ||||||||||||||||||
| 84 | - | |||||||||||||||||||
| 85 | bool QSslKeyPrivate::fromEVP_PKEY(EVP_PKEY *pkey) | - | ||||||||||||||||||
| 86 | { | - | ||||||||||||||||||
| 87 | if (pkey->type == EVP_PKEY_RSA) {
| 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:
| 1 | ||||||||||||||||||
| 96 | } | - | ||||||||||||||||||
| 97 | else if (pkey->type == EVP_PKEY_DSA) {
| 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) {
| 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 | - | |||||||||||||||||||
| 127 | void 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 blockExecuted by:
| 226 | ||||||||||||||||||
| 132 | - | |||||||||||||||||||
| 133 | void QSslKeyPrivate::decodePem(const QByteArray &pem, const QByteArray &passPhrase, | - | ||||||||||||||||||
| 134 | bool deepClear) | - | ||||||||||||||||||
| 135 | { | - | ||||||||||||||||||
| 136 | if (pem.isEmpty())
| 0-659 | ||||||||||||||||||
| 137 | return; never executed: return; | 0 | ||||||||||||||||||
| 138 | - | |||||||||||||||||||
| 139 | clear(deepClear); | - | ||||||||||||||||||
| 140 | - | |||||||||||||||||||
| 141 | if (!QSslSocket::supportsSsl())
| 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)
| 0-659 | ||||||||||||||||||
| 146 | return; never executed: return; | 0 | ||||||||||||||||||
| 147 | - | |||||||||||||||||||
| 148 | void *phrase = const_cast<char *>(passPhrase.constData()); | - | ||||||||||||||||||
| 149 | - | |||||||||||||||||||
| 150 | if (algorithm == QSsl::Rsa) {
| 282-377 | ||||||||||||||||||
| 151 | RSA *result = (type == QSsl::PublicKey)
| 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)
| 0-368 | ||||||||||||||||||
| 155 | isNull = false; executed 368 times by 4 tests: isNull = false;Executed by:
| 368 | ||||||||||||||||||
| 156 | } else if (algorithm == QSsl::Dsa) { executed 377 times by 4 tests: end of blockExecuted by:
| 121-377 | ||||||||||||||||||
| 157 | DSA *result = (type == QSsl::PublicKey)
| 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)
| 0-161 | ||||||||||||||||||
| 161 | isNull = false; executed 161 times by 2 tests: isNull = false;Executed by:
| 161 | ||||||||||||||||||
| 162 | #ifndef OPENSSL_NO_EC | - | ||||||||||||||||||
| 163 | } else if (algorithm == QSsl::Ec) { executed 161 times by 2 tests: end of blockExecuted by:
| 0-161 | ||||||||||||||||||
| 164 | EC_KEY *result = (type == QSsl::PublicKey)
| 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)
| 0-121 | ||||||||||||||||||
| 168 | isNull = false; executed 121 times by 2 tests: isNull = false;Executed by:
| 121 | ||||||||||||||||||
| 169 | #endif | - | ||||||||||||||||||
| 170 | } executed 121 times by 2 tests: end of blockExecuted by:
| 121 | ||||||||||||||||||
| 171 | - | |||||||||||||||||||
| 172 | q_BIO_free(bio); | - | ||||||||||||||||||
| 173 | } executed 659 times by 4 tests: end of blockExecuted by:
| 659 | ||||||||||||||||||
| 174 | - | |||||||||||||||||||
| 175 | int QSslKeyPrivate::length() const | - | ||||||||||||||||||
| 176 | { | - | ||||||||||||||||||
| 177 | if (isNull || algorithm == QSsl::Opaque)
| 0-744 | ||||||||||||||||||
| 178 | return -1; executed 1 time by 1 test: return -1;Executed by:
| 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:
executed 376 times by 2 tests: case QSsl::Rsa:Executed by:
| 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:
executed 210 times by 2 tests: case QSsl::Dsa:Executed by:
| 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:
executed 158 times by 2 tests: case QSsl::Ec:Executed by:
| 158 | ||||||||||||||||||
| 185 | #endif | - | ||||||||||||||||||
| 186 | default: return -1; never executed: return -1;never executed: default: | 0 | ||||||||||||||||||
| 187 | } | - | ||||||||||||||||||
| 188 | } | - | ||||||||||||||||||
| 189 | - | |||||||||||||||||||
| 190 | QByteArray QSslKeyPrivate::toPem(const QByteArray &passPhrase) const | - | ||||||||||||||||||
| 191 | { | - | ||||||||||||||||||
| 192 | if (!QSslSocket::supportsSsl() || isNull || algorithm == QSsl::Opaque)
| 0-1752 | ||||||||||||||||||
| 193 | return QByteArray(); never executed: return QByteArray(); | 0 | ||||||||||||||||||
| 194 | - | |||||||||||||||||||
| 195 | BIO *bio = q_BIO_new(q_BIO_s_mem()); | - | ||||||||||||||||||
| 196 | if (!bio)
| 0-1752 | ||||||||||||||||||
| 197 | return QByteArray(); never executed: return QByteArray(); | 0 | ||||||||||||||||||
| 198 | - | |||||||||||||||||||
| 199 | bool fail = false; | - | ||||||||||||||||||
| 200 | - | |||||||||||||||||||
| 201 | if (algorithm == QSsl::Rsa) {
| 872-880 | ||||||||||||||||||
| 202 | if (type == QSsl::PublicKey) {
| 416-464 | ||||||||||||||||||
| 203 | if (!q_PEM_write_bio_RSA_PUBKEY(bio, rsa))
| 0-416 | ||||||||||||||||||
| 204 | fail = true; never executed: fail = true; | 0 | ||||||||||||||||||
| 205 | } else { executed 416 times by 2 tests: end of blockExecuted by:
| 416 | ||||||||||||||||||
| 206 | if (!q_PEM_write_bio_RSAPrivateKey(
| 0-464 | ||||||||||||||||||
| 207 | bio, rsa,
| 0-464 | ||||||||||||||||||
| 208 | // ### the cipher should be selectable in the API:
| 0-464 | ||||||||||||||||||
| 209 | passPhrase.isEmpty() ? (const EVP_CIPHER *)0 : q_EVP_des_ede3_cbc(),
| 0-464 | ||||||||||||||||||
| 210 | const_cast<uchar *>((const uchar *)passPhrase.data()), passPhrase.size(), 0, 0)) {
| 0-464 | ||||||||||||||||||
| 211 | fail = true; | - | ||||||||||||||||||
| 212 | } never executed: end of block | 0 | ||||||||||||||||||
| 213 | } executed 464 times by 2 tests: end of blockExecuted by:
| 464 | ||||||||||||||||||
| 214 | } else if (algorithm == QSsl::Dsa) {
| 374-498 | ||||||||||||||||||
| 215 | if (type == QSsl::PublicKey) {
| 234-264 | ||||||||||||||||||
| 216 | if (!q_PEM_write_bio_DSA_PUBKEY(bio, dsa))
| 0-234 | ||||||||||||||||||
| 217 | fail = true; never executed: fail = true; | 0 | ||||||||||||||||||
| 218 | } else { executed 234 times by 2 tests: end of blockExecuted by:
| 234 | ||||||||||||||||||
| 219 | if (!q_PEM_write_bio_DSAPrivateKey(
| 0-264 | ||||||||||||||||||
| 220 | bio, dsa,
| 0-264 | ||||||||||||||||||
| 221 | // ### the cipher should be selectable in the API:
| 0-264 | ||||||||||||||||||
| 222 | passPhrase.isEmpty() ? (const EVP_CIPHER *)0 : q_EVP_des_ede3_cbc(),
| 0-264 | ||||||||||||||||||
| 223 | const_cast<uchar *>((const uchar *)passPhrase.data()), passPhrase.size(), 0, 0)) {
| 0-264 | ||||||||||||||||||
| 224 | fail = true; | - | ||||||||||||||||||
| 225 | } never executed: end of block | 0 | ||||||||||||||||||
| 226 | } executed 264 times by 1 test: end of blockExecuted by:
| 264 | ||||||||||||||||||
| 227 | #ifndef OPENSSL_NO_EC | - | ||||||||||||||||||
| 228 | } else if (algorithm == QSsl::Ec) {
| 0-374 | ||||||||||||||||||
| 229 | if (type == QSsl::PublicKey) {
| 176-198 | ||||||||||||||||||
| 230 | if (!q_PEM_write_bio_EC_PUBKEY(bio, ec))
| 0-176 | ||||||||||||||||||
| 231 | fail = true; never executed: fail = true; | 0 | ||||||||||||||||||
| 232 | } else { executed 176 times by 2 tests: end of blockExecuted by:
| 176 | ||||||||||||||||||
| 233 | if (!q_PEM_write_bio_ECPrivateKey(
| 0-198 | ||||||||||||||||||
| 234 | bio, ec,
| 0-198 | ||||||||||||||||||
| 235 | // ### the cipher should be selectable in the API:
| 0-198 | ||||||||||||||||||
| 236 | passPhrase.isEmpty() ? (const EVP_CIPHER *)0 : q_EVP_des_ede3_cbc(),
| 0-198 | ||||||||||||||||||
| 237 | const_cast<uchar *>((const uchar *)passPhrase.data()), passPhrase.size(), 0, 0)) {
| 0-198 | ||||||||||||||||||
| 238 | fail = true; | - | ||||||||||||||||||
| 239 | } never executed: end of block | 0 | ||||||||||||||||||
| 240 | } executed 198 times by 1 test: end of blockExecuted by:
| 198 | ||||||||||||||||||
| 241 | #endif | - | ||||||||||||||||||
| 242 | } else { | - | ||||||||||||||||||
| 243 | fail = true; | - | ||||||||||||||||||
| 244 | } never executed: end of block | 0 | ||||||||||||||||||
| 245 | - | |||||||||||||||||||
| 246 | QByteArray pem; | - | ||||||||||||||||||
| 247 | if (!fail) {
| 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 blockExecuted by:
| 1752 | ||||||||||||||||||
| 252 | q_BIO_free(bio); | - | ||||||||||||||||||
| 253 | return pem; executed 1752 times by 2 tests: return pem;Executed by:
| 1752 | ||||||||||||||||||
| 254 | } | - | ||||||||||||||||||
| 255 | - | |||||||||||||||||||
| 256 | Qt::HANDLE QSslKeyPrivate::handle() const | - | ||||||||||||||||||
| 257 | { | - | ||||||||||||||||||
| 258 | switch (algorithm) { | - | ||||||||||||||||||
| 259 | case QSsl::Opaque: executed 4 times by 1 test: case QSsl::Opaque:Executed by:
| 4 | ||||||||||||||||||
| 260 | return Qt::HANDLE(opaque); executed 4 times by 1 test: return Qt::HANDLE(opaque);Executed by:
| 4 | ||||||||||||||||||
| 261 | case QSsl::Rsa: executed 89 times by 2 tests: case QSsl::Rsa:Executed by:
| 89 | ||||||||||||||||||
| 262 | return Qt::HANDLE(rsa); executed 89 times by 2 tests: return Qt::HANDLE(rsa);Executed by:
| 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 | - | |||||||||||||||||||
| 274 | static 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:
| 18 | ||||||||||||||||||
| 282 | type = q_EVP_des_cbc(); | - | ||||||||||||||||||
| 283 | break; executed 18 times by 1 test: break;Executed by:
| 18 | ||||||||||||||||||
| 284 | case QSslKeyPrivate::DesEde3Cbc: executed 4 times by 1 test: case QSslKeyPrivate::DesEde3Cbc:Executed by:
| 4 | ||||||||||||||||||
| 285 | type = q_EVP_des_ede3_cbc(); | - | ||||||||||||||||||
| 286 | break; executed 4 times by 1 test: break;Executed by:
| 4 | ||||||||||||||||||
| 287 | case QSslKeyPrivate::Rc2Cbc: executed 12 times by 1 test: case QSslKeyPrivate::Rc2Cbc:Executed by:
| 12 | ||||||||||||||||||
| 288 | type = q_EVP_rc2_cbc(); | - | ||||||||||||||||||
| 289 | break; executed 12 times by 1 test: break;Executed by:
| 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)
| 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:
| 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:
| 34 | ||||||||||||||||||
| 311 | } | - | ||||||||||||||||||
| 312 | - | |||||||||||||||||||
| 313 | QByteArray 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:
| 17 | ||||||||||||||||||
| 316 | } | - | ||||||||||||||||||
| 317 | - | |||||||||||||||||||
| 318 | QByteArray 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:
| 17 | ||||||||||||||||||
| 321 | } | - | ||||||||||||||||||
| 322 | - | |||||||||||||||||||
| 323 | QT_END_NAMESPACE | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |