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 <[email protected]>
  • Loading branch information
jasnell committed Oct 12, 2020
1 parent bb62f4a commit 963fe0f
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 @@ -933,7 +933,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 @@ -950,7 +950,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 @@ -960,9 +960,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 @@ -473,6 +473,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 963fe0f

Please sign in to comment.