Skip to content
This repository has been archived by the owner on Nov 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request civetweb#1080 from linev/digest_ssl3
Browse files Browse the repository at this point in the history
Use EVP_Digest only with OpenSSL 3.0
  • Loading branch information
bel2125 authored Jul 9, 2022
2 parents 575a848 + 43f68d6 commit 5a8fb0c
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/civetweb.c
Original file line number Diff line number Diff line change
Expand Up @@ -12981,16 +12981,21 @@ mg_unlock_context(struct mg_context *ctx)
#if defined(USE_WEBSOCKET)

#if !defined(NO_SSL_DL)
#if !defined(OPENSSL_API_3_0)
#define SHA_API static
#include "sha1.inl"
#endif
#endif

static int
send_websocket_handshake(struct mg_connection *conn, const char *websock_key)
{
static const char *magic = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
char buf[100], sha[20], b64_sha[sizeof(sha) * 2];
size_t dst_len = sizeof(b64_sha);
#if !defined(OPENSSL_API_3_0)
SHA_CTX sha_ctx;
#endif
int truncated;

/* Calculate Sec-WebSocket-Accept reply from Sec-WebSocket-Key. */
Expand All @@ -13002,8 +13007,14 @@ send_websocket_handshake(struct mg_connection *conn, const char *websock_key)

DEBUG_TRACE("%s", "Send websocket handshake");

#if defined(OPENSSL_API_3_0)
EVP_Digest((unsigned char *)buf, (uint32_t)strlen(buf), (unsigned char *)sha,
NULL, EVP_get_digestbyname("sha1"), NULL);
#else
SHA1_Init(&sha_ctx);
SHA1_Update(&sha_ctx, (unsigned char *)buf, (uint32_t)strlen(buf));
SHA1_Final((unsigned char *)sha, &sha_ctx);
#endif
mg_base64_encode((unsigned char *)sha, sizeof(sha), b64_sha, &dst_len);
mg_printf(conn,
"HTTP/1.1 101 Switching Protocols\r\n"
Expand Down Expand Up @@ -22220,12 +22231,12 @@ mg_get_handler_info(struct mg_context *ctx,
mg_lock_context(ctx);

for (tmp_rh = ctx->dd.handlers; tmp_rh != NULL; tmp_rh = tmp_rh->next) {

if (buflen > handler_info_len+ tmp_rh->uri_len) {
memcpy(buffer+handler_info_len, tmp_rh->uri, tmp_rh->uri_len);
}
handler_info_len += tmp_rh->uri_len;

switch (tmp_rh->handler_type) {
case REQUEST_HANDLER:
(void)tmp_rh->handler;
Expand All @@ -22234,12 +22245,12 @@ mg_get_handler_info(struct mg_context *ctx,
(void)tmp_rh->connect_handler;
(void) tmp_rh->ready_handler;
(void) tmp_rh->data_handler;
(void) tmp_rh->close_handler;
(void) tmp_rh->close_handler;
break;
case AUTH_HANDLER:
(void) tmp_rh->auth_handler;
(void) tmp_rh->auth_handler;
break;
}
}
(void)cbdata;
}

Expand Down

0 comments on commit 5a8fb0c

Please sign in to comment.