[PATCH v12 05/10] imap-send: gracefully fail if CRAM-MD5 authentication is requested without OpenSSL
- From
Aditya Garg <gargaditya08@live.com>
- Date
- Jun 2, 2025, 10:59 UTC
- Message-ID
- <PN3PR01MB959713A2536AD407D15CE632B862A@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM>
- In-Reply-To
- <PN3PR01MB9597D3BADD7CDE568825A2D0B862A@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM>
Unlike PLAIN, XOAUTH2 and OAUTHBEARER, CRAM-MD5 authentication is not supported by libcurl and requires OpenSSL. If the user tries to use CRAM-MD5 authentication without OpenSSL, the previous behaviour was to attempt to authenticate and fail with a die(error). Handle this in a better way by first checking if OpenSSL is available and then attempting to authenticate. If OpenSSL is not available, print an error message and exit gracefully.
Signed-off-by: Aditya Garg <gargaditya08@live.com> --- imap-send.c | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-)
diff --git a/imap-send.c b/imap-send.c index 5f31dad3b0..879c72a606 100644 --- a/imap-send.c +++ b/imap-send.c @@ -1008,6 +1008,24 @@ static int auth_plain(struct imap_store *ctx, const char *prompt UNUSED) return 0; } +static int auth_cram_md5(struct imap_store *ctx, const char *prompt) +{ + int ret; + char *response; + + response = cram(prompt, ctx->cfg->user, ctx->cfg->pass); + + ret = socket_write(&ctx->imap->buf.sock, response, strlen(response)); + if (ret != strlen(response)) { + free(response); + return error("IMAP error: sending response failed"); + } + + free(response); + + return 0; +} + static int auth_oauthbearer(struct imap_store *ctx, const char *prompt UNUSED) { int ret; @@ -1050,38 +1068,13 @@ static int auth_xoauth2(struct imap_store *ctx, const char *prompt UNUSED) #else -static char *cram(const char *challenge_64 UNUSED, - const char *user UNUSED, - const char *pass UNUSED) -{ - die("If you want to use CRAM-MD5 authenticate method, " - "you have to build git-imap-send with OpenSSL library."); -} - #define auth_plain NULL +#define auth_cram_md5 NULL #define auth_oauthbearer NULL #define auth_xoauth2 NULL #endif -static int auth_cram_md5(struct imap_store *ctx, const char *prompt) -{ - int ret; - char *response; - - response = cram(prompt, ctx->cfg->user, ctx->cfg->pass); - - ret = socket_write(&ctx->imap->buf.sock, response, strlen(response)); - if (ret != strlen(response)) { - free(response); - return error("IMAP error: sending response failed"); - } - - free(response); - - return 0; -} - static void server_fill_credential(struct imap_server_conf *srvc, struct credential *cred) { if (srvc->user && srvc->pass) @@ -1287,6 +1280,13 @@ static struct imap_store *imap_open_store(struct imap_server_conf *srvc, const c "but %s doesn't support it.\n", srvc->host); goto bail; } + + #ifdef NO_OPENSSL + fprintf(stderr, "If you want to use CRAM-MD5 authentication mechanism, " + "you have to build git-imap-send with OpenSSL library."); + goto bail; + #endif + /* CRAM-MD5 */ memset(&cb, 0, sizeof(cb));
-- 2.49.0.639.g36d50d01f0