| 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) 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 | - | |||||||||||||||||||
| 48 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 49 | - | |||||||||||||||||||
| 50 | void QSslKeyPrivate::clear(bool deep) | - | ||||||||||||||||||
| 51 | { | - | ||||||||||||||||||
| 52 | isNull = true; | - | ||||||||||||||||||
| 53 | if (!QSslSocket::supportsSsl())
| 0-15246 | ||||||||||||||||||
| 54 | return; never executed: return; | 0 | ||||||||||||||||||
| 55 | if (algorithm == QSsl::Rsa && rsa) {
| 372-14490 | ||||||||||||||||||
| 56 | if (deep)
| 0-372 | ||||||||||||||||||
| 57 | q_RSA_free(rsa); executed 372 times by 4 tests: q_RSA_free(rsa);Executed by:
| 372 | ||||||||||||||||||
| 58 | rsa = 0; | - | ||||||||||||||||||
| 59 | } executed 372 times by 4 tests: end of blockExecuted by:
| 372 | ||||||||||||||||||
| 60 | if (algorithm == QSsl::Dsa && dsa) {
| 161-14923 | ||||||||||||||||||
| 61 | if (deep)
| 0-162 | ||||||||||||||||||
| 62 | q_DSA_free(dsa); executed 162 times by 2 tests: q_DSA_free(dsa);Executed by:
| 162 | ||||||||||||||||||
| 63 | dsa = 0; | - | ||||||||||||||||||
| 64 | } executed 162 times by 2 tests: end of blockExecuted by:
| 162 | ||||||||||||||||||
| 65 | #ifndef OPENSSL_NO_EC | - | ||||||||||||||||||
| 66 | if (algorithm == QSsl::Ec && ec) {
| 121-15003 | ||||||||||||||||||
| 67 | if (deep)
| 0-122 | ||||||||||||||||||
| 68 | q_EC_KEY_free(ec); executed 122 times by 2 tests: q_EC_KEY_free(ec);Executed by:
| 122 | ||||||||||||||||||
| 69 | ec = 0; | - | ||||||||||||||||||
| 70 | } executed 122 times by 2 tests: end of blockExecuted by:
| 122 | ||||||||||||||||||
| 71 | #endif | - | ||||||||||||||||||
| 72 | if (algorithm == QSsl::Opaque && opaque) {
| 5-13924 | ||||||||||||||||||
| 73 | if (deep)
| 0-5 | ||||||||||||||||||
| 74 | q_EVP_PKEY_free(opaque); executed 5 times by 1 test: q_EVP_PKEY_free(opaque);Executed by:
| 5 | ||||||||||||||||||
| 75 | opaque = 0; | - | ||||||||||||||||||
| 76 | } executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||||||||
| 77 | } executed 15246 times by 26 tests: end of blockExecuted by:
| 15246 | ||||||||||||||||||
| 78 | - | |||||||||||||||||||
| 79 | bool QSslKeyPrivate::fromEVP_PKEY(EVP_PKEY *pkey) | - | ||||||||||||||||||
| 80 | { | - | ||||||||||||||||||
| 81 | if (pkey->type == EVP_PKEY_RSA) {
| 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:
| 1 | ||||||||||||||||||
| 90 | } | - | ||||||||||||||||||
| 91 | else if (pkey->type == EVP_PKEY_DSA) {
| 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) {
| 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 | - | |||||||||||||||||||
| 121 | void 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 blockExecuted by:
| 226 | ||||||||||||||||||
| 126 | - | |||||||||||||||||||
| 127 | void QSslKeyPrivate::decodePem(const QByteArray &pem, const QByteArray &passPhrase, | - | ||||||||||||||||||
| 128 | bool deepClear) | - | ||||||||||||||||||
| 129 | { | - | ||||||||||||||||||
| 130 | if (pem.isEmpty())
| 0-657 | ||||||||||||||||||
| 131 | return; never executed: return; | 0 | ||||||||||||||||||
| 132 | - | |||||||||||||||||||
| 133 | clear(deepClear); | - | ||||||||||||||||||
| 134 | - | |||||||||||||||||||
| 135 | if (!QSslSocket::supportsSsl())
| 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)
| 0-657 | ||||||||||||||||||
| 140 | return; never executed: return; | 0 | ||||||||||||||||||
| 141 | - | |||||||||||||||||||
| 142 | void *phrase = const_cast<char *>(passPhrase.constData()); | - | ||||||||||||||||||
| 143 | - | |||||||||||||||||||
| 144 | if (algorithm == QSsl::Rsa) {
| 282-375 | ||||||||||||||||||
| 145 | RSA *result = (type == QSsl::PublicKey)
| 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)
| 0-366 | ||||||||||||||||||
| 149 | isNull = false; executed 366 times by 4 tests: isNull = false;Executed by:
| 366 | ||||||||||||||||||
| 150 | } else if (algorithm == QSsl::Dsa) { executed 375 times by 4 tests: end of blockExecuted by:
| 121-375 | ||||||||||||||||||
| 151 | DSA *result = (type == QSsl::PublicKey)
| 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)
| 0-161 | ||||||||||||||||||
| 155 | isNull = false; executed 161 times by 2 tests: isNull = false;Executed by:
| 161 | ||||||||||||||||||
| 156 | #ifndef OPENSSL_NO_EC | - | ||||||||||||||||||
| 157 | } else if (algorithm == QSsl::Ec) { executed 161 times by 2 tests: end of blockExecuted by:
| 0-161 | ||||||||||||||||||
| 158 | EC_KEY *result = (type == QSsl::PublicKey)
| 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)
| 0-121 | ||||||||||||||||||
| 162 | isNull = false; executed 121 times by 2 tests: isNull = false;Executed by:
| 121 | ||||||||||||||||||
| 163 | #endif | - | ||||||||||||||||||
| 164 | } executed 121 times by 2 tests: end of blockExecuted by:
| 121 | ||||||||||||||||||
| 165 | - | |||||||||||||||||||
| 166 | q_BIO_free(bio); | - | ||||||||||||||||||
| 167 | } executed 657 times by 4 tests: end of blockExecuted by:
| 657 | ||||||||||||||||||
| 168 | - | |||||||||||||||||||
| 169 | int QSslKeyPrivate::length() const | - | ||||||||||||||||||
| 170 | { | - | ||||||||||||||||||
| 171 | if (isNull || algorithm == QSsl::Opaque)
| 0-744 | ||||||||||||||||||
| 172 | return -1; executed 1 time by 1 test: return -1;Executed by:
| 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:
executed 376 times by 2 tests: case QSsl::Rsa:Executed by:
| 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:
executed 210 times by 2 tests: case QSsl::Dsa:Executed by:
| 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:
executed 158 times by 2 tests: case QSsl::Ec:Executed by:
| 158 | ||||||||||||||||||
| 179 | #endif | - | ||||||||||||||||||
| 180 | default: return -1; never executed: return -1;never executed: default: | 0 | ||||||||||||||||||
| 181 | } | - | ||||||||||||||||||
| 182 | } | - | ||||||||||||||||||
| 183 | - | |||||||||||||||||||
| 184 | QByteArray QSslKeyPrivate::toPem(const QByteArray &passPhrase) const | - | ||||||||||||||||||
| 185 | { | - | ||||||||||||||||||
| 186 | if (!QSslSocket::supportsSsl() || isNull || algorithm == QSsl::Opaque)
| 0-1752 | ||||||||||||||||||
| 187 | return QByteArray(); never executed: return QByteArray(); | 0 | ||||||||||||||||||
| 188 | - | |||||||||||||||||||
| 189 | BIO *bio = q_BIO_new(q_BIO_s_mem()); | - | ||||||||||||||||||
| 190 | if (!bio)
| 0-1752 | ||||||||||||||||||
| 191 | return QByteArray(); never executed: return QByteArray(); | 0 | ||||||||||||||||||
| 192 | - | |||||||||||||||||||
| 193 | bool fail = false; | - | ||||||||||||||||||
| 194 | - | |||||||||||||||||||
| 195 | if (algorithm == QSsl::Rsa) {
| 872-880 | ||||||||||||||||||
| 196 | if (type == QSsl::PublicKey) {
| 416-464 | ||||||||||||||||||
| 197 | if (!q_PEM_write_bio_RSA_PUBKEY(bio, rsa))
| 0-416 | ||||||||||||||||||
| 198 | fail = true; never executed: fail = true; | 0 | ||||||||||||||||||
| 199 | } else { executed 416 times by 2 tests: end of blockExecuted by:
| 416 | ||||||||||||||||||
| 200 | if (!q_PEM_write_bio_RSAPrivateKey(
| 0-464 | ||||||||||||||||||
| 201 | bio, rsa,
| 0-464 | ||||||||||||||||||
| 202 | // ### the cipher should be selectable in the API:
| 0-464 | ||||||||||||||||||
| 203 | passPhrase.isEmpty() ? (const EVP_CIPHER *)0 : q_EVP_des_ede3_cbc(),
| 0-464 | ||||||||||||||||||
| 204 | const_cast<uchar *>((const uchar *)passPhrase.data()), passPhrase.size(), 0, 0)) {
| 0-464 | ||||||||||||||||||
| 205 | fail = true; | - | ||||||||||||||||||
| 206 | } never executed: end of block | 0 | ||||||||||||||||||
| 207 | } executed 464 times by 2 tests: end of blockExecuted by:
| 464 | ||||||||||||||||||
| 208 | } else if (algorithm == QSsl::Dsa) {
| 374-498 | ||||||||||||||||||
| 209 | if (type == QSsl::PublicKey) {
| 234-264 | ||||||||||||||||||
| 210 | if (!q_PEM_write_bio_DSA_PUBKEY(bio, dsa))
| 0-234 | ||||||||||||||||||
| 211 | fail = true; never executed: fail = true; | 0 | ||||||||||||||||||
| 212 | } else { executed 234 times by 2 tests: end of blockExecuted by:
| 234 | ||||||||||||||||||
| 213 | if (!q_PEM_write_bio_DSAPrivateKey(
| 0-264 | ||||||||||||||||||
| 214 | bio, dsa,
| 0-264 | ||||||||||||||||||
| 215 | // ### the cipher should be selectable in the API:
| 0-264 | ||||||||||||||||||
| 216 | passPhrase.isEmpty() ? (const EVP_CIPHER *)0 : q_EVP_des_ede3_cbc(),
| 0-264 | ||||||||||||||||||
| 217 | const_cast<uchar *>((const uchar *)passPhrase.data()), passPhrase.size(), 0, 0)) {
| 0-264 | ||||||||||||||||||
| 218 | fail = true; | - | ||||||||||||||||||
| 219 | } never executed: end of block | 0 | ||||||||||||||||||
| 220 | } executed 264 times by 1 test: end of blockExecuted by:
| 264 | ||||||||||||||||||
| 221 | #ifndef OPENSSL_NO_EC | - | ||||||||||||||||||
| 222 | } else if (algorithm == QSsl::Ec) {
| 0-374 | ||||||||||||||||||
| 223 | if (type == QSsl::PublicKey) {
| 176-198 | ||||||||||||||||||
| 224 | if (!q_PEM_write_bio_EC_PUBKEY(bio, ec))
| 0-176 | ||||||||||||||||||
| 225 | fail = true; never executed: fail = true; | 0 | ||||||||||||||||||
| 226 | } else { executed 176 times by 2 tests: end of blockExecuted by:
| 176 | ||||||||||||||||||
| 227 | if (!q_PEM_write_bio_ECPrivateKey(
| 0-198 | ||||||||||||||||||
| 228 | bio, ec,
| 0-198 | ||||||||||||||||||
| 229 | // ### the cipher should be selectable in the API:
| 0-198 | ||||||||||||||||||
| 230 | passPhrase.isEmpty() ? (const EVP_CIPHER *)0 : q_EVP_des_ede3_cbc(),
| 0-198 | ||||||||||||||||||
| 231 | const_cast<uchar *>((const uchar *)passPhrase.data()), passPhrase.size(), 0, 0)) {
| 0-198 | ||||||||||||||||||
| 232 | fail = true; | - | ||||||||||||||||||
| 233 | } never executed: end of block | 0 | ||||||||||||||||||
| 234 | } executed 198 times by 1 test: end of blockExecuted by:
| 198 | ||||||||||||||||||
| 235 | #endif | - | ||||||||||||||||||
| 236 | } else { | - | ||||||||||||||||||
| 237 | fail = true; | - | ||||||||||||||||||
| 238 | } never executed: end of block | 0 | ||||||||||||||||||
| 239 | - | |||||||||||||||||||
| 240 | QByteArray pem; | - | ||||||||||||||||||
| 241 | if (!fail) {
| 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 blockExecuted by:
| 1752 | ||||||||||||||||||
| 246 | q_BIO_free(bio); | - | ||||||||||||||||||
| 247 | return pem; executed 1752 times by 2 tests: return pem;Executed by:
| 1752 | ||||||||||||||||||
| 248 | } | - | ||||||||||||||||||
| 249 | - | |||||||||||||||||||
| 250 | Qt::HANDLE QSslKeyPrivate::handle() const | - | ||||||||||||||||||
| 251 | { | - | ||||||||||||||||||
| 252 | switch (algorithm) { | - | ||||||||||||||||||
| 253 | case QSsl::Opaque: executed 4 times by 1 test: case QSsl::Opaque:Executed by:
| 4 | ||||||||||||||||||
| 254 | return Qt::HANDLE(opaque); executed 4 times by 1 test: return Qt::HANDLE(opaque);Executed by:
| 4 | ||||||||||||||||||
| 255 | case QSsl::Rsa: executed 87 times by 2 tests: case QSsl::Rsa:Executed by:
| 87 | ||||||||||||||||||
| 256 | return Qt::HANDLE(rsa); executed 87 times by 2 tests: return Qt::HANDLE(rsa);Executed by:
| 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 | - | |||||||||||||||||||
| 268 | static 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:
| 18 | ||||||||||||||||||
| 276 | type = q_EVP_des_cbc(); | - | ||||||||||||||||||
| 277 | break; executed 18 times by 1 test: break;Executed by:
| 18 | ||||||||||||||||||
| 278 | case QSslKeyPrivate::DesEde3Cbc: executed 4 times by 1 test: case QSslKeyPrivate::DesEde3Cbc:Executed by:
| 4 | ||||||||||||||||||
| 279 | type = q_EVP_des_ede3_cbc(); | - | ||||||||||||||||||
| 280 | break; executed 4 times by 1 test: break;Executed by:
| 4 | ||||||||||||||||||
| 281 | case QSslKeyPrivate::Rc2Cbc: executed 12 times by 1 test: case QSslKeyPrivate::Rc2Cbc:Executed by:
| 12 | ||||||||||||||||||
| 282 | type = q_EVP_rc2_cbc(); | - | ||||||||||||||||||
| 283 | break; executed 12 times by 1 test: break;Executed by:
| 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)
| 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:
| 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:
| 34 | ||||||||||||||||||
| 305 | } | - | ||||||||||||||||||
| 306 | - | |||||||||||||||||||
| 307 | QByteArray 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:
| 17 | ||||||||||||||||||
| 310 | } | - | ||||||||||||||||||
| 311 | - | |||||||||||||||||||
| 312 | QByteArray 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:
| 17 | ||||||||||||||||||
| 315 | } | - | ||||||||||||||||||
| 316 | - | |||||||||||||||||||
| 317 | QT_END_NAMESPACE | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |