Skip to content

Commit

Permalink
src: combine TLSWrap/SSLWrap
Browse files Browse the repository at this point in the history
SSLWrap was needlessly defined as a template class, splitting the
TLS implementation over multiple locations. The original idea, I
surmise, was to make it possible to reuse SSLWrap for some other
purpose that never manifest. This squashes them down into a single
TLSWrap class and moves tls_wrap.h/cc into src/crypto.

Signed-off-by: James M Snell <jasnell@gmail.com>

PR-URL: #35552
Reviewed-By: Alba Mendez <me@alba.sh>
  • Loading branch information
jasnell committed Oct 15, 2020
1 parent 6751b6d commit bfc9069
Show file tree
Hide file tree
Showing 10 changed files with 2,257 additions and 2,402 deletions.
8 changes: 3 additions & 5 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@
'src/crypto/crypto_keys.cc',
'src/crypto/crypto_keygen.cc',
'src/crypto/crypto_scrypt.cc',
'src/crypto/crypto_ssl.cc',
'src/crypto/crypto_tls.cc',
'src/crypto/crypto_aes.cc',
'src/crypto/crypto_bio.h',
'src/crypto/crypto_clienthello-inl.h',
Expand All @@ -951,7 +951,7 @@
'src/crypto/crypto_keys.h',
'src/crypto/crypto_keygen.h',
'src/crypto/crypto_scrypt.h',
'src/crypto/crypto_ssl.h',
'src/crypto/crypto_tls.h',
'src/crypto/crypto_clienthello.h',
'src/crypto/crypto_context.h',
'src/crypto/crypto_ecdh.h',
Expand All @@ -961,9 +961,7 @@
'src/crypto/crypto_random.h',
'src/crypto/crypto_timing.h',
'src/node_crypto.cc',
'src/node_crypto.h',
'src/tls_wrap.cc',
'src/tls_wrap.h'
'src/node_crypto.h'
],
}],
[ 'OS in "linux freebsd mac" and '
Expand Down
2 changes: 2 additions & 0 deletions src/crypto/crypto_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,8 @@ MaybeLocal<Array> GetClientHelloCiphers(


MaybeLocal<Object> GetCipherInfo(Environment* env, const SSLPointer& ssl) {
if (SSL_get_current_cipher(ssl.get()) == nullptr)
return MaybeLocal<Object>();
EscapableHandleScope scope(env->isolate());
Local<Object> info = Object::New(env->isolate());

Expand Down
20 changes: 20 additions & 0 deletions src/crypto/crypto_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,26 @@ void SecureContext::Init(const FunctionCallbackInfo<Value>& args) {
SSL_CTX_set_tlsext_ticket_key_cb(sc->ctx_.get(), TicketCompatibilityCallback);
}

SSLPointer SecureContext::CreateSSL() {
return SSLPointer(SSL_new(ctx_.get()));
}

void SecureContext::SetNewSessionCallback(NewSessionCb cb) {
SSL_CTX_sess_set_new_cb(ctx_.get(), cb);
}

void SecureContext::SetGetSessionCallback(GetSessionCb cb) {
SSL_CTX_sess_set_get_cb(ctx_.get(), cb);
}

void SecureContext::SetSelectSNIContextCallback(SelectSNIContextCb cb) {
SSL_CTX_set_tlsext_servername_callback(ctx_.get(), cb);
}

void SecureContext::SetKeylogCallback(KeylogCb cb) {
SSL_CTX_set_keylog_callback(ctx_.get(), cb);
}

void SecureContext::SetKey(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);

Expand Down
14 changes: 14 additions & 0 deletions src/crypto/crypto_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,26 @@ void IsExtraRootCertsFileLoaded(

class SecureContext final : public BaseObject {
public:
using GetSessionCb = SSL_SESSION* (*)(SSL*, const unsigned char*, int, int*);
using KeylogCb = void (*)(const SSL*, const char*);
using NewSessionCb = int (*)(SSL*, SSL_SESSION*);
using SelectSNIContextCb = int (*)(SSL*, int*, void*);

~SecureContext() override;

static void Initialize(Environment* env, v8::Local<v8::Object> target);

SSL_CTX* operator*() const { return ctx_.get(); }

SSL_CTX* ssl_ctx() const { return ctx_.get(); }

SSLPointer CreateSSL();

void SetGetSessionCallback(GetSessionCb cb);
void SetKeylogCallback(KeylogCb cb);
void SetNewSessionCallback(NewSessionCb cb);
void SetSelectSNIContextCallback(SelectSNIContextCb cb);

// TODO(joyeecheung): track the memory used by OpenSSL types
SET_NO_MEMORY_INFO()
SET_MEMORY_INFO_NAME(SecureContext)
Expand Down
Loading

0 comments on commit bfc9069

Please sign in to comment.