summaryrefslogtreecommitdiff
path: root/libre/kopete/kopete-openssl-1.1.patch
blob: 1d34e0e5c046dcf6f19f5732dd0c19e76f0ef2f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
diff -ur kopete-17.08.3/protocols/jabber/libjingle/talk/base/openssladapter.cc kopete-17.08.3-openssl-1.1/protocols/jabber/libjingle/talk/base/openssladapter.cc
--- kopete-17.08.3/protocols/jabber/libjingle/talk/base/openssladapter.cc	2017-09-30 12:08:16.000000000 +0200
+++ kopete-17.08.3-openssl-1.1/protocols/jabber/libjingle/talk/base/openssladapter.cc	2018-01-05 22:49:27.805070408 +0100
@@ -84,6 +84,7 @@
 static int socket_new(BIO* h);
 static int socket_free(BIO* data);
 
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
 static BIO_METHOD methods_socket = {
   BIO_TYPE_BIO,
   "socket",
@@ -98,16 +99,40 @@
 };
 
 BIO_METHOD* BIO_s_socket2() { return(&methods_socket); }
+#else
+static BIO_METHOD *methods_socket = NULL;
+
+static const BIO_METHOD * BIO_s_socket2(void) {
+  if (methods_socket == NULL) {
+      methods_socket = BIO_meth_new (BIO_TYPE_BIO | BIO_get_new_index (), "socket");
+      if (methods_socket == NULL ||
+          BIO_meth_set_write (methods_socket, socket_write) ||
+          BIO_meth_set_read (methods_socket, socket_read) ||
+          BIO_meth_set_puts (methods_socket, socket_puts) ||
+          BIO_meth_set_gets (methods_socket, 0) ||
+          BIO_meth_set_ctrl (methods_socket, socket_ctrl) ||
+          BIO_meth_set_create (methods_socket, socket_new) ||
+          BIO_meth_set_destroy (methods_socket, socket_free))
+      return NULL;
+    }
+  return methods_socket;
+}
+#endif
 
 BIO* BIO_new_socket(talk_base::AsyncSocket* socket) {
+  const BIO_METHOD *socket2 = BIO_s_socket2();
+  if (socket2 == NULL) {
+          return NULL;
+  }
-  BIO* ret = BIO_new(BIO_s_socket2());
+  BIO* ret = BIO_new(socket2);
   if (ret == NULL) {
           return NULL;
   }
-  ret->ptr = socket;
+  BIO_set_data(ret, socket);
   return ret;
 }
 
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
 static int socket_new(BIO* b) {
   b->shutdown = 0;
   b->init = 1;
@@ -115,6 +136,14 @@
   b->ptr = 0;
   return 1;
 }
+#else
+static int socket_new(BIO* b) {
+  BIO_set_shutdown(b, 0);
+  BIO_set_init(b, 1);
+  BIO_set_data(b, 0);
+  return 1;
+}
+#endif
 
 static int socket_free(BIO* b) {
   if (b == NULL)
@@ -125,13 +154,11 @@
 static int socket_read(BIO* b, char* out, int outl) {
   if (!out)
     return -1;
-  talk_base::AsyncSocket* socket = static_cast<talk_base::AsyncSocket*>(b->ptr);
+  talk_base::AsyncSocket* socket = static_cast<talk_base::AsyncSocket*>(BIO_get_data(b));
   BIO_clear_retry_flags(b);
   int result = socket->Recv(out, outl);
   if (result > 0) {
     return result;
-  } else if (result == 0) {
-    b->num = 1;
   } else if (socket->IsBlocking()) {
     BIO_set_retry_read(b);
   }
@@ -141,7 +168,7 @@
 static int socket_write(BIO* b, const char* in, int inl) {
   if (!in)
     return -1;
-  talk_base::AsyncSocket* socket = static_cast<talk_base::AsyncSocket*>(b->ptr);
+  talk_base::AsyncSocket* socket = static_cast<talk_base::AsyncSocket*>(BIO_get_data(b));
   BIO_clear_retry_flags(b);
   int result = socket->Send(in, inl);
   if (result > 0) {
@@ -164,7 +191,6 @@
   case BIO_CTRL_RESET:
     return 0;
   case BIO_CTRL_EOF:
-    return b->num;
   case BIO_CTRL_WPENDING:
   case BIO_CTRL_PENDING:
     return 0;
@@ -696,7 +722,9 @@
       // We assign this to a local variable, instead of passing the address
       // directly to ASN1_item_d2i.
       // See http://readlist.com/lists/openssl.org/openssl-users/0/4761.html.
-      unsigned char* ext_value_data = extension->value->data;
+      ASN1_OCTET_STRING *extension_data = X509_EXTENSION_get_data(extension);
+      unsigned char* ext_value_data = extension_data->data;
+      long length = extension_data->length;
 
 #if OPENSSL_VERSION_NUMBER >= 0x0090800fL
       const unsigned char **ext_value_data_ptr =
@@ -707,10 +735,10 @@
 
       if (meth->it) {
         ext_str = ASN1_item_d2i(NULL, ext_value_data_ptr,
-                                extension->value->length,
+                                length,
                                 ASN1_ITEM_ptr(meth->it));
       } else {
-        ext_str = meth->d2i(NULL, ext_value_data_ptr, extension->value->length);
+        ext_str = meth->d2i(NULL, ext_value_data_ptr, length);
       }
 
       STACK_OF(CONF_VALUE)* value = meth->i2v(meth, ext_str, NULL);
diff -ur kopete-17.08.3/protocols/jabber/libjingle/talk/base/openssldigest.cc kopete-17.08.3-openssl-1.1/protocols/jabber/libjingle/talk/base/openssldigest.cc
--- kopete-17.08.3/protocols/jabber/libjingle/talk/base/openssldigest.cc	2017-09-30 12:08:16.000000000 +0200
+++ kopete-17.08.3-openssl-1.1/protocols/jabber/libjingle/talk/base/openssldigest.cc	2018-01-05 22:49:27.869069361 +0100
@@ -32,16 +32,16 @@
 namespace talk_base {
 
 OpenSSLDigest::OpenSSLDigest(const std::string& algorithm) {
-  EVP_MD_CTX_init(&ctx_);
+  EVP_MD_CTX_init(ctx_);
   if (GetDigestEVP(algorithm, &md_)) {
-    EVP_DigestInit_ex(&ctx_, md_, NULL);
+    EVP_DigestInit_ex(ctx_, md_, NULL);
   } else {
     md_ = NULL;
   }
 }
 
 OpenSSLDigest::~OpenSSLDigest() {
-  EVP_MD_CTX_cleanup(&ctx_);
+  EVP_MD_CTX_destroy(ctx_);
 }
 
 size_t OpenSSLDigest::Size() const {
@@ -55,7 +55,7 @@
   if (!md_) {
     return;
   }
-  EVP_DigestUpdate(&ctx_, buf, len);
+  EVP_DigestUpdate(ctx_, buf, len);
 }
 
 size_t OpenSSLDigest::Finish(void* buf, size_t len) {
@@ -63,8 +63,8 @@
     return 0;
   }
   unsigned int md_len;
-  EVP_DigestFinal_ex(&ctx_, static_cast<unsigned char*>(buf), &md_len);
-  EVP_DigestInit_ex(&ctx_, md_, NULL);  // prepare for future Update()s
+  EVP_DigestFinal_ex(ctx_, static_cast<unsigned char*>(buf), &md_len);
+  EVP_DigestInit_ex(ctx_, md_, NULL);  // prepare for future Update()s
   ASSERT(md_len == Size());
   return md_len;
 }
diff -ur kopete-17.08.3/protocols/jabber/libjingle/talk/base/openssldigest.h kopete-17.08.3-openssl-1.1/protocols/jabber/libjingle/talk/base/openssldigest.h
--- kopete-17.08.3/protocols/jabber/libjingle/talk/base/openssldigest.h	2017-09-30 12:08:16.000000000 +0200
+++ kopete-17.08.3-openssl-1.1/protocols/jabber/libjingle/talk/base/openssldigest.h	2018-01-05 22:49:27.869069361 +0100
@@ -55,7 +55,7 @@
                             size_t* len);
 
  private:
-  EVP_MD_CTX ctx_;
+  EVP_MD_CTX* ctx_ = EVP_MD_CTX_create();
   const EVP_MD* md_;
 };
 
diff -ur kopete-17.08.3/protocols/jabber/libjingle/talk/base/opensslidentity.cc kopete-17.08.3-openssl-1.1/protocols/jabber/libjingle/talk/base/opensslidentity.cc
--- kopete-17.08.3/protocols/jabber/libjingle/talk/base/opensslidentity.cc	2017-09-30 12:08:16.000000000 +0200
+++ kopete-17.08.3-openssl-1.1/protocols/jabber/libjingle/talk/base/opensslidentity.cc	2018-01-05 22:49:27.867069394 +0100
@@ -169,7 +169,12 @@
 }
 
 void OpenSSLKeyPair::AddReference() {
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
   CRYPTO_add(&pkey_->references, 1, CRYPTO_LOCK_EVP_PKEY);
+#else
+  EVP_PKEY_up_ref(pkey_);
+#endif
+
 }
 
 #ifdef _DEBUG
@@ -275,7 +280,11 @@
 }
 
 void OpenSSLCertificate::AddReference() {
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
   CRYPTO_add(&x509_->references, 1, CRYPTO_LOCK_X509);
+#else
+  X509_up_ref(x509_);
+#endif
 }
 
 OpenSSLIdentity* OpenSSLIdentity::Generate(const std::string& common_name) {
diff -ur kopete-17.08.3/protocols/jabber/libjingle/talk/base/opensslstreamadapter.cc kopete-17.08.3-openssl-1.1/protocols/jabber/libjingle/talk/base/opensslstreamadapter.cc
--- kopete-17.08.3/protocols/jabber/libjingle/talk/base/opensslstreamadapter.cc	2017-09-30 12:08:16.000000000 +0200
+++ kopete-17.08.3-openssl-1.1/protocols/jabber/libjingle/talk/base/opensslstreamadapter.cc	2018-01-05 22:49:27.868069378 +0100
@@ -87,6 +87,7 @@
 static int stream_new(BIO* h);
 static int stream_free(BIO* data);
 
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
 static BIO_METHOD methods_stream = {
   BIO_TYPE_BIO,
   "stream",
@@ -101,17 +102,37 @@
 };
 
 static BIO_METHOD* BIO_s_stream() { return(&methods_stream); }
+#else
+static BIO_METHOD *methods_stream = NULL;
+
+static const BIO_METHOD * BIO_s_stream(void) {
+  if (methods_stream == NULL) {
+      methods_stream = BIO_meth_new (BIO_TYPE_BIO | BIO_get_new_index (), "stream");
+      if (methods_stream == NULL ||
+          BIO_meth_set_write (methods_stream, stream_write) ||
+          BIO_meth_set_read (methods_stream, stream_read) ||
+          BIO_meth_set_puts (methods_stream, stream_puts) ||
+          BIO_meth_set_gets (methods_stream, 0) ||
+          BIO_meth_set_ctrl (methods_stream, stream_ctrl) ||
+          BIO_meth_set_create (methods_stream, stream_new) ||
+          BIO_meth_set_destroy (methods_stream, stream_free))
+      return NULL;
+    }
+  return methods_stream;
+}
+#endif
 
 static BIO* BIO_new_stream(StreamInterface* stream) {
   BIO* ret = BIO_new(BIO_s_stream());
   if (ret == NULL)
     return NULL;
-  ret->ptr = stream;
+  BIO_set_data(ret, stream);
   return ret;
 }
 
 // bio methods return 1 (or at least non-zero) on success and 0 on failure.
 
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
 static int stream_new(BIO* b) {
   b->shutdown = 0;
   b->init = 1;
@@ -119,6 +140,14 @@
   b->ptr = 0;
   return 1;
 }
+#else
+static int stream_new(BIO* b) {
+  BIO_set_shutdown(b, 0);
+  BIO_set_init(b, 1);
+  BIO_set_data(b, 0);
+  return 1;
+}
+#endif
 
 static int stream_free(BIO* b) {
   if (b == NULL)
@@ -129,15 +158,13 @@
 static int stream_read(BIO* b, char* out, int outl) {
   if (!out)
     return -1;
-  StreamInterface* stream = static_cast<StreamInterface*>(b->ptr);
+  StreamInterface* stream = static_cast<StreamInterface*>(BIO_get_data(b));
   BIO_clear_retry_flags(b);
   size_t read;
   int error;
   StreamResult result = stream->Read(out, outl, &read, &error);
   if (result == SR_SUCCESS) {
     return read;
-  } else if (result == SR_EOS) {
-    b->num = 1;
   } else if (result == SR_BLOCK) {
     BIO_set_retry_read(b);
   }
@@ -147,7 +174,7 @@
 static int stream_write(BIO* b, const char* in, int inl) {
   if (!in)
     return -1;
-  StreamInterface* stream = static_cast<StreamInterface*>(b->ptr);
+  StreamInterface* stream = static_cast<StreamInterface*>(BIO_get_data(b));
   BIO_clear_retry_flags(b);
   size_t written;
   int error;
@@ -172,7 +199,6 @@
     case BIO_CTRL_RESET:
       return 0;
     case BIO_CTRL_EOF:
-      return b->num;
     case BIO_CTRL_WPENDING:
     case BIO_CTRL_PENDING:
       return 0;