Line 0
Link Here
|
|
|
1 |
--- plugins/qca-ossl/qca-ossl.cpp.orig 2017-02-06 12:29:44 UTC |
2 |
+++ plugins/qca-ossl/qca-ossl.cpp |
3 |
@@ -1,6 +1,7 @@ |
4 |
/* |
5 |
* Copyright (C) 2004-2007 Justin Karneges <justin@affinix.com> |
6 |
* Copyright (C) 2004-2006 Brad Hards <bradh@frogmouth.net> |
7 |
+ * Copyright (C) 2017 Fabian Vogt <fabian@ritter-vogt.de> |
8 |
* |
9 |
* This library is free software; you can redistribute it and/or |
10 |
* modify it under the terms of the GNU Lesser General Public |
11 |
@@ -38,6 +39,10 @@ |
12 |
#include <openssl/pkcs12.h> |
13 |
#include <openssl/ssl.h> |
14 |
|
15 |
+extern "C" { |
16 |
+#include "libcrypto-compat.h" |
17 |
+} |
18 |
+ |
19 |
#ifndef OSSL_097 |
20 |
// comment this out if you'd rather use openssl 0.9.6 |
21 |
#define OSSL_097 |
22 |
@@ -52,6 +57,73 @@ |
23 |
((_STACK*) (1 ? p : (type*)0)) |
24 |
#endif |
25 |
|
26 |
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L |
27 |
+ #define OSSL_110 |
28 |
+#endif |
29 |
+ |
30 |
+// OpenSSL 1.1.0 compatibility macros |
31 |
+#ifdef OSSL_110 |
32 |
+#define M_ASN1_IA5STRING_new() ASN1_IA5STRING_new() |
33 |
+#else |
34 |
+static HMAC_CTX *HMAC_CTX_new() { return new HMAC_CTX(); } |
35 |
+static void HMAC_CTX_free(HMAC_CTX *x) { free(x); } |
36 |
+static void EVP_PKEY_up_ref(EVP_PKEY *x) { CRYPTO_add(&x->references, 1, CRYPTO_LOCK_EVP_PKEY); } |
37 |
+static void X509_up_ref(X509 *x) { CRYPTO_add(&x->references, 1, CRYPTO_LOCK_X509); } |
38 |
+static void X509_CRL_up_ref(X509_CRL *x) { CRYPTO_add(&x->references, 1, CRYPTO_LOCK_X509_CRL); } |
39 |
+static DSA *EVP_PKEY_get0_DSA(EVP_PKEY *x) { return x->pkey.dsa; } |
40 |
+static DH *EVP_PKEY_get0_DH(EVP_PKEY *x) { return x->pkey.dh; } |
41 |
+static int RSA_meth_set_sign(RSA_METHOD *meth, |
42 |
+ int (*sign) (int type, const unsigned char *m, |
43 |
+ unsigned int m_length, |
44 |
+ unsigned char *sigret, unsigned int *siglen, |
45 |
+ const RSA *rsa)) |
46 |
+{ |
47 |
+ meth->rsa_sign = sign; |
48 |
+ return 1; |
49 |
+} |
50 |
+int RSA_meth_set_verify(RSA_METHOD *meth, |
51 |
+ int (*verify) (int dtype, const unsigned char *m, |
52 |
+ unsigned int m_length, |
53 |
+ const unsigned char *sigbuf, |
54 |
+ unsigned int siglen, const RSA *rsa)) |
55 |
+{ |
56 |
+ meth->rsa_verify = verify; |
57 |
+ return 1; |
58 |
+} |
59 |
+void X509_REQ_get0_signature(const X509_REQ *req, const ASN1_BIT_STRING **psig, |
60 |
+ const X509_ALGOR **palg) |
61 |
+{ |
62 |
+ if (psig != NULL) |
63 |
+ *psig = req->signature; |
64 |
+ if (palg != NULL) |
65 |
+ *palg = req->sig_alg; |
66 |
+} |
67 |
+int X509_REQ_get_signature_nid(const X509_REQ *req) |
68 |
+{ |
69 |
+ return OBJ_obj2nid(req->sig_alg->algorithm); |
70 |
+} |
71 |
+void X509_CRL_get0_signature(const X509_CRL *crl, const ASN1_BIT_STRING **psig, |
72 |
+ const X509_ALGOR **palg) |
73 |
+{ |
74 |
+ if (psig != NULL) |
75 |
+ *psig = crl->signature; |
76 |
+ if (palg != NULL) |
77 |
+ *palg = crl->sig_alg; |
78 |
+} |
79 |
+int X509_CRL_get_signature_nid(const X509_CRL *crl) |
80 |
+{ |
81 |
+ return OBJ_obj2nid(crl->sig_alg->algorithm); |
82 |
+} |
83 |
+const ASN1_INTEGER *X509_REVOKED_get0_serialNumber(const X509_REVOKED *x) |
84 |
+{ |
85 |
+ return x->serialNumber; |
86 |
+} |
87 |
+const ASN1_TIME *X509_REVOKED_get0_revocationDate(const X509_REVOKED *x) |
88 |
+{ |
89 |
+ return x->revocationDate; |
90 |
+} |
91 |
+#endif |
92 |
+ |
93 |
using namespace QCA; |
94 |
|
95 |
namespace opensslQCAPlugin { |
96 |
@@ -93,7 +165,7 @@ static QByteArray bio2ba(BIO *b) |
97 |
return buf; |
98 |
} |
99 |
|
100 |
-static BigInteger bn2bi(BIGNUM *n) |
101 |
+static BigInteger bn2bi(const BIGNUM *n) |
102 |
{ |
103 |
SecureArray buf(BN_num_bytes(n) + 1); |
104 |
buf[0] = 0; // positive |
105 |
@@ -109,7 +181,7 @@ static BIGNUM *bi2bn(const BigInteger &n) |
106 |
|
107 |
// take lowest bytes of BIGNUM to fit |
108 |
// pad with high byte zeroes to fit |
109 |
-static SecureArray bn2fixedbuf(BIGNUM *n, int size) |
110 |
+static SecureArray bn2fixedbuf(const BIGNUM *n, int size) |
111 |
{ |
112 |
SecureArray buf(BN_num_bytes(n)); |
113 |
BN_bn2bin(n, (unsigned char *)buf.data()); |
114 |
@@ -127,8 +199,16 @@ static SecureArray dsasig_der_to_raw(const SecureArray |
115 |
const unsigned char *inp = (const unsigned char *)in.data(); |
116 |
d2i_DSA_SIG(&sig, &inp, in.size()); |
117 |
|
118 |
- SecureArray part_r = bn2fixedbuf(sig->r, 20); |
119 |
- SecureArray part_s = bn2fixedbuf(sig->s, 20); |
120 |
+ const BIGNUM *bnr, *bns; |
121 |
+ |
122 |
+#ifdef OSSL_110 |
123 |
+ DSA_SIG_get0(sig, &bnr, &bns); |
124 |
+#else |
125 |
+ bnr = sig->r; bns = sig->s; |
126 |
+#endif |
127 |
+ |
128 |
+ SecureArray part_r = bn2fixedbuf(bnr, 20); |
129 |
+ SecureArray part_s = bn2fixedbuf(bns, 20); |
130 |
SecureArray result; |
131 |
result.append(part_r); |
132 |
result.append(part_s); |
133 |
@@ -143,13 +223,21 @@ static SecureArray dsasig_raw_to_der(const SecureArray |
134 |
return SecureArray(); |
135 |
|
136 |
DSA_SIG *sig = DSA_SIG_new(); |
137 |
- SecureArray part_r(20); |
138 |
- SecureArray part_s(20); |
139 |
+ SecureArray part_r(20); BIGNUM *bnr; |
140 |
+ SecureArray part_s(20); BIGNUM *bns; |
141 |
memcpy(part_r.data(), in.data(), 20); |
142 |
memcpy(part_s.data(), in.data() + 20, 20); |
143 |
- sig->r = BN_bin2bn((const unsigned char *)part_r.data(), part_r.size(), NULL); |
144 |
- sig->s = BN_bin2bn((const unsigned char *)part_s.data(), part_s.size(), NULL); |
145 |
+ bnr = BN_bin2bn((const unsigned char *)part_r.data(), part_r.size(), NULL); |
146 |
+ bns = BN_bin2bn((const unsigned char *)part_s.data(), part_s.size(), NULL); |
147 |
|
148 |
+#ifdef OSSL_110 |
149 |
+ if(DSA_SIG_set0(sig, bnr, bns) == 0) |
150 |
+ return SecureArray(); |
151 |
+ // Not documented what happens in the failure case, free bnr and bns? |
152 |
+#else |
153 |
+ sig->r = bnr; sig->s = bns; |
154 |
+#endif |
155 |
+ |
156 |
int len = i2d_DSA_SIG(sig, NULL); |
157 |
SecureArray result(len); |
158 |
unsigned char *p = (unsigned char *)result.data(); |
159 |
@@ -1004,29 +1092,39 @@ class opensslHashContext : public HashContext (public) |
160 |
opensslHashContext(const EVP_MD *algorithm, Provider *p, const QString &type) : HashContext(p, type) |
161 |
{ |
162 |
m_algorithm = algorithm; |
163 |
- EVP_DigestInit( &m_context, m_algorithm ); |
164 |
+ m_context = EVP_MD_CTX_new(); |
165 |
+ EVP_DigestInit( m_context, m_algorithm ); |
166 |
} |
167 |
|
168 |
+ opensslHashContext(const opensslHashContext &other) |
169 |
+ : HashContext(other) |
170 |
+ { |
171 |
+ m_algorithm = other.m_algorithm; |
172 |
+ m_context = EVP_MD_CTX_new(); |
173 |
+ EVP_MD_CTX_copy_ex(m_context, other.m_context); |
174 |
+ } |
175 |
+ |
176 |
~opensslHashContext() |
177 |
{ |
178 |
- EVP_MD_CTX_cleanup(&m_context); |
179 |
+ EVP_MD_CTX_free(m_context); |
180 |
} |
181 |
|
182 |
void clear() |
183 |
{ |
184 |
- EVP_MD_CTX_cleanup(&m_context); |
185 |
- EVP_DigestInit( &m_context, m_algorithm ); |
186 |
+ EVP_MD_CTX_free(m_context); |
187 |
+ m_context = EVP_MD_CTX_new(); |
188 |
+ EVP_DigestInit( m_context, m_algorithm ); |
189 |
} |
190 |
|
191 |
void update(const MemoryRegion &a) |
192 |
{ |
193 |
- EVP_DigestUpdate( &m_context, (unsigned char*)a.data(), a.size() ); |
194 |
+ EVP_DigestUpdate( m_context, (unsigned char*)a.data(), a.size() ); |
195 |
} |
196 |
|
197 |
MemoryRegion final() |
198 |
{ |
199 |
SecureArray a( EVP_MD_size( m_algorithm ) ); |
200 |
- EVP_DigestFinal( &m_context, (unsigned char*)a.data(), 0 ); |
201 |
+ EVP_DigestFinal( m_context, (unsigned char*)a.data(), 0 ); |
202 |
return a; |
203 |
} |
204 |
|
205 |
@@ -1037,7 +1135,7 @@ class opensslHashContext : public HashContext (public) |
206 |
|
207 |
protected: |
208 |
const EVP_MD *m_algorithm; |
209 |
- EVP_MD_CTX m_context; |
210 |
+ EVP_MD_CTX *m_context; |
211 |
}; |
212 |
|
213 |
|
214 |
@@ -1047,9 +1145,23 @@ class opensslPbkdf1Context : public KDFContext (public |
215 |
opensslPbkdf1Context(const EVP_MD *algorithm, Provider *p, const QString &type) : KDFContext(p, type) |
216 |
{ |
217 |
m_algorithm = algorithm; |
218 |
- EVP_DigestInit( &m_context, m_algorithm ); |
219 |
+ m_context = EVP_MD_CTX_new(); |
220 |
+ EVP_DigestInit( m_context, m_algorithm ); |
221 |
} |
222 |
|
223 |
+ opensslPbkdf1Context(const opensslPbkdf1Context &other) |
224 |
+ : KDFContext(other) |
225 |
+ { |
226 |
+ m_algorithm = other.m_algorithm; |
227 |
+ m_context = EVP_MD_CTX_new(); |
228 |
+ EVP_MD_CTX_copy(m_context, other.m_context); |
229 |
+ } |
230 |
+ |
231 |
+ ~opensslPbkdf1Context() |
232 |
+ { |
233 |
+ EVP_MD_CTX_free(m_context); |
234 |
+ } |
235 |
+ |
236 |
Provider::Context *clone() const |
237 |
{ |
238 |
return new opensslPbkdf1Context( *this ); |
239 |
@@ -1081,16 +1193,16 @@ class opensslPbkdf1Context : public KDFContext (public |
240 |
DK = Tc<0..dkLen-1> |
241 |
*/ |
242 |
// calculate T_1 |
243 |
- EVP_DigestUpdate( &m_context, (unsigned char*)secret.data(), secret.size() ); |
244 |
- EVP_DigestUpdate( &m_context, (unsigned char*)salt.data(), salt.size() ); |
245 |
+ EVP_DigestUpdate( m_context, (unsigned char*)secret.data(), secret.size() ); |
246 |
+ EVP_DigestUpdate( m_context, (unsigned char*)salt.data(), salt.size() ); |
247 |
SecureArray a( EVP_MD_size( m_algorithm ) ); |
248 |
- EVP_DigestFinal( &m_context, (unsigned char*)a.data(), 0 ); |
249 |
+ EVP_DigestFinal( m_context, (unsigned char*)a.data(), 0 ); |
250 |
|
251 |
// calculate T_2 up to T_c |
252 |
for ( unsigned int i = 2; i <= iterationCount; ++i ) { |
253 |
- EVP_DigestInit( &m_context, m_algorithm ); |
254 |
- EVP_DigestUpdate( &m_context, (unsigned char*)a.data(), a.size() ); |
255 |
- EVP_DigestFinal( &m_context, (unsigned char*)a.data(), 0 ); |
256 |
+ EVP_DigestInit( m_context, m_algorithm ); |
257 |
+ EVP_DigestUpdate( m_context, (unsigned char*)a.data(), a.size() ); |
258 |
+ EVP_DigestFinal( m_context, (unsigned char*)a.data(), 0 ); |
259 |
} |
260 |
|
261 |
// shrink a to become DK, of the required length |
262 |
@@ -1136,19 +1248,19 @@ class opensslPbkdf1Context : public KDFContext (public |
263 |
DK = Tc<0..dkLen-1> |
264 |
*/ |
265 |
// calculate T_1 |
266 |
- EVP_DigestUpdate( &m_context, (unsigned char*)secret.data(), secret.size() ); |
267 |
- EVP_DigestUpdate( &m_context, (unsigned char*)salt.data(), salt.size() ); |
268 |
+ EVP_DigestUpdate( m_context, (unsigned char*)secret.data(), secret.size() ); |
269 |
+ EVP_DigestUpdate( m_context, (unsigned char*)salt.data(), salt.size() ); |
270 |
SecureArray a( EVP_MD_size( m_algorithm ) ); |
271 |
- EVP_DigestFinal( &m_context, (unsigned char*)a.data(), 0 ); |
272 |
+ EVP_DigestFinal( m_context, (unsigned char*)a.data(), 0 ); |
273 |
|
274 |
// calculate T_2 up to T_c |
275 |
*iterationCount = 2 - 1; // <- Have to remove 1, unless it computes one |
276 |
timer.start(); // ^ time more than the base function |
277 |
// ^ with the same iterationCount |
278 |
while (timer.elapsed() < msecInterval) { |
279 |
- EVP_DigestInit( &m_context, m_algorithm ); |
280 |
- EVP_DigestUpdate( &m_context, (unsigned char*)a.data(), a.size() ); |
281 |
- EVP_DigestFinal( &m_context, (unsigned char*)a.data(), 0 ); |
282 |
+ EVP_DigestInit( m_context, m_algorithm ); |
283 |
+ EVP_DigestUpdate( m_context, (unsigned char*)a.data(), a.size() ); |
284 |
+ EVP_DigestFinal( m_context, (unsigned char*)a.data(), 0 ); |
285 |
++(*iterationCount); |
286 |
} |
287 |
|
288 |
@@ -1163,7 +1275,7 @@ class opensslPbkdf1Context : public KDFContext (public |
289 |
|
290 |
protected: |
291 |
const EVP_MD *m_algorithm; |
292 |
- EVP_MD_CTX m_context; |
293 |
+ EVP_MD_CTX *m_context; |
294 |
}; |
295 |
|
296 |
class opensslPbkdf2Context : public KDFContext |
297 |
@@ -1231,12 +1343,28 @@ class opensslHMACContext : public MACContext (public) |
298 |
opensslHMACContext(const EVP_MD *algorithm, Provider *p, const QString &type) : MACContext(p, type) |
299 |
{ |
300 |
m_algorithm = algorithm; |
301 |
- HMAC_CTX_init( &m_context ); |
302 |
+ m_context = HMAC_CTX_new(); |
303 |
+#ifndef OSSL_110 |
304 |
+ HMAC_CTX_init( m_context ); |
305 |
+#endif |
306 |
} |
307 |
|
308 |
+ opensslHMACContext(const opensslHMACContext &other) |
309 |
+ : MACContext(other) |
310 |
+ { |
311 |
+ m_algorithm = other.m_algorithm; |
312 |
+ m_context = HMAC_CTX_new(); |
313 |
+ HMAC_CTX_copy(m_context, other.m_context); |
314 |
+ } |
315 |
+ |
316 |
+ ~opensslHMACContext() |
317 |
+ { |
318 |
+ HMAC_CTX_free(m_context); |
319 |
+ } |
320 |
+ |
321 |
void setup(const SymmetricKey &key) |
322 |
{ |
323 |
- HMAC_Init_ex( &m_context, key.data(), key.size(), m_algorithm, 0 ); |
324 |
+ HMAC_Init_ex( m_context, key.data(), key.size(), m_algorithm, 0 ); |
325 |
} |
326 |
|
327 |
KeyLength keyLength() const |
328 |
@@ -1246,14 +1374,18 @@ class opensslHMACContext : public MACContext (public) |
329 |
|
330 |
void update(const MemoryRegion &a) |
331 |
{ |
332 |
- HMAC_Update( &m_context, (unsigned char *)a.data(), a.size() ); |
333 |
+ HMAC_Update( m_context, (unsigned char *)a.data(), a.size() ); |
334 |
} |
335 |
|
336 |
void final(MemoryRegion *out) |
337 |
{ |
338 |
SecureArray sa( EVP_MD_size( m_algorithm ), 0 ); |
339 |
- HMAC_Final(&m_context, (unsigned char *)sa.data(), 0 ); |
340 |
- HMAC_CTX_cleanup(&m_context); |
341 |
+ HMAC_Final(m_context, (unsigned char *)sa.data(), 0 ); |
342 |
+#ifdef OSSL_110 |
343 |
+ HMAC_CTX_reset(m_context); |
344 |
+#else |
345 |
+ HMAC_CTX_cleanup(m_context); |
346 |
+#endif |
347 |
*out = sa; |
348 |
} |
349 |
|
350 |
@@ -1263,7 +1395,7 @@ class opensslHMACContext : public MACContext (public) |
351 |
} |
352 |
|
353 |
protected: |
354 |
- HMAC_CTX m_context; |
355 |
+ HMAC_CTX *m_context; |
356 |
const EVP_MD *m_algorithm; |
357 |
}; |
358 |
|
359 |
@@ -1277,7 +1409,7 @@ class EVPKey |
360 |
public: |
361 |
enum State { Idle, SignActive, SignError, VerifyActive, VerifyError }; |
362 |
EVP_PKEY *pkey; |
363 |
- EVP_MD_CTX mdctx; |
364 |
+ EVP_MD_CTX *mdctx; |
365 |
State state; |
366 |
bool raw_type; |
367 |
SecureArray raw; |
368 |
@@ -1287,19 +1419,23 @@ class EVPKey |
369 |
pkey = 0; |
370 |
raw_type = false; |
371 |
state = Idle; |
372 |
+ mdctx = EVP_MD_CTX_new(); |
373 |
} |
374 |
|
375 |
EVPKey(const EVPKey &from) |
376 |
{ |
377 |
pkey = from.pkey; |
378 |
- CRYPTO_add(&pkey->references, 1, CRYPTO_LOCK_EVP_PKEY); |
379 |
+ EVP_PKEY_up_ref(pkey); |
380 |
raw_type = false; |
381 |
state = Idle; |
382 |
+ mdctx = EVP_MD_CTX_new(); |
383 |
+ EVP_MD_CTX_copy(mdctx, from.mdctx); |
384 |
} |
385 |
|
386 |
~EVPKey() |
387 |
{ |
388 |
reset(); |
389 |
+ EVP_MD_CTX_free(mdctx); |
390 |
} |
391 |
|
392 |
void reset() |
393 |
@@ -1322,8 +1458,8 @@ class EVPKey |
394 |
else |
395 |
{ |
396 |
raw_type = false; |
397 |
- EVP_MD_CTX_init(&mdctx); |
398 |
- if(!EVP_SignInit_ex(&mdctx, type, NULL)) |
399 |
+ EVP_MD_CTX_init(mdctx); |
400 |
+ if(!EVP_SignInit_ex(mdctx, type, NULL)) |
401 |
state = SignError; |
402 |
} |
403 |
} |
404 |
@@ -1339,8 +1475,8 @@ class EVPKey |
405 |
else |
406 |
{ |
407 |
raw_type = false; |
408 |
- EVP_MD_CTX_init(&mdctx); |
409 |
- if(!EVP_VerifyInit_ex(&mdctx, type, NULL)) |
410 |
+ EVP_MD_CTX_init(mdctx); |
411 |
+ if(!EVP_VerifyInit_ex(mdctx, type, NULL)) |
412 |
state = VerifyError; |
413 |
} |
414 |
} |
415 |
@@ -1352,7 +1488,7 @@ class EVPKey |
416 |
if (raw_type) |
417 |
raw += in; |
418 |
else |
419 |
- if(!EVP_SignUpdate(&mdctx, in.data(), (unsigned int)in.size())) |
420 |
+ if(!EVP_SignUpdate(mdctx, in.data(), (unsigned int)in.size())) |
421 |
state = SignError; |
422 |
} |
423 |
else if(state == VerifyActive) |
424 |
@@ -1360,7 +1496,7 @@ class EVPKey |
425 |
if (raw_type) |
426 |
raw += in; |
427 |
else |
428 |
- if(!EVP_VerifyUpdate(&mdctx, in.data(), (unsigned int)in.size())) |
429 |
+ if(!EVP_VerifyUpdate(mdctx, in.data(), (unsigned int)in.size())) |
430 |
state = VerifyError; |
431 |
} |
432 |
} |
433 |
@@ -1373,17 +1509,24 @@ class EVPKey |
434 |
unsigned int len = out.size(); |
435 |
if (raw_type) |
436 |
{ |
437 |
- if (pkey->type == EVP_PKEY_RSA) |
438 |
+ int type; |
439 |
+#ifdef OSSL_110 |
440 |
+ type = EVP_PKEY_id(pkey); |
441 |
+#else |
442 |
+ type = pkey->type; |
443 |
+#endif |
444 |
+ if (type == EVP_PKEY_RSA) |
445 |
{ |
446 |
+ RSA *rsa = EVP_PKEY_get0_RSA(pkey); |
447 |
if(RSA_private_encrypt (raw.size(), (unsigned char *)raw.data(), |
448 |
- (unsigned char *)out.data(), pkey->pkey.rsa, |
449 |
+ (unsigned char *)out.data(), rsa, |
450 |
RSA_PKCS1_PADDING) == -1) { |
451 |
|
452 |
state = SignError; |
453 |
return SecureArray (); |
454 |
} |
455 |
} |
456 |
- else if (pkey->type == EVP_PKEY_DSA) |
457 |
+ else if (type == EVP_PKEY_DSA) |
458 |
{ |
459 |
state = SignError; |
460 |
return SecureArray (); |
461 |
@@ -1395,7 +1538,7 @@ class EVPKey |
462 |
} |
463 |
} |
464 |
else { |
465 |
- if(!EVP_SignFinal(&mdctx, (unsigned char *)out.data(), &len, pkey)) |
466 |
+ if(!EVP_SignFinal(mdctx, (unsigned char *)out.data(), &len, pkey)) |
467 |
{ |
468 |
state = SignError; |
469 |
return SecureArray(); |
470 |
@@ -1418,16 +1561,24 @@ class EVPKey |
471 |
SecureArray out(EVP_PKEY_size(pkey)); |
472 |
int len = 0; |
473 |
|
474 |
- if (pkey->type == EVP_PKEY_RSA) { |
475 |
+ int type; |
476 |
+#ifdef OSSL_110 |
477 |
+ type = EVP_PKEY_type(EVP_PKEY_id(pkey)); |
478 |
+#else |
479 |
+ type = pkey->type; |
480 |
+#endif |
481 |
+ |
482 |
+ if (type == EVP_PKEY_RSA) { |
483 |
+ RSA *rsa = EVP_PKEY_get0_RSA(pkey); |
484 |
if((len = RSA_public_decrypt (sig.size(), (unsigned char *)sig.data(), |
485 |
- (unsigned char *)out.data (), pkey->pkey.rsa, |
486 |
+ (unsigned char *)out.data (), rsa, |
487 |
RSA_PKCS1_PADDING)) == -1) { |
488 |
|
489 |
state = VerifyError; |
490 |
return false; |
491 |
} |
492 |
} |
493 |
- else if (pkey->type == EVP_PKEY_DSA) |
494 |
+ else if (type == EVP_PKEY_DSA) |
495 |
{ |
496 |
state = VerifyError; |
497 |
return false; |
498 |
@@ -1447,7 +1598,7 @@ class EVPKey |
499 |
} |
500 |
else |
501 |
{ |
502 |
- if(EVP_VerifyFinal(&mdctx, (unsigned char *)sig.data(), (unsigned int)sig.size(), pkey) != 1) |
503 |
+ if(EVP_VerifyFinal(mdctx, (unsigned char *)sig.data(), (unsigned int)sig.size(), pkey) != 1) |
504 |
{ |
505 |
state = VerifyError; |
506 |
return false; |
507 |
@@ -1561,9 +1712,11 @@ static bool make_dlgroup(const QByteArray &seed, int b |
508 |
return false; |
509 |
if(ret_counter != counter) |
510 |
return false; |
511 |
- params->p = bn2bi(dsa->p); |
512 |
- params->q = bn2bi(dsa->q); |
513 |
- params->g = bn2bi(dsa->g); |
514 |
+ const BIGNUM *bnp, *bnq, *bng; |
515 |
+ DSA_get0_pqg(dsa, &bnp, &bnq, &bng); |
516 |
+ params->p = bn2bi(bnp); |
517 |
+ params->q = bn2bi(bnq); |
518 |
+ params->g = bn2bi(bng); |
519 |
DSA_free(dsa); |
520 |
return true; |
521 |
} |
522 |
@@ -1826,10 +1979,11 @@ class RSAKey : public RSAContext (public) |
523 |
return; |
524 |
|
525 |
// extract the public key into DER format |
526 |
- int len = i2d_RSAPublicKey(evp.pkey->pkey.rsa, NULL); |
527 |
+ RSA *rsa_pkey = EVP_PKEY_get0_RSA(evp.pkey); |
528 |
+ int len = i2d_RSAPublicKey(rsa_pkey, NULL); |
529 |
SecureArray result(len); |
530 |
unsigned char *p = (unsigned char *)result.data(); |
531 |
- i2d_RSAPublicKey(evp.pkey->pkey.rsa, &p); |
532 |
+ i2d_RSAPublicKey(rsa_pkey, &p); |
533 |
p = (unsigned char *)result.data(); |
534 |
|
535 |
// put the DER public key back into openssl |
536 |
@@ -1852,7 +2006,7 @@ class RSAKey : public RSAContext (public) |
537 |
|
538 |
virtual int maximumEncryptSize(EncryptionAlgorithm alg) const |
539 |
{ |
540 |
- RSA *rsa = evp.pkey->pkey.rsa; |
541 |
+ RSA *rsa = EVP_PKEY_get0_RSA(evp.pkey); |
542 |
int size = 0; |
543 |
switch(alg) |
544 |
{ |
545 |
@@ -1867,7 +2021,7 @@ class RSAKey : public RSAContext (public) |
546 |
|
547 |
virtual SecureArray encrypt(const SecureArray &in, EncryptionAlgorithm alg) |
548 |
{ |
549 |
- RSA *rsa = evp.pkey->pkey.rsa; |
550 |
+ RSA *rsa = EVP_PKEY_get0_RSA(evp.pkey); |
551 |
SecureArray buf = in; |
552 |
int max = maximumEncryptSize(alg); |
553 |
|
554 |
@@ -1900,7 +2054,7 @@ class RSAKey : public RSAContext (public) |
555 |
|
556 |
virtual bool decrypt(const SecureArray &in, SecureArray *out, EncryptionAlgorithm alg) |
557 |
{ |
558 |
- RSA *rsa = evp.pkey->pkey.rsa; |
559 |
+ RSA *rsa = EVP_PKEY_get0_RSA(evp.pkey); |
560 |
SecureArray result(RSA_size(rsa)); |
561 |
int pad; |
562 |
|
563 |
@@ -2021,14 +2175,10 @@ class RSAKey : public RSAContext (public) |
564 |
evp.reset(); |
565 |
|
566 |
RSA *rsa = RSA_new(); |
567 |
- rsa->n = bi2bn(n); |
568 |
- rsa->e = bi2bn(e); |
569 |
- rsa->p = bi2bn(p); |
570 |
- rsa->q = bi2bn(q); |
571 |
- rsa->d = bi2bn(d); |
572 |
- |
573 |
- if(!rsa->n || !rsa->e || !rsa->p || !rsa->q || !rsa->d) |
574 |
+ if(RSA_set0_key(rsa, bi2bn(n), bi2bn(e), bi2bn(d)) == 0 |
575 |
+ || RSA_set0_factors(rsa, bi2bn(p), bi2bn(q)) == 0) |
576 |
{ |
577 |
+ // Free BIGNUMS? |
578 |
RSA_free(rsa); |
579 |
return; |
580 |
} |
581 |
@@ -2036,7 +2186,7 @@ class RSAKey : public RSAContext (public) |
582 |
// When private key has no Public Exponent (e) or Private Exponent (d) |
583 |
// need to disable blinding. Otherwise decryption will be broken. |
584 |
// http://www.mail-archive.com/openssl-users@openssl.org/msg63530.html |
585 |
- if(BN_is_zero(rsa->e) || BN_is_zero(rsa->d)) |
586 |
+ if(e == BigInteger(0) || d == BigInteger(0)) |
587 |
RSA_blinding_off(rsa); |
588 |
|
589 |
evp.pkey = EVP_PKEY_new(); |
590 |
@@ -2049,10 +2199,7 @@ class RSAKey : public RSAContext (public) |
591 |
evp.reset(); |
592 |
|
593 |
RSA *rsa = RSA_new(); |
594 |
- rsa->n = bi2bn(n); |
595 |
- rsa->e = bi2bn(e); |
596 |
- |
597 |
- if(!rsa->n || !rsa->e) |
598 |
+ if(RSA_set0_key(rsa, bi2bn(n), bi2bn(e), NULL) == 0) |
599 |
{ |
600 |
RSA_free(rsa); |
601 |
return; |
602 |
@@ -2065,27 +2212,42 @@ class RSAKey : public RSAContext (public) |
603 |
|
604 |
virtual BigInteger n() const |
605 |
{ |
606 |
- return bn2bi(evp.pkey->pkey.rsa->n); |
607 |
+ RSA *rsa = EVP_PKEY_get0_RSA(evp.pkey); |
608 |
+ const BIGNUM *bnn; |
609 |
+ RSA_get0_key(rsa, &bnn, NULL, NULL); |
610 |
+ return bn2bi(bnn); |
611 |
} |
612 |
|
613 |
virtual BigInteger e() const |
614 |
{ |
615 |
- return bn2bi(evp.pkey->pkey.rsa->e); |
616 |
+ RSA *rsa = EVP_PKEY_get0_RSA(evp.pkey); |
617 |
+ const BIGNUM *bne; |
618 |
+ RSA_get0_key(rsa, NULL, &bne, NULL); |
619 |
+ return bn2bi(bne); |
620 |
} |
621 |
|
622 |
virtual BigInteger p() const |
623 |
{ |
624 |
- return bn2bi(evp.pkey->pkey.rsa->p); |
625 |
+ RSA *rsa = EVP_PKEY_get0_RSA(evp.pkey); |
626 |
+ const BIGNUM *bnp; |
627 |
+ RSA_get0_factors(rsa, &bnp, NULL); |
628 |
+ return bn2bi(bnp); |
629 |
} |
630 |
|
631 |
virtual BigInteger q() const |
632 |
{ |
633 |
- return bn2bi(evp.pkey->pkey.rsa->q); |
634 |
+ RSA *rsa = EVP_PKEY_get0_RSA(evp.pkey); |
635 |
+ const BIGNUM *bnq; |
636 |
+ RSA_get0_factors(rsa, NULL, &bnq); |
637 |
+ return bn2bi(bnq); |
638 |
} |
639 |
|
640 |
virtual BigInteger d() const |
641 |
{ |
642 |
- return bn2bi(evp.pkey->pkey.rsa->d); |
643 |
+ RSA *rsa = EVP_PKEY_get0_RSA(evp.pkey); |
644 |
+ const BIGNUM *bnd; |
645 |
+ RSA_get0_key(rsa, NULL, NULL, &bnd); |
646 |
+ return bn2bi(bnd); |
647 |
} |
648 |
|
649 |
private slots: |
650 |
@@ -2134,10 +2296,12 @@ class DSAKeyMaker : public QThread (public) |
651 |
virtual void run() |
652 |
{ |
653 |
DSA *dsa = DSA_new(); |
654 |
- dsa->p = bi2bn(domain.p()); |
655 |
- dsa->q = bi2bn(domain.q()); |
656 |
- dsa->g = bi2bn(domain.g()); |
657 |
- if(!DSA_generate_key(dsa)) |
658 |
+ BIGNUM *pne = bi2bn(domain.p()), |
659 |
+ *qne = bi2bn(domain.q()), |
660 |
+ *gne = bi2bn(domain.g()); |
661 |
+ |
662 |
+ if(!DSA_set0_pqg(dsa, pne, qne, gne) |
663 |
+ || !DSA_generate_key(dsa)) |
664 |
{ |
665 |
DSA_free(dsa); |
666 |
return; |
667 |
@@ -2212,10 +2376,11 @@ class DSAKey : public DSAContext (public) |
668 |
return; |
669 |
|
670 |
// extract the public key into DER format |
671 |
- int len = i2d_DSAPublicKey(evp.pkey->pkey.dsa, NULL); |
672 |
+ DSA *dsa_pkey = EVP_PKEY_get0_DSA(evp.pkey); |
673 |
+ int len = i2d_DSAPublicKey(dsa_pkey, NULL); |
674 |
SecureArray result(len); |
675 |
unsigned char *p = (unsigned char *)result.data(); |
676 |
- i2d_DSAPublicKey(evp.pkey->pkey.dsa, &p); |
677 |
+ i2d_DSAPublicKey(dsa_pkey, &p); |
678 |
p = (unsigned char *)result.data(); |
679 |
|
680 |
// put the DER public key back into openssl |
681 |
@@ -2244,7 +2409,7 @@ class DSAKey : public DSAContext (public) |
682 |
else |
683 |
transformsig = false; |
684 |
|
685 |
- evp.startSign(EVP_dss1()); |
686 |
+ evp.startSign(EVP_sha1()); |
687 |
} |
688 |
|
689 |
virtual void startVerify(SignatureAlgorithm, SignatureFormat format) |
690 |
@@ -2255,7 +2420,7 @@ class DSAKey : public DSAContext (public) |
691 |
else |
692 |
transformsig = false; |
693 |
|
694 |
- evp.startVerify(EVP_dss1()); |
695 |
+ evp.startVerify(EVP_sha1()); |
696 |
} |
697 |
|
698 |
virtual void update(const MemoryRegion &in) |
699 |
@@ -2305,13 +2470,14 @@ class DSAKey : public DSAContext (public) |
700 |
evp.reset(); |
701 |
|
702 |
DSA *dsa = DSA_new(); |
703 |
- dsa->p = bi2bn(domain.p()); |
704 |
- dsa->q = bi2bn(domain.q()); |
705 |
- dsa->g = bi2bn(domain.g()); |
706 |
- dsa->pub_key = bi2bn(y); |
707 |
- dsa->priv_key = bi2bn(x); |
708 |
+ BIGNUM *bnp = bi2bn(domain.p()); |
709 |
+ BIGNUM *bnq = bi2bn(domain.q()); |
710 |
+ BIGNUM *bng = bi2bn(domain.g()); |
711 |
+ BIGNUM *bnpub_key = bi2bn(y); |
712 |
+ BIGNUM *bnpriv_key = bi2bn(x); |
713 |
|
714 |
- if(!dsa->p || !dsa->q || !dsa->g || !dsa->pub_key || !dsa->priv_key) |
715 |
+ if(!DSA_set0_pqg(dsa, bnp, bnq, bng) |
716 |
+ || !DSA_set0_key(dsa, bnpub_key, bnpriv_key)) |
717 |
{ |
718 |
DSA_free(dsa); |
719 |
return; |
720 |
@@ -2327,12 +2493,13 @@ class DSAKey : public DSAContext (public) |
721 |
evp.reset(); |
722 |
|
723 |
DSA *dsa = DSA_new(); |
724 |
- dsa->p = bi2bn(domain.p()); |
725 |
- dsa->q = bi2bn(domain.q()); |
726 |
- dsa->g = bi2bn(domain.g()); |
727 |
- dsa->pub_key = bi2bn(y); |
728 |
+ BIGNUM *bnp = bi2bn(domain.p()); |
729 |
+ BIGNUM *bnq = bi2bn(domain.q()); |
730 |
+ BIGNUM *bng = bi2bn(domain.g()); |
731 |
+ BIGNUM *bnpub_key = bi2bn(y); |
732 |
|
733 |
- if(!dsa->p || !dsa->q || !dsa->g || !dsa->pub_key) |
734 |
+ if(!DSA_set0_pqg(dsa, bnp, bnq, bng) |
735 |
+ || !DSA_set0_key(dsa, bnpub_key, NULL)) |
736 |
{ |
737 |
DSA_free(dsa); |
738 |
return; |
739 |
@@ -2345,17 +2512,26 @@ class DSAKey : public DSAContext (public) |
740 |
|
741 |
virtual DLGroup domain() const |
742 |
{ |
743 |
- return DLGroup(bn2bi(evp.pkey->pkey.dsa->p), bn2bi(evp.pkey->pkey.dsa->q), bn2bi(evp.pkey->pkey.dsa->g)); |
744 |
+ DSA *dsa = EVP_PKEY_get0_DSA(evp.pkey); |
745 |
+ const BIGNUM *bnp, *bnq, *bng; |
746 |
+ DSA_get0_pqg(dsa, &bnp, &bnq, &bng); |
747 |
+ return DLGroup(bn2bi(bnp), bn2bi(bnq), bn2bi(bng)); |
748 |
} |
749 |
|
750 |
virtual BigInteger y() const |
751 |
{ |
752 |
- return bn2bi(evp.pkey->pkey.dsa->pub_key); |
753 |
+ DSA *dsa = EVP_PKEY_get0_DSA(evp.pkey); |
754 |
+ const BIGNUM *bnpub_key; |
755 |
+ DSA_get0_key(dsa, &bnpub_key, NULL); |
756 |
+ return bn2bi(bnpub_key); |
757 |
} |
758 |
|
759 |
virtual BigInteger x() const |
760 |
{ |
761 |
- return bn2bi(evp.pkey->pkey.dsa->priv_key); |
762 |
+ DSA *dsa = EVP_PKEY_get0_DSA(evp.pkey); |
763 |
+ const BIGNUM *bnpriv_key; |
764 |
+ DSA_get0_key(dsa, NULL, &bnpriv_key); |
765 |
+ return bn2bi(bnpriv_key); |
766 |
} |
767 |
|
768 |
private slots: |
769 |
@@ -2404,9 +2580,10 @@ class DHKeyMaker : public QThread (public) |
770 |
virtual void run() |
771 |
{ |
772 |
DH *dh = DH_new(); |
773 |
- dh->p = bi2bn(domain.p()); |
774 |
- dh->g = bi2bn(domain.g()); |
775 |
- if(!DH_generate_key(dh)) |
776 |
+ BIGNUM *bnp = bi2bn(domain.p()); |
777 |
+ BIGNUM *bng = bi2bn(domain.g()); |
778 |
+ if(!DH_set0_pqg(dh, bnp, NULL, bng) |
779 |
+ || !DH_generate_key(dh)) |
780 |
{ |
781 |
DH_free(dh); |
782 |
return; |
783 |
@@ -2478,12 +2655,15 @@ class DHKey : public DHContext (public) |
784 |
if(!sec) |
785 |
return; |
786 |
|
787 |
- DH *orig = evp.pkey->pkey.dh; |
788 |
+ DH *orig = EVP_PKEY_get0_DH(evp.pkey); |
789 |
DH *dh = DH_new(); |
790 |
- dh->p = BN_dup(orig->p); |
791 |
- dh->g = BN_dup(orig->g); |
792 |
- dh->pub_key = BN_dup(orig->pub_key); |
793 |
+ const BIGNUM *bnp, *bng, *bnpub_key; |
794 |
+ DH_get0_pqg(orig, &bnp, NULL, &bng); |
795 |
+ DH_get0_key(orig, &bnpub_key, NULL); |
796 |
|
797 |
+ DH_set0_key(dh, BN_dup(bnpub_key), NULL); |
798 |
+ DH_set0_pqg(dh, BN_dup(bnp), NULL, BN_dup(bng)); |
799 |
+ |
800 |
evp.reset(); |
801 |
|
802 |
evp.pkey = EVP_PKEY_new(); |
803 |
@@ -2498,10 +2678,13 @@ class DHKey : public DHContext (public) |
804 |
|
805 |
virtual SymmetricKey deriveKey(const PKeyBase &theirs) |
806 |
{ |
807 |
- DH *dh = evp.pkey->pkey.dh; |
808 |
- DH *them = static_cast<const DHKey *>(&theirs)->evp.pkey->pkey.dh; |
809 |
+ DH *dh = EVP_PKEY_get0_DH(evp.pkey); |
810 |
+ DH *them = EVP_PKEY_get0_DH(static_cast<const DHKey *>(&theirs)->evp.pkey); |
811 |
+ const BIGNUM *bnpub_key; |
812 |
+ DH_get0_key(them, &bnpub_key, NULL); |
813 |
+ |
814 |
SecureArray result(DH_size(dh)); |
815 |
- int ret = DH_compute_key((unsigned char *)result.data(), them->pub_key, dh); |
816 |
+ int ret = DH_compute_key((unsigned char *)result.data(), bnpub_key, dh); |
817 |
if(ret <= 0) |
818 |
return SymmetricKey(); |
819 |
result.resize(ret); |
820 |
@@ -2531,12 +2714,13 @@ class DHKey : public DHContext (public) |
821 |
evp.reset(); |
822 |
|
823 |
DH *dh = DH_new(); |
824 |
- dh->p = bi2bn(domain.p()); |
825 |
- dh->g = bi2bn(domain.g()); |
826 |
- dh->pub_key = bi2bn(y); |
827 |
- dh->priv_key = bi2bn(x); |
828 |
+ BIGNUM *bnp = bi2bn(domain.p()); |
829 |
+ BIGNUM *bng = bi2bn(domain.g()); |
830 |
+ BIGNUM *bnpub_key = bi2bn(y); |
831 |
+ BIGNUM *bnpriv_key = bi2bn(x); |
832 |
|
833 |
- if(!dh->p || !dh->g || !dh->pub_key || !dh->priv_key) |
834 |
+ if(!DH_set0_key(dh, bnpub_key, bnpriv_key) |
835 |
+ || !DH_set0_pqg(dh, bnp, NULL, bng)) |
836 |
{ |
837 |
DH_free(dh); |
838 |
return; |
839 |
@@ -2552,11 +2736,12 @@ class DHKey : public DHContext (public) |
840 |
evp.reset(); |
841 |
|
842 |
DH *dh = DH_new(); |
843 |
- dh->p = bi2bn(domain.p()); |
844 |
- dh->g = bi2bn(domain.g()); |
845 |
- dh->pub_key = bi2bn(y); |
846 |
+ BIGNUM *bnp = bi2bn(domain.p()); |
847 |
+ BIGNUM *bng = bi2bn(domain.g()); |
848 |
+ BIGNUM *bnpub_key = bi2bn(y); |
849 |
|
850 |
- if(!dh->p || !dh->g || !dh->pub_key) |
851 |
+ if(!DH_set0_key(dh, bnpub_key, NULL) |
852 |
+ || !DH_set0_pqg(dh, bnp, NULL, bng)) |
853 |
{ |
854 |
DH_free(dh); |
855 |
return; |
856 |
@@ -2569,17 +2754,26 @@ class DHKey : public DHContext (public) |
857 |
|
858 |
virtual DLGroup domain() const |
859 |
{ |
860 |
- return DLGroup(bn2bi(evp.pkey->pkey.dh->p), bn2bi(evp.pkey->pkey.dh->g)); |
861 |
+ DH *dh = EVP_PKEY_get0_DH(evp.pkey); |
862 |
+ const BIGNUM *bnp, *bng; |
863 |
+ DH_get0_pqg(dh, &bnp, NULL, &bng); |
864 |
+ return DLGroup(bn2bi(bnp), bn2bi(bng)); |
865 |
} |
866 |
|
867 |
virtual BigInteger y() const |
868 |
{ |
869 |
- return bn2bi(evp.pkey->pkey.dh->pub_key); |
870 |
+ DH *dh = EVP_PKEY_get0_DH(evp.pkey); |
871 |
+ const BIGNUM *bnpub_key; |
872 |
+ DH_get0_key(dh, &bnpub_key, NULL); |
873 |
+ return bn2bi(bnpub_key); |
874 |
} |
875 |
|
876 |
virtual BigInteger x() const |
877 |
{ |
878 |
- return bn2bi(evp.pkey->pkey.dh->priv_key); |
879 |
+ DH *dh = EVP_PKEY_get0_DH(evp.pkey); |
880 |
+ const BIGNUM *bnpriv_key; |
881 |
+ DH_get0_key(dh, NULL, &bnpriv_key); |
882 |
+ return bn2bi(bnpriv_key); |
883 |
} |
884 |
|
885 |
private slots: |
886 |
@@ -2618,10 +2812,14 @@ class QCA_RSA_METHOD (public) |
887 |
{ |
888 |
key = _key; |
889 |
RSA_set_method(rsa, rsa_method()); |
890 |
+#ifndef OSSL_110 |
891 |
rsa->flags |= RSA_FLAG_SIGN_VER; |
892 |
+#endif |
893 |
RSA_set_app_data(rsa, this); |
894 |
- rsa->n = bi2bn(_key.n()); |
895 |
- rsa->e = bi2bn(_key.e()); |
896 |
+ BIGNUM *bnn = bi2bn(_key.n()); |
897 |
+ BIGNUM *bne = bi2bn(_key.e()); |
898 |
+ |
899 |
+ RSA_set0_key(rsa, bnn, bne, NULL); |
900 |
} |
901 |
|
902 |
RSA_METHOD *rsa_method() |
903 |
@@ -2630,12 +2828,16 @@ class QCA_RSA_METHOD (public) |
904 |
|
905 |
if(!ops) |
906 |
{ |
907 |
- ops = new RSA_METHOD(*RSA_get_default_method()); |
908 |
- ops->rsa_priv_enc = 0;//pkcs11_rsa_encrypt; |
909 |
- ops->rsa_priv_dec = rsa_priv_dec; |
910 |
- ops->rsa_sign = rsa_sign; |
911 |
- ops->rsa_verify = 0;//pkcs11_rsa_verify; |
912 |
- ops->finish = rsa_finish; |
913 |
+ ops = RSA_meth_dup(RSA_get_default_method()); |
914 |
+ RSA_meth_set_priv_enc(ops, NULL); //pkcs11_rsa_encrypt |
915 |
+ RSA_meth_set_priv_dec(ops, rsa_priv_dec); //pkcs11_rsa_encrypt |
916 |
+#ifdef OSSL_110 |
917 |
+ RSA_meth_set_sign(ops, NULL); |
918 |
+#else |
919 |
+ RSA_meth_set_sign(ops, rsa_sign); |
920 |
+#endif |
921 |
+ RSA_meth_set_verify(ops, NULL); //pkcs11_rsa_verify |
922 |
+ RSA_meth_set_finish(ops, rsa_finish); |
923 |
} |
924 |
return ops; |
925 |
} |
926 |
@@ -2654,7 +2856,11 @@ class QCA_RSA_METHOD (public) |
927 |
} |
928 |
else |
929 |
{ |
930 |
+#if OPENSSL_VERSION_NUMBER > 0x10100000L |
931 |
+ RSAerr(RSA_F_RSA_OSSL_PRIVATE_DECRYPT, RSA_R_UNKNOWN_PADDING_TYPE); |
932 |
+#else |
933 |
RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT, RSA_R_UNKNOWN_PADDING_TYPE); |
934 |
+#endif |
935 |
return -1; |
936 |
} |
937 |
|
938 |
@@ -2675,6 +2881,7 @@ class QCA_RSA_METHOD (public) |
939 |
return -1; |
940 |
} |
941 |
|
942 |
+#ifndef OSSL_110 |
943 |
static int rsa_sign(int type, const unsigned char *m, unsigned int m_len, unsigned char *sigret, unsigned int *siglen, const RSA *rsa) |
944 |
{ |
945 |
QCA_RSA_METHOD *self = (QCA_RSA_METHOD *)RSA_get_app_data(rsa); |
946 |
@@ -2691,7 +2898,6 @@ class QCA_RSA_METHOD (public) |
947 |
} |
948 |
else |
949 |
{ |
950 |
- |
951 |
// make X509 packet |
952 |
X509_SIG sig; |
953 |
ASN1_TYPE parameter; |
954 |
@@ -2765,6 +2971,7 @@ class QCA_RSA_METHOD (public) |
955 |
|
956 |
return 1; |
957 |
} |
958 |
+#endif |
959 |
|
960 |
static int rsa_finish(RSA *rsa) |
961 |
{ |
962 |
@@ -2866,21 +3073,22 @@ class MyPKeyContext : public PKeyContext (public) |
963 |
PKeyBase *pkeyToBase(EVP_PKEY *pkey, bool sec) const |
964 |
{ |
965 |
PKeyBase *nk = 0; |
966 |
- if(pkey->type == EVP_PKEY_RSA) |
967 |
+ int pkey_type = EVP_PKEY_type(EVP_PKEY_id(pkey)); |
968 |
+ if(pkey_type == EVP_PKEY_RSA) |
969 |
{ |
970 |
RSAKey *c = new RSAKey(provider()); |
971 |
c->evp.pkey = pkey; |
972 |
c->sec = sec; |
973 |
nk = c; |
974 |
} |
975 |
- else if(pkey->type == EVP_PKEY_DSA) |
976 |
+ else if(pkey_type == EVP_PKEY_DSA) |
977 |
{ |
978 |
DSAKey *c = new DSAKey(provider()); |
979 |
c->evp.pkey = pkey; |
980 |
c->sec = sec; |
981 |
nk = c; |
982 |
} |
983 |
- else if(pkey->type == EVP_PKEY_DH) |
984 |
+ else if(pkey_type == EVP_PKEY_DH) |
985 |
{ |
986 |
DHKey *c = new DHKey(provider()); |
987 |
c->evp.pkey = pkey; |
988 |
@@ -2898,8 +3106,10 @@ class MyPKeyContext : public PKeyContext (public) |
989 |
{ |
990 |
EVP_PKEY *pkey = get_pkey(); |
991 |
|
992 |
+ int pkey_type = EVP_PKEY_type(EVP_PKEY_id(pkey)); |
993 |
+ |
994 |
// OpenSSL does not have DH import/export support |
995 |
- if(pkey->type == EVP_PKEY_DH) |
996 |
+ if(pkey_type == EVP_PKEY_DH) |
997 |
return QByteArray(); |
998 |
|
999 |
BIO *bo = BIO_new(BIO_s_mem()); |
1000 |
@@ -2912,8 +3122,10 @@ class MyPKeyContext : public PKeyContext (public) |
1001 |
{ |
1002 |
EVP_PKEY *pkey = get_pkey(); |
1003 |
|
1004 |
+ int pkey_type = EVP_PKEY_type(EVP_PKEY_id(pkey)); |
1005 |
+ |
1006 |
// OpenSSL does not have DH import/export support |
1007 |
- if(pkey->type == EVP_PKEY_DH) |
1008 |
+ if(pkey_type == EVP_PKEY_DH) |
1009 |
return QString(); |
1010 |
|
1011 |
BIO *bo = BIO_new(BIO_s_mem()); |
1012 |
@@ -2978,9 +3190,10 @@ class MyPKeyContext : public PKeyContext (public) |
1013 |
return SecureArray(); |
1014 |
|
1015 |
EVP_PKEY *pkey = get_pkey(); |
1016 |
+ int pkey_type = EVP_PKEY_type(EVP_PKEY_id(pkey)); |
1017 |
|
1018 |
// OpenSSL does not have DH import/export support |
1019 |
- if(pkey->type == EVP_PKEY_DH) |
1020 |
+ if(pkey_type == EVP_PKEY_DH) |
1021 |
return SecureArray(); |
1022 |
|
1023 |
BIO *bo = BIO_new(BIO_s_mem()); |
1024 |
@@ -3007,9 +3220,10 @@ class MyPKeyContext : public PKeyContext (public) |
1025 |
return QString(); |
1026 |
|
1027 |
EVP_PKEY *pkey = get_pkey(); |
1028 |
+ int pkey_type = EVP_PKEY_type(EVP_PKEY_id(pkey)); |
1029 |
|
1030 |
// OpenSSL does not have DH import/export support |
1031 |
- if(pkey->type == EVP_PKEY_DH) |
1032 |
+ if(pkey_type == EVP_PKEY_DH) |
1033 |
return QString(); |
1034 |
|
1035 |
BIO *bo = BIO_new(BIO_s_mem()); |
1036 |
@@ -3110,11 +3324,18 @@ class X509Item (public) |
1037 |
crl = from.crl; |
1038 |
|
1039 |
if(cert) |
1040 |
- CRYPTO_add(&cert->references, 1, CRYPTO_LOCK_X509); |
1041 |
+ X509_up_ref(cert); |
1042 |
if(req) |
1043 |
+ { |
1044 |
+#ifdef OSSL_110 |
1045 |
+ // Not exposed, so copy |
1046 |
+ req = X509_REQ_dup(req); |
1047 |
+#else |
1048 |
CRYPTO_add(&req->references, 1, CRYPTO_LOCK_X509_REQ); |
1049 |
+#endif |
1050 |
+ } |
1051 |
if(crl) |
1052 |
- CRYPTO_add(&crl->references, 1, CRYPTO_LOCK_X509_CRL); |
1053 |
+ X509_CRL_up_ref(crl); |
1054 |
} |
1055 |
|
1056 |
return *this; |
1057 |
@@ -3220,7 +3441,7 @@ class X509Item (public) |
1058 |
// |
1059 |
// This code is mostly taken from OpenSSL v0.9.5a |
1060 |
// by Eric Young |
1061 |
-QDateTime ASN1_UTCTIME_QDateTime(ASN1_UTCTIME *tm, int *isGmt) |
1062 |
+QDateTime ASN1_UTCTIME_QDateTime(const ASN1_UTCTIME *tm, int *isGmt) |
1063 |
{ |
1064 |
QDateTime qdt; |
1065 |
char *v; |
1066 |
@@ -3318,7 +3539,7 @@ class MyCertContext : public CertContext (public) |
1067 |
|
1068 |
void fromX509(X509 *x) |
1069 |
{ |
1070 |
- CRYPTO_add(&x->references, 1, CRYPTO_LOCK_X509); |
1071 |
+ X509_up_ref(x); |
1072 |
item.cert = x; |
1073 |
make_props(); |
1074 |
} |
1075 |
@@ -3349,7 +3570,7 @@ class MyCertContext : public CertContext (public) |
1076 |
if(priv.key()->type() == PKey::RSA) |
1077 |
md = EVP_sha1(); |
1078 |
else if(priv.key()->type() == PKey::DSA) |
1079 |
- md = EVP_dss1(); |
1080 |
+ md = EVP_sha1(); |
1081 |
else |
1082 |
return false; |
1083 |
|
1084 |
@@ -3480,7 +3701,7 @@ class MyCertContext : public CertContext (public) |
1085 |
|
1086 |
const MyCertContext *our_cc = this; |
1087 |
X509 *x = our_cc->item.cert; |
1088 |
- CRYPTO_add(&x->references, 1, CRYPTO_LOCK_X509); |
1089 |
+ X509_up_ref(x); |
1090 |
sk_X509_push(untrusted_list, x); |
1091 |
|
1092 |
const MyCertContext *other_cc = static_cast<const MyCertContext *>(other); |
1093 |
@@ -3595,14 +3816,31 @@ class MyCertContext : public CertContext (public) |
1094 |
p.policies = get_cert_policies(ex); |
1095 |
} |
1096 |
|
1097 |
- if (x->signature) |
1098 |
+#if OPENSSL_VERSION_NUMBER >= 0x10002000L |
1099 |
+#ifdef OSSL_110 |
1100 |
+ const |
1101 |
+#endif |
1102 |
+ ASN1_BIT_STRING *signature; |
1103 |
+ |
1104 |
+ X509_get0_signature(&signature, NULL, x); |
1105 |
+ if(signature) |
1106 |
{ |
1107 |
+ p.sig = QByteArray(signature->length, 0); |
1108 |
+ for (int i=0; i< signature->length; i++) |
1109 |
+ p.sig[i] = signature->data[i]; |
1110 |
+ } |
1111 |
+ |
1112 |
+ switch( X509_get_signature_nid(x) ) |
1113 |
+#else |
1114 |
+ if(x->signature) |
1115 |
+ { |
1116 |
p.sig = QByteArray(x->signature->length, 0); |
1117 |
for (int i=0; i< x->signature->length; i++) |
1118 |
p.sig[i] = x->signature->data[i]; |
1119 |
} |
1120 |
|
1121 |
switch( OBJ_obj2nid(x->cert_info->signature->algorithm) ) |
1122 |
+#endif |
1123 |
{ |
1124 |
case NID_sha1WithRSAEncryption: |
1125 |
p.sigalgo = QCA::EMSA3_SHA1; |
1126 |
@@ -3634,7 +3872,11 @@ class MyCertContext : public CertContext (public) |
1127 |
p.sigalgo = QCA::EMSA3_SHA512; |
1128 |
break; |
1129 |
default: |
1130 |
+#if OPENSSL_VERSION_NUMBER >= 0x10002000L |
1131 |
+ qDebug() << "Unknown signature value: " << X509_get_signature_nid(x); |
1132 |
+#else |
1133 |
qDebug() << "Unknown signature value: " << OBJ_obj2nid(x->cert_info->signature->algorithm); |
1134 |
+#endif |
1135 |
p.sigalgo = QCA::SignatureUnknown; |
1136 |
} |
1137 |
|
1138 |
@@ -3751,7 +3993,7 @@ class MyCAContext : public CAContext (public) |
1139 |
if(privateKey -> key()->type() == PKey::RSA) |
1140 |
md = EVP_sha1(); |
1141 |
else if(privateKey -> key()->type() == PKey::DSA) |
1142 |
- md = EVP_dss1(); |
1143 |
+ md = EVP_sha1(); |
1144 |
else |
1145 |
return 0; |
1146 |
|
1147 |
@@ -3934,7 +4176,7 @@ class MyCSRContext : public CSRContext (public) |
1148 |
if(priv.key()->type() == PKey::RSA) |
1149 |
md = EVP_sha1(); |
1150 |
else if(priv.key()->type() == PKey::DSA) |
1151 |
- md = EVP_dss1(); |
1152 |
+ md = EVP_sha1(); |
1153 |
else |
1154 |
return false; |
1155 |
|
1156 |
@@ -4095,14 +4337,17 @@ class MyCSRContext : public CSRContext (public) |
1157 |
|
1158 |
sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free); |
1159 |
|
1160 |
- if (x->signature) |
1161 |
+ const ASN1_BIT_STRING *signature; |
1162 |
+ |
1163 |
+ X509_REQ_get0_signature(x, &signature, NULL); |
1164 |
+ if(signature) |
1165 |
{ |
1166 |
- p.sig = QByteArray(x->signature->length, 0); |
1167 |
- for (int i=0; i< x->signature->length; i++) |
1168 |
- p.sig[i] = x->signature->data[i]; |
1169 |
+ p.sig = QByteArray(signature->length, 0); |
1170 |
+ for (int i=0; i< signature->length; i++) |
1171 |
+ p.sig[i] = signature->data[i]; |
1172 |
} |
1173 |
|
1174 |
- switch( OBJ_obj2nid(x->sig_alg->algorithm) ) |
1175 |
+ switch( X509_REQ_get_signature_nid(x) ) |
1176 |
{ |
1177 |
case NID_sha1WithRSAEncryption: |
1178 |
p.sigalgo = QCA::EMSA3_SHA1; |
1179 |
@@ -4122,7 +4367,7 @@ class MyCSRContext : public CSRContext (public) |
1180 |
p.sigalgo = QCA::EMSA1_SHA1; |
1181 |
break; |
1182 |
default: |
1183 |
- qDebug() << "Unknown signature value: " << OBJ_obj2nid(x->sig_alg->algorithm); |
1184 |
+ qDebug() << "Unknown signature value: " << X509_REQ_get_signature_nid(x); |
1185 |
p.sigalgo = QCA::SignatureUnknown; |
1186 |
} |
1187 |
|
1188 |
@@ -4186,7 +4431,7 @@ class MyCRLContext : public CRLContext (public) |
1189 |
|
1190 |
void fromX509(X509_CRL *x) |
1191 |
{ |
1192 |
- CRYPTO_add(&x->references, 1, CRYPTO_LOCK_X509_CRL); |
1193 |
+ X509_CRL_up_ref(x); |
1194 |
item.crl = x; |
1195 |
make_props(); |
1196 |
} |
1197 |
@@ -4238,8 +4483,8 @@ class MyCRLContext : public CRLContext (public) |
1198 |
|
1199 |
for (int i = 0; i < sk_X509_REVOKED_num(revokeStack); ++i) { |
1200 |
X509_REVOKED *rev = sk_X509_REVOKED_value(revokeStack, i); |
1201 |
- BigInteger serial = bn2bi(ASN1_INTEGER_to_BN(rev->serialNumber, NULL)); |
1202 |
- QDateTime time = ASN1_UTCTIME_QDateTime( rev->revocationDate, NULL); |
1203 |
+ BigInteger serial = bn2bi(ASN1_INTEGER_to_BN(X509_REVOKED_get0_serialNumber(rev), NULL)); |
1204 |
+ QDateTime time = ASN1_UTCTIME_QDateTime( X509_REVOKED_get0_revocationDate(rev), NULL); |
1205 |
QCA::CRLEntry::Reason reason = QCA::CRLEntry::Unspecified; |
1206 |
int pos = X509_REVOKED_get_ext_by_NID(rev, NID_crl_reason, -1); |
1207 |
if (pos != -1) { |
1208 |
@@ -4288,13 +4533,18 @@ class MyCRLContext : public CRLContext (public) |
1209 |
p.revoked.append(thisEntry); |
1210 |
} |
1211 |
|
1212 |
- if (x->signature) |
1213 |
+ const ASN1_BIT_STRING *signature; |
1214 |
+ |
1215 |
+ X509_CRL_get0_signature(x, &signature, NULL); |
1216 |
+ if(signature) |
1217 |
{ |
1218 |
- p.sig = QByteArray(x->signature->length, 0); |
1219 |
- for (int i=0; i< x->signature->length; i++) |
1220 |
- p.sig[i] = x->signature->data[i]; |
1221 |
+ p.sig = QByteArray(signature->length, 0); |
1222 |
+ for (int i=0; i< signature->length; i++) |
1223 |
+ p.sig[i] = signature->data[i]; |
1224 |
} |
1225 |
- switch( OBJ_obj2nid(x->sig_alg->algorithm) ) |
1226 |
+ |
1227 |
+ |
1228 |
+ switch( X509_CRL_get_signature_nid(x) ) |
1229 |
{ |
1230 |
case NID_sha1WithRSAEncryption: |
1231 |
p.sigalgo = QCA::EMSA3_SHA1; |
1232 |
@@ -4326,7 +4576,7 @@ class MyCRLContext : public CRLContext (public) |
1233 |
p.sigalgo = QCA::EMSA3_SHA512; |
1234 |
break; |
1235 |
default: |
1236 |
- qWarning() << "Unknown signature value: " << OBJ_obj2nid(x->sig_alg->algorithm); |
1237 |
+ qWarning() << "Unknown signature value: " << X509_CRL_get_signature_nid(x); |
1238 |
p.sigalgo = QCA::SignatureUnknown; |
1239 |
} |
1240 |
|
1241 |
@@ -4487,21 +4737,21 @@ Validity MyCertContext::validate(const QList<CertConte |
1242 |
{ |
1243 |
const MyCertContext *cc = static_cast<const MyCertContext *>(trusted[n]); |
1244 |
X509 *x = cc->item.cert; |
1245 |
- CRYPTO_add(&x->references, 1, CRYPTO_LOCK_X509); |
1246 |
+ X509_up_ref(x); |
1247 |
sk_X509_push(trusted_list, x); |
1248 |
} |
1249 |
for(n = 0; n < untrusted.count(); ++n) |
1250 |
{ |
1251 |
const MyCertContext *cc = static_cast<const MyCertContext *>(untrusted[n]); |
1252 |
X509 *x = cc->item.cert; |
1253 |
- CRYPTO_add(&x->references, 1, CRYPTO_LOCK_X509); |
1254 |
+ X509_up_ref(x); |
1255 |
sk_X509_push(untrusted_list, x); |
1256 |
} |
1257 |
for(n = 0; n < crls.count(); ++n) |
1258 |
{ |
1259 |
const MyCRLContext *cc = static_cast<const MyCRLContext *>(crls[n]); |
1260 |
X509_CRL *x = cc->item.crl; |
1261 |
- CRYPTO_add(&x->references, 1, CRYPTO_LOCK_X509_CRL); |
1262 |
+ X509_CRL_up_ref(x); |
1263 |
crl_list.append(x); |
1264 |
} |
1265 |
|
1266 |
@@ -4526,7 +4776,7 @@ Validity MyCertContext::validate(const QList<CertConte |
1267 |
int ret = X509_verify_cert(ctx); |
1268 |
int err = -1; |
1269 |
if(!ret) |
1270 |
- err = ctx->error; |
1271 |
+ err = X509_STORE_CTX_get_error(ctx); |
1272 |
|
1273 |
// cleanup |
1274 |
X509_STORE_CTX_free(ctx); |
1275 |
@@ -4560,21 +4810,21 @@ Validity MyCertContext::validate_chain(const QList<Cer |
1276 |
{ |
1277 |
const MyCertContext *cc = static_cast<const MyCertContext *>(trusted[n]); |
1278 |
X509 *x = cc->item.cert; |
1279 |
- CRYPTO_add(&x->references, 1, CRYPTO_LOCK_X509); |
1280 |
+ X509_up_ref(x); |
1281 |
sk_X509_push(trusted_list, x); |
1282 |
} |
1283 |
for(n = 1; n < chain.count(); ++n) |
1284 |
{ |
1285 |
const MyCertContext *cc = static_cast<const MyCertContext *>(chain[n]); |
1286 |
X509 *x = cc->item.cert; |
1287 |
- CRYPTO_add(&x->references, 1, CRYPTO_LOCK_X509); |
1288 |
+ X509_up_ref(x); |
1289 |
sk_X509_push(untrusted_list, x); |
1290 |
} |
1291 |
for(n = 0; n < crls.count(); ++n) |
1292 |
{ |
1293 |
const MyCRLContext *cc = static_cast<const MyCRLContext *>(crls[n]); |
1294 |
X509_CRL *x = cc->item.crl; |
1295 |
- CRYPTO_add(&x->references, 1, CRYPTO_LOCK_X509_CRL); |
1296 |
+ X509_CRL_up_ref(x); |
1297 |
crl_list.append(x); |
1298 |
} |
1299 |
|
1300 |
@@ -4599,7 +4849,7 @@ Validity MyCertContext::validate_chain(const QList<Cer |
1301 |
int ret = X509_verify_cert(ctx); |
1302 |
int err = -1; |
1303 |
if(!ret) |
1304 |
- err = ctx->error; |
1305 |
+ err = X509_STORE_CTX_get_error(ctx); |
1306 |
|
1307 |
// grab the chain, which may not be fully populated |
1308 |
STACK_OF(X509) *xchain = X509_STORE_CTX_get_chain(ctx); |
1309 |
@@ -4663,7 +4913,7 @@ class MyPKCS12Context : public PKCS12Context (public) |
1310 |
for(int n = 1; n < chain.count(); ++n) |
1311 |
{ |
1312 |
X509 *x = static_cast<const MyCertContext *>(chain[n])->item.cert; |
1313 |
- CRYPTO_add(&x->references, 1, CRYPTO_LOCK_X509); |
1314 |
+ X509_up_ref(x); |
1315 |
sk_X509_push(ca, x); |
1316 |
} |
1317 |
} |
1318 |
@@ -5398,7 +5648,7 @@ class MyTLSContext : public TLSContext (public) |
1319 |
OpenSSL_add_ssl_algorithms(); |
1320 |
SSL_CTX *ctx = 0; |
1321 |
switch (version) { |
1322 |
-#ifndef OPENSSL_NO_SSL2 |
1323 |
+#if !defined(OPENSSL_NO_SSL2) && !defined(OSSL_110) |
1324 |
case TLS::SSL_v2: |
1325 |
ctx = SSL_CTX_new(SSLv2_client_method()); |
1326 |
break; |
1327 |
@@ -5429,8 +5679,8 @@ class MyTLSContext : public TLSContext (public) |
1328 |
STACK_OF(SSL_CIPHER) *sk = SSL_get_ciphers(ssl); |
1329 |
QStringList cipherList; |
1330 |
for(int i = 0; i < sk_SSL_CIPHER_num(sk); ++i) { |
1331 |
- SSL_CIPHER *thisCipher = sk_SSL_CIPHER_value(sk, i); |
1332 |
- cipherList += cipherIDtoString(version, thisCipher->id); |
1333 |
+ const SSL_CIPHER *thisCipher = sk_SSL_CIPHER_value(sk, i); |
1334 |
+ cipherList += cipherIDtoString(version, SSL_CIPHER_get_id(thisCipher)); |
1335 |
} |
1336 |
|
1337 |
SSL_free(ssl); |
1338 |
@@ -5807,13 +6057,15 @@ class MyTLSContext : public TLSContext (public) |
1339 |
{ |
1340 |
SessionInfo sessInfo; |
1341 |
|
1342 |
- sessInfo.isCompressed = (0 != SSL_SESSION_get_compress_id(ssl->session)); |
1343 |
+ SSL_SESSION *session = SSL_get0_session(ssl); |
1344 |
+ sessInfo.isCompressed = (0 != SSL_SESSION_get_compress_id(session)); |
1345 |
+ int ssl_version = SSL_version(ssl); |
1346 |
|
1347 |
- if (ssl->version == TLS1_VERSION) |
1348 |
+ if (ssl_version == TLS1_VERSION) |
1349 |
sessInfo.version = TLS::TLS_v1; |
1350 |
- else if (ssl->version == SSL3_VERSION) |
1351 |
+ else if (ssl_version == SSL3_VERSION) |
1352 |
sessInfo.version = TLS::SSL_v3; |
1353 |
- else if (ssl->version == SSL2_VERSION) |
1354 |
+ else if (ssl_version == SSL2_VERSION) |
1355 |
sessInfo.version = TLS::SSL_v2; |
1356 |
else { |
1357 |
qDebug("unexpected version response"); |
1358 |
@@ -5821,7 +6073,7 @@ class MyTLSContext : public TLSContext (public) |
1359 |
} |
1360 |
|
1361 |
sessInfo.cipherSuite = cipherIDtoString( sessInfo.version, |
1362 |
- SSL_get_current_cipher(ssl)->id); |
1363 |
+ SSL_CIPHER_get_id(SSL_get_current_cipher(ssl))); |
1364 |
|
1365 |
sessInfo.cipherMaxBits = SSL_get_cipher_bits(ssl, &(sessInfo.cipherBits)); |
1366 |
|
1367 |
@@ -6393,7 +6645,7 @@ class MyMessageContext : public MessageContext (public |
1368 |
for(int n = 0; n < nonroots.count(); ++n) |
1369 |
{ |
1370 |
X509 *x = static_cast<MyCertContext *>(nonroots[n].context())->item.cert; |
1371 |
- CRYPTO_add(&x->references, 1, CRYPTO_LOCK_X509); |
1372 |
+ X509_up_ref(x); |
1373 |
sk_X509_push(other_certs, x); |
1374 |
} |
1375 |
|
1376 |
@@ -6435,7 +6687,7 @@ class MyMessageContext : public MessageContext (public |
1377 |
|
1378 |
other_certs = sk_X509_new_null(); |
1379 |
X509 *x = static_cast<MyCertContext *>(target.context())->item.cert; |
1380 |
- CRYPTO_add(&x->references, 1, CRYPTO_LOCK_X509); |
1381 |
+ X509_up_ref(x); |
1382 |
sk_X509_push(other_certs, x); |
1383 |
|
1384 |
bi = BIO_new(BIO_s_mem()); |
1385 |
@@ -6498,7 +6750,7 @@ class MyMessageContext : public MessageContext (public |
1386 |
for(int n = 0; n < untrusted_list.count(); ++n) |
1387 |
{ |
1388 |
X509 *x = static_cast<MyCertContext *>(untrusted_list[n].context())->item.cert; |
1389 |
- CRYPTO_add(&x->references, 1, CRYPTO_LOCK_X509); |
1390 |
+ X509_up_ref(x); |
1391 |
sk_X509_push(other_certs, x); |
1392 |
} |
1393 |
|
1394 |
@@ -6749,14 +7001,27 @@ class opensslCipherContext : public CipherContext (pub |
1395 |
opensslCipherContext(const EVP_CIPHER *algorithm, const int pad, Provider *p, const QString &type) : CipherContext(p, type) |
1396 |
{ |
1397 |
m_cryptoAlgorithm = algorithm; |
1398 |
- EVP_CIPHER_CTX_init(&m_context); |
1399 |
+ m_context = EVP_CIPHER_CTX_new(); |
1400 |
+ EVP_CIPHER_CTX_init(m_context); |
1401 |
m_pad = pad; |
1402 |
m_type = type; |
1403 |
} |
1404 |
|
1405 |
+ opensslCipherContext(const opensslCipherContext &other) |
1406 |
+ : CipherContext(other) |
1407 |
+ { |
1408 |
+ m_cryptoAlgorithm = other.m_cryptoAlgorithm; |
1409 |
+ m_context = EVP_CIPHER_CTX_new(); |
1410 |
+ EVP_CIPHER_CTX_copy(m_context, other.m_context); |
1411 |
+ m_direction = other.m_direction; |
1412 |
+ m_pad = other.m_pad; |
1413 |
+ m_type = other.m_type; |
1414 |
+ } |
1415 |
+ |
1416 |
~opensslCipherContext() |
1417 |
{ |
1418 |
- EVP_CIPHER_CTX_cleanup(&m_context); |
1419 |
+ EVP_CIPHER_CTX_cleanup(m_context); |
1420 |
+ EVP_CIPHER_CTX_free(m_context); |
1421 |
} |
1422 |
|
1423 |
void setup(Direction dir, |
1424 |
@@ -6769,20 +7034,20 @@ class opensslCipherContext : public CipherContext (pub |
1425 |
m_cryptoAlgorithm = EVP_des_ede(); |
1426 |
} |
1427 |
if (Encode == m_direction) { |
1428 |
- EVP_EncryptInit_ex(&m_context, m_cryptoAlgorithm, 0, 0, 0); |
1429 |
- EVP_CIPHER_CTX_set_key_length(&m_context, key.size()); |
1430 |
- EVP_EncryptInit_ex(&m_context, 0, 0, |
1431 |
+ EVP_EncryptInit_ex(m_context, m_cryptoAlgorithm, 0, 0, 0); |
1432 |
+ EVP_CIPHER_CTX_set_key_length(m_context, key.size()); |
1433 |
+ EVP_EncryptInit_ex(m_context, 0, 0, |
1434 |
(const unsigned char*)(key.data()), |
1435 |
(const unsigned char*)(iv.data())); |
1436 |
} else { |
1437 |
- EVP_DecryptInit_ex(&m_context, m_cryptoAlgorithm, 0, 0, 0); |
1438 |
- EVP_CIPHER_CTX_set_key_length(&m_context, key.size()); |
1439 |
- EVP_DecryptInit_ex(&m_context, 0, 0, |
1440 |
+ EVP_DecryptInit_ex(m_context, m_cryptoAlgorithm, 0, 0, 0); |
1441 |
+ EVP_CIPHER_CTX_set_key_length(m_context, key.size()); |
1442 |
+ EVP_DecryptInit_ex(m_context, 0, 0, |
1443 |
(const unsigned char*)(key.data()), |
1444 |
(const unsigned char*)(iv.data())); |
1445 |
} |
1446 |
|
1447 |
- EVP_CIPHER_CTX_set_padding(&m_context, m_pad); |
1448 |
+ EVP_CIPHER_CTX_set_padding(m_context, m_pad); |
1449 |
} |
1450 |
|
1451 |
Provider::Context *clone() const |
1452 |
@@ -6792,7 +7057,7 @@ class opensslCipherContext : public CipherContext (pub |
1453 |
|
1454 |
int blockSize() const |
1455 |
{ |
1456 |
- return EVP_CIPHER_CTX_block_size(&m_context); |
1457 |
+ return EVP_CIPHER_CTX_block_size(m_context); |
1458 |
} |
1459 |
|
1460 |
bool update(const SecureArray &in, SecureArray *out) |
1461 |
@@ -6805,7 +7070,7 @@ class opensslCipherContext : public CipherContext (pub |
1462 |
out->resize(in.size()+blockSize()); |
1463 |
int resultLength; |
1464 |
if (Encode == m_direction) { |
1465 |
- if (0 == EVP_EncryptUpdate(&m_context, |
1466 |
+ if (0 == EVP_EncryptUpdate(m_context, |
1467 |
(unsigned char*)out->data(), |
1468 |
&resultLength, |
1469 |
(unsigned char*)in.data(), |
1470 |
@@ -6813,7 +7078,7 @@ class opensslCipherContext : public CipherContext (pub |
1471 |
return false; |
1472 |
} |
1473 |
} else { |
1474 |
- if (0 == EVP_DecryptUpdate(&m_context, |
1475 |
+ if (0 == EVP_DecryptUpdate(m_context, |
1476 |
(unsigned char*)out->data(), |
1477 |
&resultLength, |
1478 |
(unsigned char*)in.data(), |
1479 |
@@ -6830,13 +7095,13 @@ class opensslCipherContext : public CipherContext (pub |
1480 |
out->resize(blockSize()); |
1481 |
int resultLength; |
1482 |
if (Encode == m_direction) { |
1483 |
- if (0 == EVP_EncryptFinal_ex(&m_context, |
1484 |
+ if (0 == EVP_EncryptFinal_ex(m_context, |
1485 |
(unsigned char*)out->data(), |
1486 |
&resultLength)) { |
1487 |
return false; |
1488 |
} |
1489 |
} else { |
1490 |
- if (0 == EVP_DecryptFinal_ex(&m_context, |
1491 |
+ if (0 == EVP_DecryptFinal_ex(m_context, |
1492 |
(unsigned char*)out->data(), |
1493 |
&resultLength)) { |
1494 |
return false; |
1495 |
@@ -6871,7 +7136,7 @@ class opensslCipherContext : public CipherContext (pub |
1496 |
|
1497 |
|
1498 |
protected: |
1499 |
- EVP_CIPHER_CTX m_context; |
1500 |
+ EVP_CIPHER_CTX *m_context; |
1501 |
const EVP_CIPHER *m_cryptoAlgorithm; |
1502 |
Direction m_direction; |
1503 |
int m_pad; |