From 7dfa587d18c9d55cf2625c138250ef02c464d911 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Mon, 3 Sep 2012 23:26:19 +0200 Subject: [PATCH] crypto, tls: make setSNICallback() compatible with domains --- src/node_crypto.cc | 23 ++++++++++------------- src/node_crypto.h | 4 ++-- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 50f0b42d1fa..0d681bb81f2 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -938,23 +938,20 @@ int Connection::SelectSNIContextCallback_(SSL *s, int *ad, void* arg) { } p->servername_ = Persistent::New(String::New(servername)); - // Call sniCallback_ and use it's return value as context - if (!p->sniCallback_.IsEmpty()) { + // Call the SNI callback and use its return value as context + if (!p->sniObject_.IsEmpty()) { if (!p->sniContext_.IsEmpty()) { p->sniContext_.Dispose(); } // Get callback init args Local argv[1] = {*p->servername_}; - Local callback = *p->sniCallback_; // Call it - // - // XXX There should be an object connected to this that - // we can attach a domain onto. - Local ret; - ret = Local::New(MakeCallback(Context::GetCurrent()->Global(), - callback, ARRAY_SIZE(argv), argv)); + Local ret = Local::New(MakeCallback(p->sniObject_, + "onselect", + ARRAY_SIZE(argv), + argv)); // If ret is SecureContext if (secure_context_constructor->HasInstance(ret)) { @@ -1774,11 +1771,11 @@ Handle Connection::SetSNICallback(const Arguments& args) { } // Release old handle - if (!ss->sniCallback_.IsEmpty()) { - ss->sniCallback_.Dispose(); + if (!ss->sniObject_.IsEmpty()) { + ss->sniObject_.Dispose(); } - ss->sniCallback_ = Persistent::New( - Local::Cast(args[0])); + ss->sniObject_ = Persistent::New(Object::New()); + ss->sniObject_->Set(String::New("onselect"), args[0]); return True(); } diff --git a/src/node_crypto.h b/src/node_crypto.h index 1ee23c8a74b..fe433596ac4 100644 --- a/src/node_crypto.h +++ b/src/node_crypto.h @@ -110,7 +110,7 @@ class Connection : ObjectWrap { #endif #ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB - v8::Persistent sniCallback_; + v8::Persistent sniObject_; v8::Persistent sniContext_; v8::Persistent servername_; #endif @@ -185,7 +185,7 @@ class Connection : ObjectWrap { #endif #ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB - if (!sniCallback_.IsEmpty()) sniCallback_.Dispose(); + if (!sniObject_.IsEmpty()) sniObject_.Dispose(); if (!sniContext_.IsEmpty()) sniContext_.Dispose(); if (!servername_.IsEmpty()) servername_.Dispose(); #endif