Skip to content

Commit 33e4ec8

Browse files
committed
Merge branch 'ky/imap-send-openssl-1.1.0'
Upcoming OpenSSL 1.1.0 will break compilation b updating a few APIs we use in imap-send, which has been adjusted for the change. * ky/imap-send-openssl-1.1.0: configure: remove checking for HMAC_CTX_cleanup imap-send: avoid deprecated TLSv1_method() imap-send: check NULL return of SSL_CTX_new() imap-send: use HMAC() function provided by OpenSSL
2 parents 886c76d + 1245c74 commit 33e4ec8

File tree

5 files changed

+21
-28
lines changed

5 files changed

+21
-28
lines changed

Makefile

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,6 @@ all::
355355
#
356356
# Define HAVE_CLOCK_MONOTONIC if your platform has CLOCK_MONOTONIC in librt.
357357
#
358-
# Define NO_HMAC_CTX_CLEANUP if your OpenSSL is version 0.9.6b or earlier to
359-
# cleanup the HMAC context with the older HMAC_cleanup function.
360-
#
361358
# Define USE_PARENS_AROUND_GETTEXT_N to "yes" if your compiler happily
362359
# compiles the following initialization:
363360
#
@@ -1138,9 +1135,6 @@ ifndef NO_OPENSSL
11381135
ifdef NEEDS_CRYPTO_WITH_SSL
11391136
OPENSSL_LIBSSL += -lcrypto
11401137
endif
1141-
ifdef NO_HMAC_CTX_CLEANUP
1142-
BASIC_CFLAGS += -DNO_HMAC_CTX_CLEANUP
1143-
endif
11441138
else
11451139
BASIC_CFLAGS += -DNO_OPENSSL
11461140
BLK_SHA1 = 1

compat/apple-common-crypto.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@
33
#define HEADER_HMAC_H
44
#define HEADER_SHA_H
55
#include <CommonCrypto/CommonHMAC.h>
6-
#define HMAC_CTX CCHmacContext
7-
#define HMAC_Init(hmac, key, len, algo) CCHmacInit(hmac, algo, key, len)
8-
#define HMAC_Update CCHmacUpdate
9-
#define HMAC_Final(hmac, hash, ptr) CCHmacFinal(hmac, hash)
10-
#define HMAC_CTX_cleanup(ignore)
116
#define EVP_md5(...) kCCHmacAlgMD5
7+
/* CCHmac doesn't take md_len and the return type is void */
8+
#define HMAC git_CC_HMAC
9+
static inline unsigned char *git_CC_HMAC(CCHmacAlgorithm alg,
10+
const void *key, int key_len,
11+
const unsigned char *data, size_t data_len,
12+
unsigned char *md, unsigned int *md_len)
13+
{
14+
CCHmac(alg, key, key_len, data, data_len, md);
15+
return md;
16+
}
17+
1218
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
1319
#define APPLE_LION_OR_NEWER
1420
#include <Security/Security.h>

configure.ac

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -970,10 +970,6 @@ AC_CHECK_LIB([iconv], [locale_charset],
970970
[CHARSET_LIB=-lcharset])])
971971
GIT_CONF_SUBST([CHARSET_LIB])
972972
#
973-
# Define NO_HMAC_CTX_CLEANUP=YesPlease if HMAC_CTX_cleanup is missing.
974-
AC_CHECK_LIB([crypto], [HMAC_CTX_cleanup],
975-
[], [GIT_CONF_SUBST([NO_HMAC_CTX_CLEANUP], [YesPlease])])
976-
#
977973
# Define HAVE_CLOCK_GETTIME=YesPlease if clock_gettime is available.
978974
GIT_CHECK_FUNC(clock_gettime,
979975
[HAVE_CLOCK_GETTIME=YesPlease],

git-compat-util.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,6 @@ extern char *gitdirname(char *);
279279
#endif
280280
#include <openssl/ssl.h>
281281
#include <openssl/err.h>
282-
#ifdef NO_HMAC_CTX_CLEANUP
283-
#define HMAC_CTX_cleanup HMAC_cleanup
284-
#endif
285282
#endif
286283

287284
/* On most systems <netdb.h> would have given us this, but

imap-send.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -287,17 +287,20 @@ static int ssl_socket_connect(struct imap_socket *sock, int use_tls_only, int ve
287287
SSL_library_init();
288288
SSL_load_error_strings();
289289

290-
if (use_tls_only)
291-
meth = TLSv1_method();
292-
else
293-
meth = SSLv23_method();
294-
290+
meth = SSLv23_method();
295291
if (!meth) {
296292
ssl_socket_perror("SSLv23_method");
297293
return -1;
298294
}
299295

300296
ctx = SSL_CTX_new(meth);
297+
if (!ctx) {
298+
ssl_socket_perror("SSL_CTX_new");
299+
return -1;
300+
}
301+
302+
if (use_tls_only)
303+
SSL_CTX_set_options(ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3);
301304

302305
if (verify)
303306
SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, NULL);
@@ -862,7 +865,6 @@ static char hexchar(unsigned int b)
862865
static char *cram(const char *challenge_64, const char *user, const char *pass)
863866
{
864867
int i, resp_len, encoded_len, decoded_len;
865-
HMAC_CTX hmac;
866868
unsigned char hash[16];
867869
char hex[33];
868870
char *response, *response_64, *challenge;
@@ -877,10 +879,8 @@ static char *cram(const char *challenge_64, const char *user, const char *pass)
877879
(unsigned char *)challenge_64, encoded_len);
878880
if (decoded_len < 0)
879881
die("invalid challenge %s", challenge_64);
880-
HMAC_Init(&hmac, (unsigned char *)pass, strlen(pass), EVP_md5());
881-
HMAC_Update(&hmac, (unsigned char *)challenge, decoded_len);
882-
HMAC_Final(&hmac, hash, NULL);
883-
HMAC_CTX_cleanup(&hmac);
882+
if (!HMAC(EVP_md5(), pass, strlen(pass), (unsigned char *)challenge, decoded_len, hash, NULL))
883+
die("HMAC error");
884884

885885
hex[32] = 0;
886886
for (i = 0; i < 16; i++) {

0 commit comments

Comments
 (0)