Skip to content

Commit 963fe0f

Browse files
committed
src: combine TLSWrap/SSLWrap
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]>
1 parent bb62f4a commit 963fe0f

10 files changed

+2257
-2402
lines changed

node.gyp

+3-5
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@
933933
'src/crypto/crypto_keys.cc',
934934
'src/crypto/crypto_keygen.cc',
935935
'src/crypto/crypto_scrypt.cc',
936-
'src/crypto/crypto_ssl.cc',
936+
'src/crypto/crypto_tls.cc',
937937
'src/crypto/crypto_aes.cc',
938938
'src/crypto/crypto_bio.h',
939939
'src/crypto/crypto_clienthello-inl.h',
@@ -950,7 +950,7 @@
950950
'src/crypto/crypto_keys.h',
951951
'src/crypto/crypto_keygen.h',
952952
'src/crypto/crypto_scrypt.h',
953-
'src/crypto/crypto_ssl.h',
953+
'src/crypto/crypto_tls.h',
954954
'src/crypto/crypto_clienthello.h',
955955
'src/crypto/crypto_context.h',
956956
'src/crypto/crypto_ecdh.h',
@@ -960,9 +960,7 @@
960960
'src/crypto/crypto_random.h',
961961
'src/crypto/crypto_timing.h',
962962
'src/node_crypto.cc',
963-
'src/node_crypto.h',
964-
'src/tls_wrap.cc',
965-
'src/tls_wrap.h'
963+
'src/node_crypto.h'
966964
],
967965
}],
968966
[ 'OS in "linux freebsd mac" and '

src/crypto/crypto_common.cc

+2
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,8 @@ MaybeLocal<Array> GetClientHelloCiphers(
799799

800800

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

src/crypto/crypto_context.cc

+20
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,26 @@ void SecureContext::Init(const FunctionCallbackInfo<Value>& args) {
473473
SSL_CTX_set_tlsext_ticket_key_cb(sc->ctx_.get(), TicketCompatibilityCallback);
474474
}
475475

476+
SSLPointer SecureContext::CreateSSL() {
477+
return SSLPointer(SSL_new(ctx_.get()));
478+
}
479+
480+
void SecureContext::SetNewSessionCallback(NewSessionCb cb) {
481+
SSL_CTX_sess_set_new_cb(ctx_.get(), cb);
482+
}
483+
484+
void SecureContext::SetGetSessionCallback(GetSessionCb cb) {
485+
SSL_CTX_sess_set_get_cb(ctx_.get(), cb);
486+
}
487+
488+
void SecureContext::SetSelectSNIContextCallback(SelectSNIContextCb cb) {
489+
SSL_CTX_set_tlsext_servername_callback(ctx_.get(), cb);
490+
}
491+
492+
void SecureContext::SetKeylogCallback(KeylogCb cb) {
493+
SSL_CTX_set_keylog_callback(ctx_.get(), cb);
494+
}
495+
476496
void SecureContext::SetKey(const FunctionCallbackInfo<Value>& args) {
477497
Environment* env = Environment::GetCurrent(args);
478498

src/crypto/crypto_context.h

+14
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,26 @@ void IsExtraRootCertsFileLoaded(
2323

2424
class SecureContext final : public BaseObject {
2525
public:
26+
using GetSessionCb = SSL_SESSION* (*)(SSL*, const unsigned char*, int, int*);
27+
using KeylogCb = void (*)(const SSL*, const char*);
28+
using NewSessionCb = int (*)(SSL*, SSL_SESSION*);
29+
using SelectSNIContextCb = int (*)(SSL*, int*, void*);
30+
2631
~SecureContext() override;
2732

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

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

37+
SSL_CTX* ssl_ctx() const { return ctx_.get(); }
38+
39+
SSLPointer CreateSSL();
40+
41+
void SetGetSessionCallback(GetSessionCb cb);
42+
void SetKeylogCallback(KeylogCb cb);
43+
void SetNewSessionCallback(NewSessionCb cb);
44+
void SetSelectSNIContextCallback(SelectSNIContextCb cb);
45+
3246
// TODO(joyeecheung): track the memory used by OpenSSL types
3347
SET_NO_MEMORY_INFO()
3448
SET_MEMORY_INFO_NAME(SecureContext)

0 commit comments

Comments
 (0)