Line 0
Link Here
|
|
|
1 |
From d58e20ee652038dc4ec4fe4765dc3639ed735526 Mon Sep 17 00:00:00 2001 |
2 |
From: Fabian Vogt <fabian@ritter-vogt.de> |
3 |
Date: Sat, 16 Dec 2017 22:29:40 +0100 |
4 |
Subject: Add support for OpenSSL 1.1.0 |
5 |
|
6 |
Test Plan: |
7 |
Ran the testsuite with OpenSSL 1.1.0g and 1.0.2j, all passed. |
8 |
Using this code with kdeconnect and okteta successfully on my system now. |
9 |
|
10 |
Reviewers: iromanov |
11 |
|
12 |
Subscribers: anthonyfieroni, alonbl, heikobecker, cfeck, asturmlechner, bero, rdieter |
13 |
|
14 |
Differential Revision: https://phabricator.kde.org/D9416 |
15 |
--- plugins/qca-ossl/ossl110-compat.h.orig 2018-02-14 20:19:15 UTC |
16 |
+++ plugins/qca-ossl/ossl110-compat.h |
17 |
@@ -0,0 +1,283 @@ |
18 |
+/* |
19 |
+ * Copyright (C) 2017 Gabriel Souza Franco <gabrielfrancosouza@gmail.com> |
20 |
+ * |
21 |
+ * This library is free software; you can redistribute it and/or |
22 |
+ * modify it under the terms of the GNU Lesser General Public |
23 |
+ * License as published by the Free Software Foundation; either |
24 |
+ * version 2.1 of the License, or (at your option) any later version. |
25 |
+ * |
26 |
+ * This library is distributed in the hope that it will be useful, |
27 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
28 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
29 |
+ * Lesser General Public License for more details. |
30 |
+ * |
31 |
+ * You should have received a copy of the GNU Lesser General Public |
32 |
+ * License along with this library; if not, write to the Free Software |
33 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
34 |
+ * |
35 |
+ */ |
36 |
+ |
37 |
+#ifndef OSSL110COMPAT_H |
38 |
+#define OSSL110COMPAT_H |
39 |
+ |
40 |
+#include <openssl/evp.h> |
41 |
+#include <openssl/hmac.h> |
42 |
+#include <openssl/rsa.h> |
43 |
+#include <openssl/dsa.h> |
44 |
+ |
45 |
+#if OPENSSL_VERSION_NUMBER < 0x10100000L |
46 |
+#define RSA_F_RSA_METH_DUP 161 |
47 |
+ |
48 |
+static void DSA_SIG_get0(const DSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps) |
49 |
+{ |
50 |
+ if (pr) |
51 |
+ *pr = sig->r; |
52 |
+ if (ps) |
53 |
+ *ps = sig->s; |
54 |
+} |
55 |
+ |
56 |
+static int DSA_SIG_set0(DSA_SIG *sig, BIGNUM *r, BIGNUM *s) |
57 |
+{ |
58 |
+ if (!sig) return 0; |
59 |
+ sig->r = r; |
60 |
+ sig->s = s; |
61 |
+ return 1; |
62 |
+} |
63 |
+ |
64 |
+static void DSA_get0_pqg(const DSA *dsa, const BIGNUM **p, const BIGNUM **q, const BIGNUM **g) |
65 |
+{ |
66 |
+ if (p) |
67 |
+ *p = dsa->p; |
68 |
+ if (q) |
69 |
+ *q = dsa->q; |
70 |
+ if (g) |
71 |
+ *g = dsa->g; |
72 |
+} |
73 |
+ |
74 |
+static int DSA_set0_pqg(DSA *dsa, BIGNUM *p, BIGNUM *q, BIGNUM *g) |
75 |
+{ |
76 |
+ if (!dsa) return 0; |
77 |
+ dsa->p = p; |
78 |
+ dsa->q = q; |
79 |
+ dsa->g = g; |
80 |
+ return 1; |
81 |
+} |
82 |
+ |
83 |
+static void RSA_get0_key(const RSA *rsa, const BIGNUM **n, const BIGNUM **e, const BIGNUM **d) |
84 |
+{ |
85 |
+ if (n) |
86 |
+ *n = rsa->n; |
87 |
+ if (e) |
88 |
+ *e = rsa->e; |
89 |
+ if (d) |
90 |
+ *d = rsa->d; |
91 |
+} |
92 |
+ |
93 |
+static int RSA_set0_key(RSA *rsa, BIGNUM *n, BIGNUM *e, BIGNUM *d) |
94 |
+{ |
95 |
+ if (!rsa) return 0; |
96 |
+ rsa->n = n; |
97 |
+ rsa->e = e; |
98 |
+ rsa->d = d; |
99 |
+ return 1; |
100 |
+} |
101 |
+ |
102 |
+static void RSA_get0_factors(const RSA *rsa, const BIGNUM **p, const BIGNUM **q) |
103 |
+{ |
104 |
+ if (p) |
105 |
+ *p = rsa->p; |
106 |
+ if (q) |
107 |
+ *q = rsa->q; |
108 |
+} |
109 |
+ |
110 |
+static int RSA_set0_factors(RSA *rsa, BIGNUM *p, BIGNUM *q) |
111 |
+{ |
112 |
+ if (!rsa) return 0; |
113 |
+ rsa->p = p; |
114 |
+ rsa->q = q; |
115 |
+ return 1; |
116 |
+} |
117 |
+ |
118 |
+static void DH_get0_pqg(const DH *dh, const BIGNUM **p, const BIGNUM **q, const BIGNUM **g) |
119 |
+{ |
120 |
+ if (p) |
121 |
+ *p = dh->p; |
122 |
+ if (q) |
123 |
+ *q = dh->q; |
124 |
+ if (g) |
125 |
+ *g = dh->g; |
126 |
+} |
127 |
+ |
128 |
+static int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g) |
129 |
+{ |
130 |
+ if (!dh) return 0; |
131 |
+ dh->p = p; |
132 |
+ dh->q = q; |
133 |
+ dh->g = g; |
134 |
+ return 1; |
135 |
+} |
136 |
+ |
137 |
+static void DH_get0_key(const DH *dh, const BIGNUM **pub_key, const BIGNUM **priv_key) |
138 |
+{ |
139 |
+ if (pub_key) |
140 |
+ *pub_key = dh->pub_key; |
141 |
+ if (priv_key) |
142 |
+ *priv_key = dh->priv_key; |
143 |
+} |
144 |
+ |
145 |
+static int DH_set0_key(DH *dh, BIGNUM *pub_key, BIGNUM *priv_key) |
146 |
+{ |
147 |
+ if (!dh) return 0; |
148 |
+ dh->pub_key = pub_key; |
149 |
+ dh->priv_key = priv_key; |
150 |
+ return 1; |
151 |
+} |
152 |
+ |
153 |
+static void DSA_get0_key(const DSA *dsa, const BIGNUM **pub_key, const BIGNUM **priv_key) |
154 |
+{ |
155 |
+ if (pub_key) |
156 |
+ *pub_key = dsa->pub_key; |
157 |
+ if (priv_key) |
158 |
+ *priv_key = dsa->priv_key; |
159 |
+} |
160 |
+ |
161 |
+static int DSA_set0_key(DSA *dsa, BIGNUM *pub_key, BIGNUM *priv_key) |
162 |
+{ |
163 |
+ if (!dsa) return 0; |
164 |
+ dsa->pub_key = pub_key; |
165 |
+ dsa->priv_key = priv_key; |
166 |
+ return 1; |
167 |
+} |
168 |
+ |
169 |
+static void X509_SIG_getm(const X509_SIG *sig, X509_ALGOR **palg, ASN1_OCTET_STRING **pdigest) |
170 |
+{ |
171 |
+ if (palg) |
172 |
+ *palg = sig->algor; |
173 |
+ if (pdigest) |
174 |
+ *pdigest = sig->digest; |
175 |
+} |
176 |
+ |
177 |
+static void X509_REQ_get0_signature(const X509_REQ *req, const ASN1_BIT_STRING **psig, const X509_ALGOR **palg) |
178 |
+{ |
179 |
+ if (psig) |
180 |
+ *psig = req->signature; |
181 |
+ if (palg) |
182 |
+ *palg = req->sig_alg; |
183 |
+} |
184 |
+ |
185 |
+static void X509_CRL_get0_signature(const X509_CRL *crl, const ASN1_BIT_STRING **psig, const X509_ALGOR **palg) |
186 |
+{ |
187 |
+ if (psig) |
188 |
+ *psig = crl->signature; |
189 |
+ if (palg) |
190 |
+ *palg = crl->sig_alg; |
191 |
+} |
192 |
+ |
193 |
+static RSA_METHOD *RSA_meth_dup(const RSA_METHOD *meth) |
194 |
+{ |
195 |
+ if (!meth) |
196 |
+ return NULL; |
197 |
+ |
198 |
+ RSA_METHOD *_meth = (RSA_METHOD *) OPENSSL_malloc(sizeof(*_meth)); |
199 |
+ |
200 |
+ if (!_meth) |
201 |
+ { |
202 |
+ RSAerr(RSA_F_RSA_METH_DUP, ERR_R_MALLOC_FAILURE); |
203 |
+ return NULL; |
204 |
+ } |
205 |
+ |
206 |
+ memcpy(_meth, meth, sizeof(*_meth)); |
207 |
+ _meth->name = strdup(meth->name); |
208 |
+ if (!_meth->name) { |
209 |
+ OPENSSL_free(_meth); |
210 |
+ RSAerr(RSA_F_RSA_METH_DUP, ERR_R_MALLOC_FAILURE); |
211 |
+ return NULL; |
212 |
+ } |
213 |
+ |
214 |
+ return _meth; |
215 |
+} |
216 |
+ |
217 |
+static int RSA_meth_set_priv_enc(RSA_METHOD *rsa, int (*priv_enc) (int flen, const unsigned char *from, |
218 |
+ unsigned char *to, RSA *rsa, int padding)) |
219 |
+{ |
220 |
+ if (!rsa) return 0; |
221 |
+ rsa->rsa_priv_enc = priv_enc; |
222 |
+ return 1; |
223 |
+} |
224 |
+ |
225 |
+static int RSA_meth_set_priv_dec(RSA_METHOD *rsa, int (*priv_dec) (int flen, const unsigned char *from, |
226 |
+ unsigned char *to, RSA *rsa, int padding)) |
227 |
+{ |
228 |
+ if (!rsa) return 0; |
229 |
+ rsa->rsa_priv_dec = priv_dec; |
230 |
+ return 1; |
231 |
+} |
232 |
+ |
233 |
+static int RSA_meth_set_sign(RSA_METHOD *meth, int (*sign) (int type, const unsigned char *m, |
234 |
+ unsigned int m_length, unsigned char *sigret, unsigned int *siglen, const RSA *rsa)) |
235 |
+{ |
236 |
+ if (!meth) return 0; |
237 |
+ meth->rsa_sign = sign; |
238 |
+ return 1; |
239 |
+} |
240 |
+ |
241 |
+static int RSA_meth_set_verify(RSA_METHOD *meth, int (*verify) (int dtype, const unsigned char *m, |
242 |
+ unsigned int m_length, const unsigned char *sigbuf, unsigned int siglen, const RSA *rsa)) |
243 |
+{ |
244 |
+ if (!meth) return 0; |
245 |
+ meth->rsa_verify = verify; |
246 |
+ return 1; |
247 |
+} |
248 |
+ |
249 |
+static int RSA_meth_set_finish(RSA_METHOD *meth, int (*finish) (RSA *rsa)) |
250 |
+{ |
251 |
+ if (!meth) return 0; |
252 |
+ meth->finish = finish; |
253 |
+ return 1; |
254 |
+} |
255 |
+ |
256 |
+static HMAC_CTX *HMAC_CTX_new() |
257 |
+{ |
258 |
+ HMAC_CTX *ctx = (HMAC_CTX *) OPENSSL_malloc(sizeof(HMAC_CTX)); |
259 |
+ if (ctx) |
260 |
+ HMAC_CTX_init(ctx); |
261 |
+ return ctx; |
262 |
+} |
263 |
+ |
264 |
+static void HMAC_CTX_free(HMAC_CTX *ctx) |
265 |
+{ |
266 |
+ if (!ctx) |
267 |
+ return; |
268 |
+ HMAC_CTX_cleanup(ctx); |
269 |
+ EVP_MD_CTX_cleanup(&ctx->i_ctx); |
270 |
+ EVP_MD_CTX_cleanup(&ctx->o_ctx); |
271 |
+ EVP_MD_CTX_cleanup(&ctx->md_ctx); |
272 |
+ OPENSSL_free(ctx); |
273 |
+} |
274 |
+ |
275 |
+#define ASN1_STRING_get0_data(...) (const unsigned char*)ASN1_STRING_data(__VA_ARGS__) |
276 |
+ |
277 |
+#define EVP_MD_CTX_new(...) EVP_MD_CTX_create(__VA_ARGS__) |
278 |
+#define EVP_MD_CTX_free(...) EVP_MD_CTX_destroy(__VA_ARGS__) |
279 |
+ |
280 |
+#define EVP_PKEY_up_ref(pkey) CRYPTO_add(&(pkey)->references, 1, CRYPTO_LOCK_EVP_PKEY) |
281 |
+#define X509_up_ref(cert) CRYPTO_add(&(cert)->references, 1, CRYPTO_LOCK_X509) |
282 |
+#define X509_CRL_up_ref(crl) CRYPTO_add(&(crl)->references, 1, CRYPTO_LOCK_X509_CRL) |
283 |
+ |
284 |
+#define EVP_PKEY_id(pky) (pky)->type |
285 |
+#define EVP_PKEY_get0_DSA(pky) (pky)->pkey.dsa |
286 |
+#define EVP_PKEY_get0_RSA(pky) (pky)->pkey.rsa |
287 |
+#define EVP_PKEY_get0_DH(pky) (pky)->pkey.dh |
288 |
+ |
289 |
+#define X509_CRL_get0_lastUpdate X509_CRL_get_lastUpdate |
290 |
+#define X509_CRL_get0_nextUpdate X509_CRL_get_nextUpdate |
291 |
+ |
292 |
+#define X509_REQ_get_signature_nid(req) OBJ_obj2nid((req)->sig_alg->algorithm) |
293 |
+#define X509_CRL_get_signature_nid(crl) OBJ_obj2nid((crl)->sig_alg->algorithm) |
294 |
+ |
295 |
+#define X509_REVOKED_get0_serialNumber(rev) (rev)->serialNumber |
296 |
+#define X509_REVOKED_get0_revocationDate(rev) (rev)->revocationDate |
297 |
+ |
298 |
+#endif // OPENSSL_VERSION_NUMBER < 0x10100000L |
299 |
+ |
300 |
+#endif // OSSL110COMPAT_H |