From cdfe49ee0d64a78dc599594341b8e029aae8e0f8 Mon Sep 17 00:00:00 2001 From: "Trever L. Adams" Date: Thu, 29 Jun 2017 21:28:11 -0600 Subject: [PATCH] FS-9785: update mod_event_multicast to work with OpenSSL 1.1.0. --- .../mod_event_multicast/mod_event_multicast.c | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c b/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c index 011166b270..f591855a3e 100644 --- a/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c +++ b/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c @@ -291,7 +291,11 @@ static void event_handler(switch_event_t *event) char *buf; #ifdef HAVE_OPENSSL int outlen, tmplen; +#if OPENSSL_VERSION_NUMBER >= 0x10100000 + EVP_CIPHER_CTX *ctx; +#else EVP_CIPHER_CTX ctx; +#endif char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1]; switch_uuid_t uuid; @@ -309,6 +313,19 @@ static void event_handler(switch_event_t *event) if (globals.psk) { switch_copy_string(buf, uuid_str, SWITCH_UUID_FORMATTED_LENGTH); +#if OPENSSL_VERSION_NUMBER >= 0x10100000 + ctx = EVP_CIPHER_CTX_new(); + EVP_EncryptInit(ctx, EVP_bf_cbc(), NULL, NULL); + EVP_CIPHER_CTX_set_key_length(ctx, strlen(globals.psk)); + EVP_EncryptInit(ctx, NULL, (unsigned char *) globals.psk, (unsigned char *) uuid_str); + EVP_EncryptUpdate(ctx, (unsigned char *) buf + SWITCH_UUID_FORMATTED_LENGTH, + &outlen, (unsigned char *) packet, (int) strlen(packet)); + EVP_EncryptUpdate(ctx, (unsigned char *) buf + SWITCH_UUID_FORMATTED_LENGTH + outlen, + &tmplen, (unsigned char *) MAGIC, (int) strlen((char *) MAGIC)); + outlen += tmplen; + EVP_EncryptFinal(ctx, (unsigned char *) buf + SWITCH_UUID_FORMATTED_LENGTH + outlen, &tmplen); + EVP_CIPHER_CTX_cleanup(ctx); +#else EVP_CIPHER_CTX_init(&ctx); EVP_EncryptInit(&ctx, EVP_bf_cbc(), NULL, NULL); EVP_CIPHER_CTX_set_key_length(&ctx, strlen(globals.psk)); @@ -320,6 +337,7 @@ static void event_handler(switch_event_t *event) outlen += tmplen; EVP_EncryptFinal(&ctx, (unsigned char *) buf + SWITCH_UUID_FORMATTED_LENGTH + outlen, &tmplen); EVP_CIPHER_CTX_cleanup(&ctx); +#endif outlen += tmplen; len = (size_t) outlen + SWITCH_UUID_FORMATTED_LENGTH; *(buf + SWITCH_UUID_FORMATTED_LENGTH + outlen) = '\0'; @@ -530,7 +548,11 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_event_multicast_runtime) char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1]; char *tmp; int outl, tmplen; +#if OPENSSL_VERSION_NUMBER >= 0x10100000L + EVP_CIPHER_CTX *ctx; +#else EVP_CIPHER_CTX ctx; +#endif len -= SWITCH_UUID_FORMATTED_LENGTH; @@ -541,6 +563,15 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_event_multicast_runtime) switch_copy_string(uuid_str, packet, SWITCH_UUID_FORMATTED_LENGTH); packet += SWITCH_UUID_FORMATTED_LENGTH; +#if OPENSSL_VERSION_NUMBER >= 0x10100000L + ctx = EVP_CIPHER_CTX_new(); + EVP_DecryptInit(ctx, EVP_bf_cbc(), NULL, NULL); + EVP_CIPHER_CTX_set_key_length(ctx, strlen(globals.psk)); + EVP_DecryptInit(ctx, NULL, (unsigned char *) globals.psk, (unsigned char *) uuid_str); + EVP_DecryptUpdate(ctx, (unsigned char *) tmp, &outl, (unsigned char *) packet, (int) len); + EVP_DecryptFinal(ctx, (unsigned char *) tmp + outl, &tmplen); + EVP_CIPHER_CTX_cleanup(ctx); +#else EVP_CIPHER_CTX_init(&ctx); EVP_DecryptInit(&ctx, EVP_bf_cbc(), NULL, NULL); EVP_CIPHER_CTX_set_key_length(&ctx, strlen(globals.psk)); @@ -548,6 +579,8 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_event_multicast_runtime) EVP_DecryptUpdate(&ctx, (unsigned char *) tmp, &outl, (unsigned char *) packet, (int) len); EVP_DecryptFinal(&ctx, (unsigned char *) tmp + outl, &tmplen); EVP_CIPHER_CTX_cleanup(&ctx); +#endif + *(tmp + outl + tmplen) = '\0'; /*switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "decrypted event as %s\n----------\n of actual length %d (%d) %d\n", tmp, outl + tmplen, (int) len, (int) strlen(tmp)); */