From 1ed2c7b11570f5d16bdc70d151fa78c3dccf6d38 Mon Sep 17 00:00:00 2001 From: Kazuki Yamaguchi Date: Sat, 9 Apr 2016 01:22:13 +0900 Subject: imap-send: use HMAC() function provided by OpenSSL Fix compile errors with OpenSSL 1.1.0. HMAC_CTX is made opaque and HMAC_CTX_cleanup is removed in OpenSSL 1.1.0. But since we just want to calculate one HMAC, we can use HMAC() here, which exists since OpenSSL 0.9.6 at least. Signed-off-by: Kazuki Yamaguchi Signed-off-by: Junio C Hamano diff --git a/compat/apple-common-crypto.h b/compat/apple-common-crypto.h index d3fb264..11727f3 100644 --- a/compat/apple-common-crypto.h +++ b/compat/apple-common-crypto.h @@ -3,12 +3,18 @@ #define HEADER_HMAC_H #define HEADER_SHA_H #include -#define HMAC_CTX CCHmacContext -#define HMAC_Init(hmac, key, len, algo) CCHmacInit(hmac, algo, key, len) -#define HMAC_Update CCHmacUpdate -#define HMAC_Final(hmac, hash, ptr) CCHmacFinal(hmac, hash) -#define HMAC_CTX_cleanup(ignore) #define EVP_md5(...) kCCHmacAlgMD5 +/* CCHmac doesn't take md_len and the return type is void */ +#define HMAC git_CC_HMAC +static inline unsigned char *git_CC_HMAC(CCHmacAlgorithm alg, + const void *key, int key_len, + const unsigned char *data, size_t data_len, + unsigned char *md, unsigned int *md_len) +{ + CCHmac(alg, key, key_len, data, data_len, md); + return md; +} + #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 #define APPLE_LION_OR_NEWER #include diff --git a/imap-send.c b/imap-send.c index 8c3fc21..8bf363b 100644 --- a/imap-send.c +++ b/imap-send.c @@ -862,7 +862,6 @@ static char hexchar(unsigned int b) static char *cram(const char *challenge_64, const char *user, const char *pass) { int i, resp_len, encoded_len, decoded_len; - HMAC_CTX hmac; unsigned char hash[16]; char hex[33]; char *response, *response_64, *challenge; @@ -877,10 +876,8 @@ static char *cram(const char *challenge_64, const char *user, const char *pass) (unsigned char *)challenge_64, encoded_len); if (decoded_len < 0) die("invalid challenge %s", challenge_64); - HMAC_Init(&hmac, (unsigned char *)pass, strlen(pass), EVP_md5()); - HMAC_Update(&hmac, (unsigned char *)challenge, decoded_len); - HMAC_Final(&hmac, hash, NULL); - HMAC_CTX_cleanup(&hmac); + if (!HMAC(EVP_md5(), pass, strlen(pass), (unsigned char *)challenge, decoded_len, hash, NULL)) + die("HMAC error"); hex[32] = 0; for (i = 0; i < 16; i++) { -- cgit v0.10.2-6-g49f6 From 6738a33b3102222b25f7a1596aa1ed39c478a268 Mon Sep 17 00:00:00 2001 From: Kazuki Yamaguchi Date: Sat, 9 Apr 2016 01:22:14 +0900 Subject: imap-send: check NULL return of SSL_CTX_new() SSL_CTX_new() may fail with return value NULL. Signed-off-by: Kazuki Yamaguchi Signed-off-by: Junio C Hamano diff --git a/imap-send.c b/imap-send.c index 8bf363b..e964e2a 100644 --- a/imap-send.c +++ b/imap-send.c @@ -298,6 +298,10 @@ static int ssl_socket_connect(struct imap_socket *sock, int use_tls_only, int ve } ctx = SSL_CTX_new(meth); + if (!ctx) { + ssl_socket_perror("SSL_CTX_new"); + return -1; + } if (verify) SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, NULL); -- cgit v0.10.2-6-g49f6 From b51c0d4b4c70b3d2ddac1657b98b17e77af1c404 Mon Sep 17 00:00:00 2001 From: Kazuki Yamaguchi Date: Sat, 9 Apr 2016 01:22:15 +0900 Subject: imap-send: avoid deprecated TLSv1_method() Use SSLv23_method always and disable SSL if needed. TLSv1_method() function is deprecated in OpenSSL 1.1.0 and the compiler emits a warning. SSLv23_method() is also deprecated, but the alternative, TLS_method(), is new in OpenSSL 1.1.0 so requires checking by configure. Stick to SSLv23_method() for now (this is aliased to TLS_method()). Signed-off-by: Kazuki Yamaguchi Signed-off-by: Junio C Hamano diff --git a/imap-send.c b/imap-send.c index e964e2a..78b6ff6 100644 --- a/imap-send.c +++ b/imap-send.c @@ -287,11 +287,7 @@ static int ssl_socket_connect(struct imap_socket *sock, int use_tls_only, int ve SSL_library_init(); SSL_load_error_strings(); - if (use_tls_only) - meth = TLSv1_method(); - else - meth = SSLv23_method(); - + meth = SSLv23_method(); if (!meth) { ssl_socket_perror("SSLv23_method"); return -1; @@ -303,6 +299,9 @@ static int ssl_socket_connect(struct imap_socket *sock, int use_tls_only, int ve return -1; } + if (use_tls_only) + SSL_CTX_set_options(ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3); + if (verify) SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, NULL); -- cgit v0.10.2-6-g49f6 From 1245c74936d5803415306ade3c5050614a26af4e Mon Sep 17 00:00:00 2001 From: Kazuki Yamaguchi Date: Sat, 9 Apr 2016 01:22:16 +0900 Subject: configure: remove checking for HMAC_CTX_cleanup We don't need it, as we no longer use HMAC_CTX_cleanup() directly. Signed-off-by: Kazuki Yamaguchi Signed-off-by: Junio C Hamano diff --git a/Makefile b/Makefile index 37e2d9e..cad1f45 100644 --- a/Makefile +++ b/Makefile @@ -354,9 +354,6 @@ all:: # # Define HAVE_CLOCK_MONOTONIC if your platform has CLOCK_MONOTONIC in librt. # -# Define NO_HMAC_CTX_CLEANUP if your OpenSSL is version 0.9.6b or earlier to -# cleanup the HMAC context with the older HMAC_cleanup function. -# # Define USE_PARENS_AROUND_GETTEXT_N to "yes" if your compiler happily # compiles the following initialization: # @@ -1120,9 +1117,6 @@ ifndef NO_OPENSSL ifdef NEEDS_CRYPTO_WITH_SSL OPENSSL_LIBSSL += -lcrypto endif - ifdef NO_HMAC_CTX_CLEANUP - BASIC_CFLAGS += -DNO_HMAC_CTX_CLEANUP - endif else BASIC_CFLAGS += -DNO_OPENSSL BLK_SHA1 = 1 diff --git a/configure.ac b/configure.ac index 1f55009..367e72f 100644 --- a/configure.ac +++ b/configure.ac @@ -970,10 +970,6 @@ AC_CHECK_LIB([iconv], [locale_charset], [CHARSET_LIB=-lcharset])]) GIT_CONF_SUBST([CHARSET_LIB]) # -# Define NO_HMAC_CTX_CLEANUP=YesPlease if HMAC_CTX_cleanup is missing. -AC_CHECK_LIB([crypto], [HMAC_CTX_cleanup], - [], [GIT_CONF_SUBST([NO_HMAC_CTX_CLEANUP], [YesPlease])]) -# # Define HAVE_CLOCK_GETTIME=YesPlease if clock_gettime is available. GIT_CHECK_FUNC(clock_gettime, [HAVE_CLOCK_GETTIME=YesPlease], diff --git a/git-compat-util.h b/git-compat-util.h index f035363..c062ddf 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -277,9 +277,6 @@ extern char *gitbasename(char *); #endif #include #include -#ifdef NO_HMAC_CTX_CLEANUP -#define HMAC_CTX_cleanup HMAC_cleanup -#endif #endif /* On most systems would have given us this, but -- cgit v0.10.2-6-g49f6