Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
crypto, tls: make setSNICallback() compatible with domains
  • Loading branch information
bnoordhuis committed Sep 3, 2012
1 parent 7d0543c commit 7dfa587
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
23 changes: 10 additions & 13 deletions src/node_crypto.cc
Expand Up @@ -938,23 +938,20 @@ int Connection::SelectSNIContextCallback_(SSL *s, int *ad, void* arg) {
}
p->servername_ = Persistent<String>::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<Value> argv[1] = {*p->servername_};
Local<Function> callback = *p->sniCallback_;

// Call it
//
// XXX There should be an object connected to this that
// we can attach a domain onto.
Local<Value> ret;
ret = Local<Value>::New(MakeCallback(Context::GetCurrent()->Global(),
callback, ARRAY_SIZE(argv), argv));
Local<Value> ret = Local<Value>::New(MakeCallback(p->sniObject_,
"onselect",
ARRAY_SIZE(argv),
argv));

// If ret is SecureContext
if (secure_context_constructor->HasInstance(ret)) {
Expand Down Expand Up @@ -1774,11 +1771,11 @@ Handle<Value> 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<Function>::New(
Local<Function>::Cast(args[0]));
ss->sniObject_ = Persistent<Object>::New(Object::New());
ss->sniObject_->Set(String::New("onselect"), args[0]);

return True();
}
Expand Down
4 changes: 2 additions & 2 deletions src/node_crypto.h
Expand Up @@ -110,7 +110,7 @@ class Connection : ObjectWrap {
#endif

#ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
v8::Persistent<v8::Function> sniCallback_;
v8::Persistent<v8::Object> sniObject_;
v8::Persistent<v8::Value> sniContext_;
v8::Persistent<v8::String> servername_;
#endif
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7dfa587

Please sign in to comment.