Skip to content

Update imap-send.c, fix incompatibilities with OpenSSL 1.1.x #516

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions imap-send.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,28 @@ static int verify_hostname(X509 *cert, const char *hostname)
/* try the DNS subjectAltNames */
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the Git mailing list, Junio C Hamano wrote (reply to this):

"Liam Huang via GitGitGadget" <[email protected]> writes:

> From: Liam Huang <[email protected]>
>
> Some APIs have been changed since OpenSSL 1.1.0, so fix incompatibilities with OpenSSL 1.1.x.

I wonder if the patch can be made a lot less noisy with something
along this line

        #if OPENSSL_VERSION_NUMBER < 0x10100000L
        #define OPENSSL_sk_num(x) sk_GENERAL_NAME_num(x)
        #define OPENSSL_sk_value(x,y) sk_GENERAL_NAME_value((x),(y))
        #define OPENSSL_sk_pop_free(x,y) sk_GENERAL_NAME_pop_free((x),(y))
        #endif

which would allow you to reduce many #if/#else/#endif in the actual
code.

found = 0;
if ((subj_alt_names = X509_get_ext_d2i(cert, NID_subject_alt_name, NULL, NULL))) {
#if (OPENSSL_VERSION_NUMBER >= 0x10100000L)
int num_subj_alt_names = OPENSSL_sk_num(subj_alt_names);
#else
int num_subj_alt_names = sk_GENERAL_NAME_num(subj_alt_names);
#endif
for (i = 0; !found && i < num_subj_alt_names; i++) {

#if (OPENSSL_VERSION_NUMBER >= 0x10100000L)
GENERAL_NAME *subj_alt_name = OPENSSL_sk_value(subj_alt_names, i);
#else
GENERAL_NAME *subj_alt_name = sk_GENERAL_NAME_value(subj_alt_names, i);
#endif
if (subj_alt_name->type == GEN_DNS &&
strlen((const char *)subj_alt_name->d.ia5->data) == (size_t)subj_alt_name->d.ia5->length &&
host_matches(hostname, (const char *)(subj_alt_name->d.ia5->data)))
found = 1;
}
#if (OPENSSL_VERSION_NUMBER >= 0x10100000L)
OPENSSL_sk_pop_free(subj_alt_names, GENERAL_NAME_free);
#else
sk_GENERAL_NAME_pop_free(subj_alt_names, GENERAL_NAME_free);
#endif
}
if (found)
return 0;
Expand All @@ -284,12 +297,22 @@ static int ssl_socket_connect(struct imap_socket *sock, int use_tls_only, int ve
int ret;
X509 *cert;

#if (OPENSSL_VERSION_NUMBER >= 0x10100000L)
OPENSSL_init_ssl(0, NULL);

meth = TLS_method();
#else
SSL_library_init();
SSL_load_error_strings();

meth = SSLv23_method();
#endif
if (!meth) {
#if (OPENSSL_VERSION_NUMBER >= 0x10100000L)
ssl_socket_perror("TLS_method");
#else
ssl_socket_perror("SSLv23_method");
#endif
return -1;
}

Expand Down