Skip to content

Commit

Permalink
Update to Node v12 (lynckia#1500)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcague authored Nov 20, 2019
1 parent cb2d43c commit 27749a4
Show file tree
Hide file tree
Showing 21 changed files with 199 additions and 191 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.14.4
12.13.0
26 changes: 22 additions & 4 deletions erizo/src/erizo/dtls/DtlsClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ extern "C" {
#include <cstring>

#include "./DtlsSocket.h"
#include "./bf_dwrap.h"

using dtls::DtlsSocketContext;
using dtls::DtlsSocket;
Expand All @@ -42,30 +41,42 @@ static std::mutex* array_mutex;

DEFINE_LOGGER(DtlsSocketContext, "dtls.DtlsSocketContext");
log4cxx::LoggerPtr sslLogger(log4cxx::Logger::getLogger("dtls.SSL"));

#if OPENSSL_VERSION_NUMBER < 0x10100000
static void ssl_lock_callback(int mode, int type, const char* file, int line) {
if (mode & CRYPTO_LOCK) {
array_mutex[type].lock();
} else {
array_mutex[type].unlock();
}
}

static unsigned long ssl_thread_id() { // NOLINT
#if OPENSSL_VERSION_NUMBER < 0x10000000
unsigned long ssl_thread_id() { // NOLINT
return (unsigned long)std::hash<std::thread::id>()(std::this_thread::get_id()); // NOLINT
}
#else
void ssl_thread_id(CRYPTO_THREADID *id) { // NOLINT
CRYPTO_THREADID_set_numeric(id, (unsigned long)std::hash<std::thread::id>()(std::this_thread::get_id()); // NOLINT
}
#endif
#endif

#if OPENSSL_VERSION_NUMBER < 0x10100000
static int ssl_thread_setup() {
array_mutex = new std::mutex[CRYPTO_num_locks()];

if (!array_mutex) {
return 0;
} else {
#if OPENSSL_VERSION_NUMBER < 0x10000000
CRYPTO_set_id_callback(ssl_thread_id);
#else
CRYPTO_THREADID_set_callback(ssl_thread_id);
#endif
CRYPTO_set_locking_callback(ssl_lock_callback);
}
return 1;
}
#endif

static int ssl_thread_cleanup() {
if (!array_mutex) {
Expand Down Expand Up @@ -298,6 +309,7 @@ int createCert(const std::string& pAor, int expireDays, int keyLen, X509*& outCe
}

void DtlsSocketContext::Init() {
#if OPENSSL_VERSION_NUMBER < 0x10100000
ssl_thread_setup();
if (DtlsSocketContext::mCert == nullptr) {
OpenSSL_add_all_algorithms();
Expand All @@ -306,6 +318,12 @@ int createCert(const std::string& pAor, int expireDays, int keyLen, X509*& outCe
ERR_load_crypto_strings();
createCert("sip:[email protected]", 365, 1024, DtlsSocketContext::mCert, DtlsSocketContext::privkey);
}
#else
if (DtlsSocketContext::mCert == nullptr) {
OPENSSL_init_ssl(0, NULL);
createCert("sip:[email protected]", 365, 1024, DtlsSocketContext::mCert, DtlsSocketContext::privkey);
}
#endif
}

void DtlsSocketContext::Destroy() {
Expand Down
20 changes: 10 additions & 10 deletions erizo/src/erizo/dtls/DtlsSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#include "./config.h"
#endif

#include "./bf_dwrap.h"

using dtls::DtlsSocket;
using dtls::SrtpSessionKeys;
using std::memcpy;
Expand All @@ -32,8 +30,6 @@ DtlsSocket::DtlsSocket(DtlsSocketContext* socketContext, enum SocketType type):
mSsl = SSL_new(mContext);
assert(mSsl != 0);
SSL_set_mtu(mSsl, DTLS_MTU);
mSsl->ctx = mContext;
mSsl->session_ctx = mContext;

switch (type) {
case Client:
Expand All @@ -48,13 +44,16 @@ DtlsSocket::DtlsSocket(DtlsSocketContext* socketContext, enum SocketType type):
default:
assert(0);
}
BIO* memBIO1 = BIO_new(BIO_s_mem());
mInBio = BIO_new(BIO_f_dwrap());
BIO_push(mInBio, memBIO1);

BIO* memBIO2 = BIO_new(BIO_s_mem());
mOutBio = BIO_new(BIO_f_dwrap());
BIO_push(mOutBio, memBIO2);
dwrap_bio_method = BIO_f_dwrap();

BIO* mem_in_BIO = BIO_new(BIO_s_mem());
mInBio = BIO_new(dwrap_bio_method);
BIO_push(mInBio, mem_in_BIO);

BIO* mem_out_BIO = BIO_new(BIO_s_mem());
mOutBio = BIO_new(dwrap_bio_method);
BIO_push(mOutBio, mem_out_BIO);

SSL_set_bio(mSsl, mInBio, mOutBio);
SSL_accept(mSsl);
Expand All @@ -71,6 +70,7 @@ void DtlsSocket::close() {
ELOG_DEBUG("SSL Shutdown");
SSL_shutdown(mSsl);
SSL_free(mSsl);
BIO_f_wrap_destroy(dwrap_bio_method);
mSsl = NULL;
}
}
Expand Down
2 changes: 2 additions & 0 deletions erizo/src/erizo/dtls/DtlsSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extern "C" {
#include <memory>
#include <string>

#include "dtls/bf_dwrap.h"
#include "../logger.h"

const int SRTP_MASTER_KEY_KEY_LEN = 16;
Expand Down Expand Up @@ -117,6 +118,7 @@ class DtlsSocket {
DtlsSocketContext* mSocketContext;

// OpenSSL context data
BIO_METHOD *dwrap_bio_method;
SSL *mSsl;
BIO *mInBio;
BIO *mOutBio;
Expand Down
77 changes: 36 additions & 41 deletions erizo/src/erizo/dtls/bf_dwrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,58 @@
#include <assert.h>
#include <memory.h>

#define BIO_TYPE_DWRAP (50 | 0x0400 | 0x0200)
#define BIO_TYPE_DWRAP (50|0x0400|0x0200)

static int dwrap_new(BIO *bio);
static int dwrap_free(BIO *a);
static int dwrap_create(BIO *bio);
static int dwrap_destroy(BIO *a);
static int dwrap_read(BIO *b, char *out, int outl);
static int dwrap_write(BIO *b, const char *in, int inl);
static int dwrap_puts(BIO *b, const char *in);
static int dwrap_gets(BIO *b, char *buf, int size);
static long dwrap_ctrl(BIO *b, int cmd, long num, void *ptr); // NOLINT(runtime/int)
static long dwrap_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp); // NOLINT(runtime/int)

static BIO_METHOD methods_dwrap = {
BIO_TYPE_DWRAP,
"dtls_wrapper",
dwrap_write,
dwrap_read,
dwrap_puts,
dwrap_gets,
dwrap_ctrl,
dwrap_new,
dwrap_free,
dwrap_callback_ctrl
};

typedef struct BIO_F_DWRAP_CTX_ {
int dgram_timer_exp;
} BIO_F_DWRAP_CTX;


BIO_METHOD *BIO_f_dwrap(void) {
return(&methods_dwrap);
BIO_METHOD *method = BIO_meth_new(BIO_TYPE_DWRAP, "dtls_wrapper");
BIO_meth_set_write(method, dwrap_write);
BIO_meth_set_read(method, dwrap_read);
BIO_meth_set_puts(method, dwrap_puts);
BIO_meth_set_ctrl(method, dwrap_ctrl);
BIO_meth_set_gets(method, dwrap_gets);
BIO_meth_set_create(method, dwrap_create);
BIO_meth_set_destroy(method, dwrap_destroy);
BIO_meth_set_callback_ctrl(method, dwrap_callback_ctrl);
return method;
}

void BIO_f_wrap_destroy(BIO_METHOD *method) {
BIO_meth_free(method);
}

static int dwrap_new(BIO *bi) {
BIO_F_DWRAP_CTX *ctx = OPENSSL_malloc(sizeof(BIO_F_BUFFER_CTX));
static int dwrap_create(BIO *bi) {
BIO_F_DWRAP_CTX *ctx = OPENSSL_malloc(sizeof(BIO_F_DWRAP_CTX));
if (!ctx) return(0);

memset(ctx, 0, sizeof(BIO_F_BUFFER_CTX));
memset(ctx, 0, sizeof(BIO_F_DWRAP_CTX));

bi->init = 1;
bi->ptr = (char *)ctx; // NOLINT
bi->flags = 0;
BIO_set_init(bi, 1);
BIO_set_data(bi, (char *)ctx); // NOLINT
BIO_set_flags(bi, 0);

return 1;
}

static int dwrap_free(BIO *a) {
static int dwrap_destroy(BIO *a) {
if (a == NULL) return 0;

OPENSSL_free(a->ptr);
a->ptr = NULL;
a->init = 0;
a->flags = 0;
BIO_F_DWRAP_CTX *ctx = (BIO_F_DWRAP_CTX*)BIO_get_data(a);
OPENSSL_free(ctx);
BIO_set_init(a, 0);
BIO_set_flags(a, 0);
return 1;
}

Expand All @@ -68,7 +67,8 @@ static int dwrap_read(BIO *b, char *out, int outl) {

BIO_clear_retry_flags(b);

ret = BIO_read(b->next_bio, out, outl);
BIO *next = BIO_next(b);
ret = BIO_read(next, out, outl);

if (ret <= 0) {
BIO_copy_next_retry(b);
Expand All @@ -82,7 +82,9 @@ static int dwrap_write(BIO *b, const char *in, int inl) {
return 0;
}

int ret = BIO_write(b->next_bio, in, inl);
BIO *next = BIO_next(b);

int ret = BIO_write(next, in, inl);
return ret;
}

Expand All @@ -102,7 +104,7 @@ static long dwrap_ctrl(BIO *b, int cmd, long num, void *ptr) { // NOLINT(runtim
long ret; // NOLINT(runtime/int)
BIO_F_DWRAP_CTX *ctx;

ctx = b->ptr;
ctx = (BIO_F_DWRAP_CTX*) BIO_get_data(b);

switch (cmd) {
case BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP:
Expand All @@ -120,7 +122,7 @@ static long dwrap_ctrl(BIO *b, int cmd, long num, void *ptr) { // NOLINT(runtim
ret = 1;
break;
default:
ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
ret = BIO_ctrl(BIO_next(b), cmd, num, ptr);
break;
}

Expand All @@ -130,32 +132,26 @@ static long dwrap_ctrl(BIO *b, int cmd, long num, void *ptr) { // NOLINT(runtim
static long dwrap_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) { // NOLINT(runtime/int)
long ret; // NOLINT(runtime/int)

ret = BIO_callback_ctrl(b->next_bio, cmd, fp);
ret = BIO_callback_ctrl(BIO_next(b), cmd, fp);

return ret;
}


/* ====================================================================
Copyright (c) 2007-2008, Eric Rescorla and Derek MacDonald
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. None of the contributors names may be used to endorse or promote
products derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Expand All @@ -167,5 +163,4 @@ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
==================================================================== */
10 changes: 2 additions & 8 deletions erizo/src/erizo/dtls/bf_dwrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,26 @@
#define ERIZO_SRC_ERIZO_DTLS_BF_DWRAP_H_

extern "C" {
BIO_METHOD *BIO_f_dwrap(void);
BIO_METHOD *BIO_f_dwrap(void);
void BIO_f_wrap_destroy(BIO_METHOD *method);
}

#endif // ERIZO_SRC_ERIZO_DTLS_BF_DWRAP_H_

/* ====================================================================
Copyright (c) 2007-2008, Eric Rescorla and Derek MacDonald
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. None of the contributors names may be used to endorse or promote
products derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Expand All @@ -38,5 +33,4 @@ extern "C" {
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
==================================================================== */
4 changes: 2 additions & 2 deletions erizoAPI/AsyncPromiseWorker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ void AsyncPromiseWorker::Execute() {
void AsyncPromiseWorker::HandleOKCallback() {
Nan::HandleScope scope;
auto resolver = Nan::New(*_persistent);
resolver->Resolve(Nan::GetCurrentContext(), Nan::New("").ToLocalChecked());
resolver->Resolve(Nan::GetCurrentContext(), Nan::New("").ToLocalChecked()).IsNothing();
}

void AsyncPromiseWorker::HandleErrorCallback() {
Nan::HandleScope scope;
auto resolver = Nan::New(*_persistent);
resolver->Reject(Nan::GetCurrentContext(), Nan::New("").ToLocalChecked());
resolver->Reject(Nan::GetCurrentContext(), Nan::New("").ToLocalChecked()).IsNothing();
}

Loading

0 comments on commit 27749a4

Please sign in to comment.