Skip to content

Commit

Permalink
Remove support for openssl older than 1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jonesmz committed Jan 29, 2024
1 parent d274637 commit 4d32823
Show file tree
Hide file tree
Showing 10 changed files with 9 additions and 302 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ 'ubuntu:16.04', 'ubuntu:20.04', 'ubuntu:22.04' ]
os: [ 'ubuntu:18.04', 'ubuntu:20.04', 'ubuntu:22.04' ]
runs-on: ubuntu-latest
container: ${{ matrix.os }}
steps:
Expand Down
12 changes: 1 addition & 11 deletions src/apps/common/apputils.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,7 @@ extern int IS_TURN_SERVER;

/* ALPN */

#define OPENSSL_FIRST_ALPN_VERSION (0x10002003L)

#if OPENSSL_VERSION_NUMBER >= OPENSSL_FIRST_ALPN_VERSION
#define ALPN_SUPPORTED 1
#else
#define ALPN_SUPPORTED 0
#endif

/* TLS */

Expand Down Expand Up @@ -96,7 +90,7 @@ extern int IS_TURN_SERVER;

#endif

#if defined(TURN_NO_DTLS) || (!defined(DTLS_CTRL_LISTEN) && (OPENSSL_VERSION_NUMBER < 0x10100000L))
#if defined(TURN_NO_DTLS)

#define DTLS_SUPPORTED 0
#define DTLSv1_2_SUPPORTED 0
Expand All @@ -113,11 +107,7 @@ extern int IS_TURN_SERVER;

#endif

#if OPENSSL_VERSION_NUMBER >= OPENSSL_FIRST_ALPN_VERSION
#define SSL_SESSION_ECDH_AUTO_SUPPORTED 1
#else
#define SSL_SESSION_ECDH_AUTO_SUPPORTED 0
#endif

/////////// SSL //////////////////////////

Expand Down
4 changes: 0 additions & 4 deletions src/apps/relay/dbdrivers/dbd_mysql.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,8 @@ char *decryptPassword(char *in, const unsigned char *mykey) {
init_ctr(&state, iv);
memset(outdata, '\0', sizeof(outdata));

#if OPENSSL_VERSION_NUMBER >= 0x10100000L
CRYPTO_ctr128_encrypt(encryptedText, outdata, newTotalSize, &key, state.ivec, state.ecount, &state.num,
(block128_f)AES_encrypt);
#else
AES_ctr128_encrypt(encryptedText, outdata, newTotalSize, &key, state.ivec, state.ecount, &state.num);
#endif

strcat(last, (char *)outdata);
out = (char *)malloc(sizeof(char) * strlen(last));
Expand Down
19 changes: 1 addition & 18 deletions src/apps/relay/dtls_listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,7 @@ static int generate_cookie(SSL *ssl, unsigned char *cookie, unsigned int *cookie
return 1;
}

static int verify_cookie(SSL *ssl,
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
const
#endif
unsigned char *cookie,
unsigned int cookie_len) {
static int verify_cookie(SSL *ssl, const unsigned char *cookie, unsigned int cookie_len) {
unsigned int resultlength = 0;
unsigned char result[COOKIE_SECRET_LENGTH];

Expand Down Expand Up @@ -284,14 +279,8 @@ static ioa_socket_handle dtls_server_input_handler(dtls_listener_relay_server_ty

SSL_set_bio(connecting_ssl, NULL, wbio);
SSL_set_options(connecting_ssl, SSL_OP_COOKIE_EXCHANGE
#if OPENSSL_VERSION_NUMBER < 0x10100000L
#if defined(SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS)
| SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS
#endif
#else
#if defined(SSL_OP_NO_RENEGOTIATION)
| SSL_OP_NO_RENEGOTIATION
#endif
#endif
);
SSL_set_max_cert_list(connecting_ssl, 655350);
Expand Down Expand Up @@ -557,14 +546,8 @@ static int create_new_connected_udp_socket(dtls_listener_relay_server_type *serv
SSL_set_bio(connecting_ssl, NULL, wbio);

SSL_set_options(connecting_ssl, SSL_OP_COOKIE_EXCHANGE
#if OPENSSL_VERSION_NUMBER < 0x10100000L
#if defined(SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS)
| SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS
#endif
#else
#if defined(SSL_OP_NO_RENEGOTIATION)
| SSL_OP_NO_RENEGOTIATION
#endif
#endif
);

Expand Down
134 changes: 0 additions & 134 deletions src/apps/relay/mainrelay.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@
#define MAX_TRIES 3
#endif

#if (!defined OPENSSL_VERSION_1_1_1)
#define OPENSSL_VERSION_1_1_1 0x10101000L
#endif

////// TEMPORARY data //////////

static int use_lt_credentials = 0;
Expand Down Expand Up @@ -1721,12 +1717,8 @@ void encrypt_aes_128(unsigned char *in, const unsigned char *mykey) {
struct ctr_state state;
init_ctr(&state, iv);

#if OPENSSL_VERSION_NUMBER >= 0x10100000L
CRYPTO_ctr128_encrypt(in, out, strlen((char *)in), &key, state.ivec, state.ecount, &state.num,
(block128_f)AES_encrypt);
#else
AES_ctr128_encrypt(in, out, strlen((char *)in), &key, state.ivec, state.ecount, &state.num);
#endif

totalSize += strlen((char *)in);
size = strlen((char *)in);
Expand Down Expand Up @@ -1808,12 +1800,8 @@ void decrypt_aes_128(char *in, const unsigned char *mykey) {
init_ctr(&state, iv);
memset(outdata, '\0', sizeof(outdata));

#if OPENSSL_VERSION_NUMBER >= 0x10100000L
CRYPTO_ctr128_encrypt(encryptedText, outdata, newTotalSize, &key, state.ivec, state.ecount, &state.num,
(block128_f)AES_encrypt);
#else
AES_ctr128_encrypt(encryptedText, outdata, newTotalSize, &key, state.ivec, state.ecount, &state.num);
#endif

strcat(last, (char *)outdata);
printf("%s\n", last);
Expand Down Expand Up @@ -3332,65 +3320,10 @@ int main(int argc, char **argv) {
////////// OpenSSL locking ////////////////////////////////////////

#if defined(OPENSSL_THREADS)
#if OPENSSL_VERSION_NUMBER < OPENSSL_VERSION_1_1_0

// array larger than anything that OpenSSL may need:
static TURN_MUTEX_DECLARE(mutex_buf[256]);
static int mutex_buf_initialized = 0;

void coturn_locking_function(int mode, int n, const char *file, int line);
void coturn_locking_function(int mode, int n, const char *file, int line) {
UNUSED_ARG(file);
UNUSED_ARG(line);
if (mutex_buf_initialized && (n < CRYPTO_num_locks())) {
if (mode & CRYPTO_LOCK) {
TURN_MUTEX_LOCK(&(mutex_buf[n]));
} else {
TURN_MUTEX_UNLOCK(&(mutex_buf[n]));
}
}
}

void coturn_id_function(CRYPTO_THREADID *ctid);
void coturn_id_function(CRYPTO_THREADID *ctid) {
UNUSED_ARG(ctid);
CRYPTO_THREADID_set_numeric(ctid, (unsigned long)pthread_self());
}

static int THREAD_setup(void) {
int i;
for (i = 0; i < CRYPTO_num_locks(); i++) {
TURN_MUTEX_INIT(&(mutex_buf[i]));
}

mutex_buf_initialized = 1;
CRYPTO_THREADID_set_callback(coturn_id_function);
CRYPTO_set_locking_callback(coturn_locking_function);
return 1;
}

int THREAD_cleanup(void) {
int i;

if (!mutex_buf_initialized) {
return 0;
}

CRYPTO_THREADID_set_callback(NULL);
CRYPTO_set_locking_callback(NULL);
for (i = 0; i < CRYPTO_num_locks(); i++) {
TURN_MUTEX_DESTROY(&(mutex_buf[i]));
}

mutex_buf_initialized = 0;
return 1;
}
#else
static int THREAD_setup(void) { return 1; }

int THREAD_cleanup(void);
int THREAD_cleanup(void) { return 1; }
#endif /* OPENSSL_VERSION_NUMBER < OPENSSL_VERSION_1_1_0 */
#endif /* defined(OPENSSL_THREADS) */

static void adjust_key_file_name(char *fn, const char *file_title, int critical) {
Expand Down Expand Up @@ -3466,16 +3399,7 @@ static DH *get_dh566(void) {
if ((dh = DH_new()) == NULL) {
return (NULL);
}
#if OPENSSL_VERSION_NUMBER < 0x10100000L
dh->p = BN_bin2bn(dh566_p, sizeof(dh566_p), NULL);
dh->g = BN_bin2bn(dh566_g, sizeof(dh566_g), NULL);
if ((dh->p == NULL) || (dh->g == NULL)) {
DH_free(dh);
return (NULL);
}
#else
DH_set0_pqg(dh, BN_bin2bn(dh566_p, sizeof(dh566_p), NULL), NULL, BN_bin2bn(dh566_g, sizeof(dh566_g), NULL));
#endif
return (dh);
}

Expand Down Expand Up @@ -3503,16 +3427,7 @@ static DH *get_dh1066(void) {
if ((dh = DH_new()) == NULL) {
return (NULL);
}
#if OPENSSL_VERSION_NUMBER < 0x10100000L
dh->p = BN_bin2bn(dh1066_p, sizeof(dh1066_p), NULL);
dh->g = BN_bin2bn(dh1066_g, sizeof(dh1066_g), NULL);
if ((dh->p == NULL) || (dh->g == NULL)) {
DH_free(dh);
return (NULL);
}
#else
DH_set0_pqg(dh, BN_bin2bn(dh1066_p, sizeof(dh1066_p), NULL), NULL, BN_bin2bn(dh1066_g, sizeof(dh1066_g), NULL));
#endif
return (dh);
}

Expand Down Expand Up @@ -3549,16 +3464,7 @@ static DH *get_dh2066(void) {
if ((dh = DH_new()) == NULL) {
return (NULL);
}
#if OPENSSL_VERSION_NUMBER < 0x10100000L
dh->p = BN_bin2bn(dh2066_p, sizeof(dh2066_p), NULL);
dh->g = BN_bin2bn(dh2066_g, sizeof(dh2066_g), NULL);
if ((dh->p == NULL) || (dh->g == NULL)) {
DH_free(dh);
return (NULL);
}
#else
DH_set0_pqg(dh, BN_bin2bn(dh2066_p, sizeof(dh2066_p), NULL), NULL, BN_bin2bn(dh2066_g, sizeof(dh2066_g), NULL));
#endif
return (dh);
}

Expand Down Expand Up @@ -3721,11 +3627,6 @@ static void set_ctx(SSL_CTX **out, const char *protocol, const SSL_METHOD *metho
}

if (set_auto_curve) {
#if SSL_SESSION_ECDH_AUTO_SUPPORTED
#if OPENSSL_VERSION_NUMBER < 0x10100000L
SSL_CTX_set_ecdh_auto(ctx, 1);
#endif
#endif
set_auto_curve = 0;
}
}
Expand Down Expand Up @@ -3867,22 +3768,6 @@ static void openssl_load_certificates(void) {

TURN_MUTEX_LOCK(&turn_params.tls_mutex);
if (!turn_params.no_tls) {
#if OPENSSL_VERSION_NUMBER < 0x10100000L
set_ctx(&turn_params.tls_ctx, "TLS", TLSv1_2_server_method()); /*openssl-1.0.2 version specific API */
if (turn_params.no_tlsv1) {
SSL_CTX_set_options(turn_params.tls_ctx, SSL_OP_NO_TLSv1);
}
#if TLSv1_1_SUPPORTED
if (turn_params.no_tlsv1_1) {
SSL_CTX_set_options(turn_params.tls_ctx, SSL_OP_NO_TLSv1_1);
}
#if TLSv1_2_SUPPORTED
if (turn_params.no_tlsv1_2) {
SSL_CTX_set_options(turn_params.tls_ctx, SSL_OP_NO_TLSv1_2);
}
#endif
#endif
#else // OPENSSL_VERSION_NUMBER < 0x10100000L
set_ctx(&turn_params.tls_ctx, "TLS", TLS_server_method());
if (turn_params.no_tlsv1) {
SSL_CTX_set_min_proto_version(turn_params.tls_ctx, TLS1_1_VERSION);
Expand All @@ -3895,39 +3780,20 @@ static void openssl_load_certificates(void) {
SSL_CTX_set_min_proto_version(turn_params.tls_ctx, TLS1_3_VERSION);
}
#endif
#endif // OPENSSL_VERSION_NUMBER < 0x10100000L
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "TLS cipher suite: %s\n", turn_params.cipher_list);
}

if (!turn_params.no_dtls) {
#if !DTLS_SUPPORTED
TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "ERROR: DTLS is not supported.\n");
#elif OPENSSL_VERSION_NUMBER < 0x10000000L
TURN_LOG_FUNC(
TURN_LOG_LEVEL_WARNING,
"WARNING: TURN Server was compiled with rather old OpenSSL version, DTLS may not be working correctly.\n");
#else
#if OPENSSL_VERSION_NUMBER < 0x10100000L // before openssl-1.1.0 no version independent API
#if DTLSv1_2_SUPPORTED
set_ctx(&turn_params.dtls_ctx, "DTLS", DTLSv1_2_server_method()); // openssl-1.0.2
if (turn_params.no_tlsv1_2) {
SSL_CTX_set_options(turn_params.dtls_ctx, SSL_OP_NO_DTLSv1_2);
}
#else
set_ctx(&turn_params.dtls_ctx, "DTLS", DTLSv1_server_method()); // < openssl-1.0.2
#endif
if (turn_params.no_tlsv1 || turn_params.no_tlsv1_1) {
SSL_CTX_set_options(turn_params.dtls_ctx, SSL_OP_NO_DTLSv1);
}
#else // OPENSSL_VERSION_NUMBER < 0x10100000L
set_ctx(&turn_params.dtls_ctx, "DTLS", DTLS_server_method());
if (turn_params.no_tlsv1 || turn_params.no_tlsv1_1) {
SSL_CTX_set_min_proto_version(turn_params.dtls_ctx, DTLS1_2_VERSION);
}
if (turn_params.no_tlsv1_2) {
SSL_CTX_set_max_proto_version(turn_params.dtls_ctx, DTLS1_VERSION);
}
#endif // OPENSSL_VERSION_NUMBER < 0x10100000L
setup_dtls_callbacks(turn_params.dtls_ctx);
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "DTLS cipher suite: %s\n", turn_params.cipher_list);
#endif
Expand Down
2 changes: 0 additions & 2 deletions src/apps/relay/mainrelay.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@
#include <openssl/pem.h>
#include <openssl/ssl.h>

#if OPENSSL_VERSION_NUMBER >= 0x10100000L
#include <openssl/modes.h>
#endif

#if !defined(TURN_NO_SYSTEMD)
#include <systemd/sd-daemon.h>
Expand Down
3 changes: 1 addition & 2 deletions src/apps/relay/netengine.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
#include "mainrelay.h"

//////////// Backward compatibility with OpenSSL 1.0.x //////////////
#if (OPENSSL_VERSION_NUMBER < 0x10100001L || \
(defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER <= 0x3040000fL))
#if defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER <= 0x3040000fL
#define SSL_CTX_up_ref(ctx) CRYPTO_add(&(ctx)->references, 1, CRYPTO_LOCK_SSL_CTX)
#endif

Expand Down
25 changes: 2 additions & 23 deletions src/apps/relay/ns_ioalib_engine_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1371,30 +1371,9 @@ ioa_socket_handle create_ioa_socket_from_fd(ioa_engine_handle e, ioa_socket_raw
}

static void ssl_info_callback(SSL *ssl, int where, int ret) {

UNUSED_ARG(ret);
UNUSED_ARG(ssl);
UNUSED_ARG(where);

#if OPENSSL_VERSION_NUMBER < 0x10100000L
#if defined(SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS)
if (0 != (where & SSL_CB_HANDSHAKE_START)) {
ioa_socket_handle s = (ioa_socket_handle)SSL_get_app_data(ssl);
if (s) {
++(s->ssl_renegs);
}
} else if (0 != (where & SSL_CB_HANDSHAKE_DONE)) {
if (ssl->s3) {
ioa_socket_handle s = (ioa_socket_handle)SSL_get_app_data(ssl);
if (s) {
if (s->ssl_renegs > SSL_MAX_RENEG_NUMBER) {
ssl->s3->flags |= SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS;
}
}
}
}
#endif
#endif
}

typedef void (*ssl_info_callback_t)(const SSL *ssl, int type, int val);
Expand Down Expand Up @@ -1835,7 +1814,7 @@ int ssl_read(evutil_socket_t fd, SSL *ssl, ioa_network_buffer_handle nbh, int ve
BIO *rbio = BIO_new_mem_buf(buffer, old_buffer_len);
BIO_set_mem_eof_return(rbio, -1);

#if OPENSSL_VERSION_NUMBER < 0x10100000L || (defined LIBRESSL_VERSION_NUMBER && LIBRESSL_VERSION_NUMBER < 0x3040000fL)
#if defined LIBRESSL_VERSION_NUMBER && LIBRESSL_VERSION_NUMBER < 0x3040000fL
ssl->rbio = rbio;
#else
SSL_set0_rbio(ssl, rbio);
Expand Down Expand Up @@ -1934,7 +1913,7 @@ int ssl_read(evutil_socket_t fd, SSL *ssl, ioa_network_buffer_handle nbh, int ve
if (ret > 0) {
ioa_network_buffer_add_offset_size(nbh, (uint16_t)buf_size, 0, (size_t)ret);
}
#if OPENSSL_VERSION_NUMBER < 0x10100000L || (defined LIBRESSL_VERSION_NUMBER && LIBRESSL_VERSION_NUMBER < 0x3040000fL)
#if defined LIBRESSL_VERSION_NUMBER && LIBRESSL_VERSION_NUMBER < 0x3040000fL
ssl->rbio = NULL;
BIO_free(rbio);
#else
Expand Down

0 comments on commit 4d32823

Please sign in to comment.