ssl/qsslkey.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5 -
6 -
7 -
8 -
9 -
10 -
11 -
12void QSslKeyPrivate::clear(bool deep) -
13{ -
14 isNull = true; -
15 if (!QSslSocket::supportsSsl())
partially evaluated: !QSslSocket::supportsSsl()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:10894
0-10894
16 return;
never executed: return;
0
17 if (rsa) {
evaluated: rsa
TRUEFALSE
yes
Evaluation Count:297
yes
Evaluation Count:10597
297-10597
18 if (deep)
partially evaluated: deep
TRUEFALSE
yes
Evaluation Count:297
no
Evaluation Count:0
0-297
19 q_RSA_free(rsa);
executed: q_RSA_free(rsa);
Execution Count:297
297
20 rsa = 0; -
21 }
executed: }
Execution Count:297
297
22 if (dsa) {
evaluated: dsa
TRUEFALSE
yes
Evaluation Count:160
yes
Evaluation Count:10734
160-10734
23 if (deep)
partially evaluated: deep
TRUEFALSE
yes
Evaluation Count:160
no
Evaluation Count:0
0-160
24 q_DSA_free(dsa);
executed: q_DSA_free(dsa);
Execution Count:160
160
25 dsa = 0; -
26 }
executed: }
Execution Count:160
160
27 if (opaque) {
partially evaluated: opaque
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:10894
0-10894
28 if (deep)
never evaluated: deep
0
29 q_EVP_PKEY_free(opaque);
never executed: q_EVP_PKEY_free(opaque);
0
30 opaque = 0; -
31 }
never executed: }
0
32}
executed: }
Execution Count:10894
10894
33void QSslKeyPrivate::decodePem(const QByteArray &pem, const QByteArray &passPhrase, -
34 bool deepClear) -
35{ -
36 if (pem.isEmpty())
partially evaluated: pem.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:542
0-542
37 return;
never executed: return;
0
38 -
39 clear(deepClear); -
40 -
41 if (!QSslSocket::supportsSsl())
partially evaluated: !QSslSocket::supportsSsl()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:542
0-542
42 return;
never executed: return;
0
43 -
44 BIO *bio = q_BIO_new_mem_buf(const_cast<char *>(pem.data()), pem.size()); -
45 if (!bio)
partially evaluated: !bio
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:542
0-542
46 return;
never executed: return;
0
47 -
48 void *phrase = (void *)passPhrase.constData(); -
49 -
50 if (algorithm == QSsl::Rsa) {
evaluated: algorithm == QSsl::Rsa
TRUEFALSE
yes
Evaluation Count:350
yes
Evaluation Count:192
192-350
51 RSA *result = (type == QSsl::PublicKey)
evaluated: (type == QSsl::PublicKey)
TRUEFALSE
yes
Evaluation Count:116
yes
Evaluation Count:234
116-234
52 ? q_PEM_read_bio_RSA_PUBKEY(bio, &rsa, 0, phrase) -
53 : q_PEM_read_bio_RSAPrivateKey(bio, &rsa, 0, phrase); -
54 if (rsa && rsa == result)
evaluated: rsa
TRUEFALSE
yes
Evaluation Count:291
yes
Evaluation Count:59
partially evaluated: rsa == result
TRUEFALSE
yes
Evaluation Count:291
no
Evaluation Count:0
0-291
55 isNull = false;
executed: isNull = false;
Execution Count:291
291
56 } else {
executed: }
Execution Count:350
350
57 DSA *result = (type == QSsl::PublicKey)
evaluated: (type == QSsl::PublicKey)
TRUEFALSE
yes
Evaluation Count:64
yes
Evaluation Count:128
64-128
58 ? q_PEM_read_bio_DSA_PUBKEY(bio, &dsa, 0, phrase) -
59 : q_PEM_read_bio_DSAPrivateKey(bio, &dsa, 0, phrase); -
60 if (dsa && dsa == result)
evaluated: dsa
TRUEFALSE
yes
Evaluation Count:160
yes
Evaluation Count:32
partially evaluated: dsa == result
TRUEFALSE
yes
Evaluation Count:160
no
Evaluation Count:0
0-160
61 isNull = false;
executed: isNull = false;
Execution Count:160
160
62 }
executed: }
Execution Count:192
192
63 -
64 q_BIO_free(bio); -
65}
executed: }
Execution Count:542
542
66 -
67 -
68 -
69 -
70 -
71 -
72QSslKey::QSslKey() -
73 : d(new QSslKeyPrivate) -
74{ -
75}
executed: }
Execution Count:4634
4634
76 -
77 -
78 -
79 -
80QByteArray QSslKeyPrivate::pemHeader() const -
81{ -
82 -
83 if (type == QSsl::PublicKey)
evaluated: type == QSsl::PublicKey
TRUEFALSE
yes
Evaluation Count:463
yes
Evaluation Count:627
463-627
84 return QByteArray("-----BEGIN PUBLIC KEY-----\n");
executed: return QByteArray("-----BEGIN PUBLIC KEY-----\n");
Execution Count:463
463
85 else if (algorithm == QSsl::Rsa)
evaluated: algorithm == QSsl::Rsa
TRUEFALSE
yes
Evaluation Count:399
yes
Evaluation Count:228
228-399
86 return QByteArray("-----BEGIN RSA PRIVATE KEY-----\n");
executed: return QByteArray("-----BEGIN RSA PRIVATE KEY-----\n");
Execution Count:399
399
87 return QByteArray("-----BEGIN DSA PRIVATE KEY-----\n");
executed: return QByteArray("-----BEGIN DSA PRIVATE KEY-----\n");
Execution Count:228
228
88} -
89 -
90 -
91 -
92 -
93QByteArray QSslKeyPrivate::pemFooter() const -
94{ -
95 -
96 if (type == QSsl::PublicKey)
evaluated: type == QSsl::PublicKey
TRUEFALSE
yes
Evaluation Count:463
yes
Evaluation Count:627
463-627
97 return QByteArray("-----END PUBLIC KEY-----\n");
executed: return QByteArray("-----END PUBLIC KEY-----\n");
Execution Count:463
463
98 else if (algorithm == QSsl::Rsa)
evaluated: algorithm == QSsl::Rsa
TRUEFALSE
yes
Evaluation Count:399
yes
Evaluation Count:228
228-399
99 return QByteArray("-----END RSA PRIVATE KEY-----\n");
executed: return QByteArray("-----END RSA PRIVATE KEY-----\n");
Execution Count:399
399
100 return QByteArray("-----END DSA PRIVATE KEY-----\n");
executed: return QByteArray("-----END DSA PRIVATE KEY-----\n");
Execution Count:228
228
101} -
102 -
103 -
104 -
105 -
106 -
107 -
108QByteArray QSslKeyPrivate::pemFromDer(const QByteArray &der) const -
109{ -
110 QByteArray pem(der.toBase64()); -
111 -
112 const int lineWidth = 64; -
113 const int newLines = pem.size() / lineWidth; -
114 const bool rem = pem.size() % lineWidth; -
115 -
116 -
117 for (int i = 0; i < newLines; ++i)
evaluated: i < newLines
TRUEFALSE
yes
Evaluation Count:2054
yes
Evaluation Count:266
266-2054
118 pem.insert((i + 1) * lineWidth + i, '\n');
executed: pem.insert((i + 1) * lineWidth + i, '\n');
Execution Count:2054
2054
119 if (rem)
evaluated: rem
TRUEFALSE
yes
Evaluation Count:250
yes
Evaluation Count:16
16-250
120 pem.append('\n');
executed: pem.append('\n');
Execution Count:250
250
121 -
122 pem.prepend(pemHeader()); -
123 pem.append(pemFooter()); -
124 -
125 return pem;
executed: return pem;
Execution Count:266
266
126} -
127 -
128 -
129 -
130 -
131 -
132 -
133QByteArray QSslKeyPrivate::derFromPem(const QByteArray &pem) const -
134{ -
135 const QByteArray header = pemHeader(); -
136 const QByteArray footer = pemFooter(); -
137 -
138 QByteArray der(pem); -
139 -
140 const int headerIndex = der.indexOf(header); -
141 const int footerIndex = der.indexOf(footer); -
142 if (headerIndex == -1 || footerIndex == -1)
partially evaluated: headerIndex == -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:824
partially evaluated: footerIndex == -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:824
0-824
143 return QByteArray();
never executed: return QByteArray();
0
144 -
145 der = der.mid(headerIndex + header.size(), footerIndex - (headerIndex + header.size())); -
146 -
147 return QByteArray::fromBase64(der);
executed: return QByteArray::fromBase64(der);
Execution Count:824
824
148} -
149QSslKey::QSslKey(const QByteArray &encoded, QSsl::KeyAlgorithm algorithm, -
150 QSsl::EncodingFormat encoding, QSsl::KeyType type, const QByteArray &passPhrase) -
151 : d(new QSslKeyPrivate) -
152{ -
153 d->type = type; -
154 d->algorithm = algorithm; -
155 d->decodePem((encoding == QSsl::Der) -
156 ? d->pemFromDer(encoded) : encoded, -
157 passPhrase); -
158}
executed: }
Execution Count:535
535
159QSslKey::QSslKey(QIODevice *device, QSsl::KeyAlgorithm algorithm, QSsl::EncodingFormat encoding, -
160 QSsl::KeyType type, const QByteArray &passPhrase) -
161 : d(new QSslKeyPrivate) -
162{ -
163 QByteArray encoded; -
164 if (device)
partially evaluated: device
TRUEFALSE
yes
Evaluation Count:7
no
Evaluation Count:0
0-7
165 encoded = device->readAll();
executed: encoded = device->readAll();
Execution Count:7
7
166 d->type = type; -
167 d->algorithm = algorithm; -
168 d->decodePem((encoding == QSsl::Der) ? -
169 d->pemFromDer(encoded) : encoded, -
170 passPhrase); -
171}
executed: }
Execution Count:7
7
172QSslKey::QSslKey(Qt::HANDLE handle, QSsl::KeyType type) -
173 : d(new QSslKeyPrivate) -
174{ -
175 d->opaque = reinterpret_cast<EVP_PKEY *>(handle); -
176 d->algorithm = QSsl::Opaque; -
177 d->type = type; -
178 d->isNull = !d->opaque; -
179}
never executed: }
0
180 -
181 -
182 -
183 -
184QSslKey::QSslKey(const QSslKey &other) : d(other.d) -
185{ -
186}
executed: }
Execution Count:297
297
187 -
188 -
189 -
190 -
191QSslKey::~QSslKey() -
192{ -
193} -
194 -
195 -
196 -
197 -
198 -
199 -
200 -
201QSslKey &QSslKey::operator=(const QSslKey &other) -
202{ -
203 d = other.d; -
204 return *this;
executed: return *this;
Execution Count:147
147
205} -
206bool QSslKey::isNull() const -
207{ -
208 return d->isNull;
executed: return d->isNull;
Execution Count:979
979
209} -
210 -
211 -
212 -
213 -
214 -
215 -
216void QSslKey::clear() -
217{ -
218 d = new QSslKeyPrivate; -
219}
never executed: }
0
220 -
221 -
222 -
223 -
224int QSslKey::length() const -
225{ -
226 if (d->isNull || d->algorithm == QSsl::Opaque)
evaluated: d->isNull
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:582
partially evaluated: d->algorithm == QSsl::Opaque
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:582
0-582
227 return -1;
executed: return -1;
Execution Count:1
1
228 -
229 return (d->algorithm == QSsl::Rsa) 582
230 ? q_BN_num_bits(d->rsa->n) : q_BN_num_bits(d->dsa->p);
executed: return (d->algorithm == QSsl::Rsa) ? q_BN_num_bits(d->rsa->n) : q_BN_num_bits(d->dsa->p);
Execution Count:582
582
231} -
232 -
233 -
234 -
235 -
236QSsl::KeyType QSslKey::type() const -
237{ -
238 return d->type;
executed: return d->type;
Execution Count:538
538
239} -
240 -
241 -
242 -
243 -
244QSsl::KeyAlgorithm QSslKey::algorithm() const -
245{ -
246 return d->algorithm;
executed: return d->algorithm;
Execution Count:728
728
247} -
248 -
249 -
250 -
251 -
252 -
253 -
254 -
255QByteArray QSslKey::toDer(const QByteArray &passPhrase) const -
256{ -
257 if (d->isNull || d->algorithm == QSsl::Opaque)
partially evaluated: d->isNull
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:824
partially evaluated: d->algorithm == QSsl::Opaque
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:824
0-824
258 return QByteArray();
never executed: return QByteArray();
0
259 -
260 return d->derFromPem(toPem(passPhrase));
executed: return d->derFromPem(toPem(passPhrase));
Execution Count:824
824
261} -
262 -
263 -
264 -
265 -
266 -
267 -
268QByteArray QSslKey::toPem(const QByteArray &passPhrase) const -
269{ -
270 if (!QSslSocket::supportsSsl() || d->isNull || d->algorithm == QSsl::Opaque)
partially evaluated: !QSslSocket::supportsSsl()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1638
evaluated: d->isNull
TRUEFALSE
yes
Evaluation Count:88
yes
Evaluation Count:1550
partially evaluated: d->algorithm == QSsl::Opaque
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1550
0-1638
271 return QByteArray();
executed: return QByteArray();
Execution Count:88
88
272 -
273 BIO *bio = q_BIO_new(q_BIO_s_mem()); -
274 if (!bio)
partially evaluated: !bio
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1550
0-1550
275 return QByteArray();
never executed: return QByteArray();
0
276 -
277 bool fail = false; -
278 -
279 if (d->algorithm == QSsl::Rsa) {
evaluated: d->algorithm == QSsl::Rsa
TRUEFALSE
yes
Evaluation Count:990
yes
Evaluation Count:560
560-990
280 if (d->type == QSsl::PublicKey) {
evaluated: d->type == QSsl::PublicKey
TRUEFALSE
yes
Evaluation Count:416
yes
Evaluation Count:574
416-574
281 if (!q_PEM_write_bio_RSA_PUBKEY(bio, d->rsa))
partially evaluated: !q_PEM_write_bio_RSA_PUBKEY(bio, d->rsa)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:416
0-416
282 fail = true;
never executed: fail = true;
0
283 } else {
executed: }
Execution Count:416
416
284 if (!q_PEM_write_bio_RSAPrivateKey( 0-574
285 bio, d->rsa, 0-574
286 0-574
287 passPhrase.isEmpty() ? (const EVP_CIPHER *)0 : q_EVP_des_ede3_cbc(), 0-574
288 (uchar *)passPhrase.data(), passPhrase.size(), 0, 0)) {
partially evaluated: !q_PEM_write_bio_RSAPrivateKey( bio, d->rsa, passPhrase.isEmpty() ? (const EVP_CIPHER *)0 : q_EVP_des_ede3_cbc(), (uchar *)passPhrase.data(), passPhrase.size(), 0, 0)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:574
0-574
289 fail = true; -
290 }
never executed: }
0
291 }
executed: }
Execution Count:574
574
292 } else { -
293 if (d->type == QSsl::PublicKey) {
evaluated: d->type == QSsl::PublicKey
TRUEFALSE
yes
Evaluation Count:232
yes
Evaluation Count:328
232-328
294 if (!q_PEM_write_bio_DSA_PUBKEY(bio, d->dsa))
partially evaluated: !q_PEM_write_bio_DSA_PUBKEY(bio, d->dsa)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:232
0-232
295 fail = true;
never executed: fail = true;
0
296 } else {
executed: }
Execution Count:232
232
297 if (!q_PEM_write_bio_DSAPrivateKey( 0-328
298 bio, d->dsa, 0-328
299 0-328
300 passPhrase.isEmpty() ? (const EVP_CIPHER *)0 : q_EVP_des_ede3_cbc(), 0-328
301 (uchar *)passPhrase.data(), passPhrase.size(), 0, 0)) {
partially evaluated: !q_PEM_write_bio_DSAPrivateKey( bio, d->dsa, passPhrase.isEmpty() ? (const EVP_CIPHER *)0 : q_EVP_des_ede3_cbc(), (uchar *)passPhrase.data(), passPhrase.size(), 0, 0)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:328
0-328
302 fail = true; -
303 }
never executed: }
0
304 }
executed: }
Execution Count:328
328
305 } -
306 -
307 QByteArray pem; -
308 if (!fail) {
partially evaluated: !fail
TRUEFALSE
yes
Evaluation Count:1550
no
Evaluation Count:0
0-1550
309 char *data; -
310 long size = (int)q_BIO_ctrl(bio,3,0,(char *)&data); -
311 pem = QByteArray(data, size); -
312 }
executed: }
Execution Count:1550
1550
313 q_BIO_free(bio); -
314 return pem;
executed: return pem;
Execution Count:1550
1550
315} -
316Qt::HANDLE QSslKey::handle() const -
317{ -
318 switch (d->algorithm) { -
319 case QSsl::Opaque: -
320 return Qt::HANDLE(d->opaque);
never executed: return Qt::HANDLE(d->opaque);
0
321 case QSsl::Rsa: -
322 return Qt::HANDLE(d->rsa);
executed: return Qt::HANDLE(d->rsa);
Execution Count:3
3
323 case QSsl::Dsa: -
324 return Qt::HANDLE(d->dsa);
never executed: return Qt::HANDLE(d->dsa);
0
325 default: -
326 return Qt::HANDLE(__null);
never executed: return Qt::HANDLE(__null);
0
327 } -
328}
never executed: }
0
329 -
330 -
331 -
332 -
333bool QSslKey::operator==(const QSslKey &other) const -
334{ -
335 if (isNull())
evaluated: isNull()
TRUEFALSE
yes
Evaluation Count:44
yes
Evaluation Count:181
44-181
336 return other.isNull();
executed: return other.isNull();
Execution Count:44
44
337 if (other.isNull())
partially evaluated: other.isNull()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:181
0-181
338 return isNull();
never executed: return isNull();
0
339 if (algorithm() != other.algorithm())
partially evaluated: algorithm() != other.algorithm()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:181
0-181
340 return false;
never executed: return false;
0
341 if (type() != other.type())
partially evaluated: type() != other.type()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:181
0-181
342 return false;
never executed: return false;
0
343 if (length() != other.length())
partially evaluated: length() != other.length()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:181
0-181
344 return false;
never executed: return false;
0
345 if (algorithm() == QSsl::Opaque)
partially evaluated: algorithm() == QSsl::Opaque
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:181
0-181
346 return handle() == other.handle();
never executed: return handle() == other.handle();
0
347 return toDer() == other.toDer();
executed: return toDer() == other.toDer();
Execution Count:181
181
348} -
349class QDebug; -
350QDebug operator<<(QDebug debug, const QSslKey &key) -
351{ -
352 debug << "QSslKey(" -
353 << (key.type() == QSsl::PublicKey ? "PublicKey" : "PrivateKey") -
354 << ", " << (key.algorithm() == QSsl::Opaque ? "OPAQUE" : -
355 (key.algorithm() == QSsl::Rsa ? "RSA" : "DSA")) -
356 << ", " << key.length() -
357 << ')'; -
358 return debug;
never executed: return debug;
0
359} -
360 -
361 -
362 -
363 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial