crypto: fix legacy SNICallback
authorFedor Indutny <fedor@indutny.com>
Sun, 17 May 2015 13:10:24 +0000 (15:10 +0200)
committerFedor Indutny <fedor@indutny.com>
Wed, 22 Jul 2015 21:00:37 +0000 (14:00 -0700)
`onselect` is set on the `sniObject_` not on the `Connection` instance.

See: https://github.com/joyent/node/pull/25109
PR-URL: https://github.com/nodejs/io.js/pull/1720
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
src/node_crypto.cc
test/parallel/test-tls-legacy-onselect.js [new file with mode: 0644]

index 915ba05..ba71eb7 100644 (file)
@@ -2346,8 +2346,15 @@ int Connection::SelectSNIContextCallback_(SSL *s, int *ad, void* arg) {
     if (!conn->sniObject_.IsEmpty()) {
       conn->sni_context_.Reset();
 
+      Local<Object> sni_obj = PersistentToLocal(env->isolate(),
+                                                conn->sniObject_);
+
       Local<Value> arg = PersistentToLocal(env->isolate(), conn->servername_);
-      Local<Value> ret = conn->MakeCallback(env->onselect_string(), 1, &arg);
+      Local<Value> ret = node::MakeCallback(env->isolate(),
+                                            sni_obj,
+                                            env->onselect_string(),
+                                            1,
+                                            &arg);
 
       // If ret is SecureContext
       Local<FunctionTemplate> secure_context_constructor_template =
diff --git a/test/parallel/test-tls-legacy-onselect.js b/test/parallel/test-tls-legacy-onselect.js
new file mode 100644 (file)
index 0000000..6f1e9a9
--- /dev/null
@@ -0,0 +1,45 @@
+'use strict';
+var common = require('../common');
+var assert = require('assert');
+
+if (!common.hasCrypto) {
+  console.log('1..0 # Skipped: missing crypto');
+  return;
+}
+var tls = require('tls');
+var net = require('net');
+
+var fs = require('fs');
+
+var success = false;
+
+function filenamePEM(n) {
+  return require('path').join(common.fixturesDir, 'keys', n + '.pem');
+}
+
+function loadPEM(n) {
+  return fs.readFileSync(filenamePEM(n));
+}
+
+var server = net.Server(function(raw) {
+  var pair = tls.createSecurePair(null, true, false, false);
+  pair.on('error', function() {});
+  pair.ssl.setSNICallback(function() {
+    raw.destroy();
+    server.close();
+    success = true;
+  });
+  require('_tls_legacy').pipe(pair, raw);
+}).listen(common.PORT, function() {
+  tls.connect({
+    port: common.PORT,
+    rejectUnauthorized: false,
+    servername: 'server'
+  }, function() {
+  }).on('error', function() {
+    // Just ignore
+  });
+});
+process.on('exit', function() {
+  assert(success);
+});