Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: use BaseObjectPtr to store SNI context #30548

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/node_crypto.cc
Expand Up @@ -144,6 +144,7 @@ template void SSLWrap<TLSWrap>::AddMethods(Environment* env,
template void SSLWrap<TLSWrap>::ConfigureSecureContext(SecureContext* sc);
template void SSLWrap<TLSWrap>::SetSNIContext(SecureContext* sc);
template int SSLWrap<TLSWrap>::SetCACerts(SecureContext* sc);
template void SSLWrap<TLSWrap>::MemoryInfo(MemoryTracker* tracker) const;
template SSL_SESSION* SSLWrap<TLSWrap>::GetSessionCallback(
SSL* s,
const unsigned char* key,
Expand Down Expand Up @@ -2990,9 +2991,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);
bnoordhuis marked this conversation as resolved.
Show resolved Hide resolved

int rv;

Expand Down Expand Up @@ -3074,6 +3081,12 @@ int SSLWrap<Base>::SetCACerts(SecureContext* sc) {
return 1;
}

template <class Base>
void SSLWrap<Base>::MemoryInfo(MemoryTracker* tracker) const {
tracker->TrackField("ocsp_response", ocsp_response_);
tracker->TrackField("sni_context", sni_context_);
}

int VerifyCallback(int preverify_ok, X509_STORE_CTX* ctx) {
// From https://www.openssl.org/docs/man1.1.1/man3/SSL_verify_cb:
//
Expand Down
4 changes: 3 additions & 1 deletion src/node_crypto.h
Expand Up @@ -222,6 +222,8 @@ class SSLWrap {
inline bool is_awaiting_new_session() const { return awaiting_new_session_; }
inline bool is_waiting_cert_cb() const { return cert_cb_ != nullptr; }

void MemoryInfo(MemoryTracker* tracker) const;

protected:
typedef void (*CertCb)(void* arg);

Expand Down Expand Up @@ -308,7 +310,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
4 changes: 2 additions & 2 deletions src/tls_wrap.cc
Expand Up @@ -1065,10 +1065,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 All @@ -1089,6 +1088,7 @@ void TLSWrap::GetWriteQueueSize(const FunctionCallbackInfo<Value>& info) {


void TLSWrap::MemoryInfo(MemoryTracker* tracker) const {
SSLWrap<TLSWrap>::MemoryInfo(tracker);
tracker->TrackField("error", error_);
tracker->TrackFieldWithSize("pending_cleartext_input",
pending_cleartext_input_.size(),
Expand Down