Skip to content

Commit 8c96c56

Browse files
committed
Update imap-send.c, fix incompatibilities with OpenSSL 1.1.x
Some APIs have been changed since OpenSSL 1.1.0, so fix incompatibilities with OpenSSL 1.1.x. See: * <https://www.openssl.org/docs/man1.1.0/man3/SSLv23_method.html> * <https://wiki.openssl.org/index.php/Library_Initialization> Signed-off-by: Liam Huang <[email protected]>
1 parent 042ed3e commit 8c96c56

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

imap-send.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,15 +249,28 @@ static int verify_hostname(X509 *cert, const char *hostname)
249249
/* try the DNS subjectAltNames */
250250
found = 0;
251251
if ((subj_alt_names = X509_get_ext_d2i(cert, NID_subject_alt_name, NULL, NULL))) {
252+
#if (OPENSSL_VERSION_NUMBER >= 0x10100000L)
253+
int num_subj_alt_names = OPENSSL_sk_num(subj_alt_names);
254+
#else
252255
int num_subj_alt_names = sk_GENERAL_NAME_num(subj_alt_names);
256+
#endif
253257
for (i = 0; !found && i < num_subj_alt_names; i++) {
258+
259+
#if (OPENSSL_VERSION_NUMBER >= 0x10100000L)
260+
GENERAL_NAME *subj_alt_name = OPENSSL_sk_value(subj_alt_names, i);
261+
#else
254262
GENERAL_NAME *subj_alt_name = sk_GENERAL_NAME_value(subj_alt_names, i);
263+
#endif
255264
if (subj_alt_name->type == GEN_DNS &&
256265
strlen((const char *)subj_alt_name->d.ia5->data) == (size_t)subj_alt_name->d.ia5->length &&
257266
host_matches(hostname, (const char *)(subj_alt_name->d.ia5->data)))
258267
found = 1;
259268
}
269+
#if (OPENSSL_VERSION_NUMBER >= 0x10100000L)
270+
OPENSSL_sk_pop_free(subj_alt_names, GENERAL_NAME_free);
271+
#else
260272
sk_GENERAL_NAME_pop_free(subj_alt_names, GENERAL_NAME_free);
273+
#endif
261274
}
262275
if (found)
263276
return 0;
@@ -284,12 +297,22 @@ static int ssl_socket_connect(struct imap_socket *sock, int use_tls_only, int ve
284297
int ret;
285298
X509 *cert;
286299

300+
#if (OPENSSL_VERSION_NUMBER >= 0x10100000L)
301+
OPENSSL_init_ssl(0, NULL);
302+
303+
meth = TLS_method();
304+
#else
287305
SSL_library_init();
288306
SSL_load_error_strings();
289307

290308
meth = SSLv23_method();
309+
#endif
291310
if (!meth) {
311+
#if (OPENSSL_VERSION_NUMBER >= 0x10100000L)
312+
ssl_socket_perror("TLS_method");
313+
#else
292314
ssl_socket_perror("SSLv23_method");
315+
#endif
293316
return -1;
294317
}
295318

0 commit comments

Comments
 (0)