Skip to content

Commit

Permalink
src: use BaseObjectPtr to store SNI context
Browse files Browse the repository at this point in the history
Rather than relying on a link to the JS object, store a pointer to
the C++ object directly.

PR-URL: #30548
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
  • Loading branch information
addaleax authored and targos committed Apr 28, 2020
1 parent 8961d33 commit ce8d8c0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
12 changes: 9 additions & 3 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2423,9 +2423,15 @@ void SSLWrap<Base>::CertCbDone(const FunctionCallbackInfo<Value>& args) {
goto fire_cb;

if (cons->HasInstance(ctx)) {
SecureContext* sc;
ASSIGN_OR_RETURN_UNWRAP(&sc, ctx.As<Object>());
w->sni_context_.Reset(env->isolate(), ctx);
SecureContext* sc = Unwrap<SecureContext>(ctx.As<Object>());
CHECK_NOT_NULL(sc);
// XXX: There is a method w->SetSNIContext(sc), and you might think that
// it makes sense to call that here and make setting w->sni_context_ part
// of it. In fact, that passes the test suite, although SetSNIContext()
// performs a lot more operations.
// If anybody is familiar enough with the TLS code to know whether it makes
// sense, please do so or document why it doesn't.
w->sni_context_ = BaseObjectPtr<SecureContext>(sc);

if (UseSNIContext(w->ssl_, sc) && !w->SetCACerts(sc)) {
// Not clear why sometimes we throw error, and sometimes we call
Expand Down
2 changes: 1 addition & 1 deletion src/node_crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ class SSLWrap {
ClientHelloParser hello_parser_;

v8::Global<v8::ArrayBufferView> ocsp_response_;
v8::Global<v8::Value> sni_context_;
BaseObjectPtr<SecureContext> sni_context_;

friend class SecureContext;
};
Expand Down
3 changes: 1 addition & 2 deletions src/tls_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1091,10 +1091,9 @@ int TLSWrap::SelectSNIContextCallback(SSL* s, int* ad, void* arg) {
return SSL_TLSEXT_ERR_NOACK;
}

p->sni_context_.Reset(env->isolate(), ctx);

SecureContext* sc = Unwrap<SecureContext>(ctx.As<Object>());
CHECK_NOT_NULL(sc);
p->sni_context_ = BaseObjectPtr<SecureContext>(sc);
p->SetSNIContext(sc);
return SSL_TLSEXT_ERR_OK;
}
Expand Down

0 comments on commit ce8d8c0

Please sign in to comment.