Skip to content

Commit bfc9069

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 <jasnell@gmail.com> PR-URL: #35552 Reviewed-By: Alba Mendez <me@alba.sh>
1 parent 6751b6d commit bfc9069

10 files changed

+2257
-2402
lines changed

node.gyp

+3-5
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@
934934
'src/crypto/crypto_keys.cc',
935935
'src/crypto/crypto_keygen.cc',
936936
'src/crypto/crypto_scrypt.cc',
937-
'src/crypto/crypto_ssl.cc',
937+
'src/crypto/crypto_tls.cc',
938938
'src/crypto/crypto_aes.cc',
939939
'src/crypto/crypto_bio.h',
940940
'src/crypto/crypto_clienthello-inl.h',
@@ -951,7 +951,7 @@
951951
'src/crypto/crypto_keys.h',
952952
'src/crypto/crypto_keygen.h',
953953
'src/crypto/crypto_scrypt.h',
954-
'src/crypto/crypto_ssl.h',
954+
'src/crypto/crypto_tls.h',
955955
'src/crypto/crypto_clienthello.h',
956956
'src/crypto/crypto_context.h',
957957
'src/crypto/crypto_ecdh.h',
@@ -961,9 +961,7 @@
961961
'src/crypto/crypto_random.h',
962962
'src/crypto/crypto_timing.h',
963963
'src/node_crypto.cc',
964-
'src/node_crypto.h',
965-
'src/tls_wrap.cc',
966-
'src/tls_wrap.h'
964+
'src/node_crypto.h'
967965
],
968966
}],
969967
[ '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
@@ -472,6 +472,26 @@ void SecureContext::Init(const FunctionCallbackInfo<Value>& args) {
472472
SSL_CTX_set_tlsext_ticket_key_cb(sc->ctx_.get(), TicketCompatibilityCallback);
473473
}
474474

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

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)