tls: handle `ssl.start()` errors
authorFedor Indutny <fedor.indutny@gmail.com>
Wed, 13 Nov 2013 12:58:46 +0000 (16:58 +0400)
committerFedor Indutny <fedor.indutny@gmail.com>
Wed, 13 Nov 2013 13:09:25 +0000 (17:09 +0400)
lib/tls.js
test/simple/test-tls-connect.js

index f575bd6..2077b8f 100644 (file)
@@ -940,6 +940,10 @@ function SecurePair(credentials, isServer, requestCert, rejectUnauthorized,
     /* The Connection may be destroyed by an abort call */
     if (self.ssl) {
       self.ssl.start();
+
+      /* In case of cipher suite failures - SSL_accept/SSL_connect may fail */
+      if (self.ssl && self.ssl.error)
+        self.error();
     }
   });
 }
index fe2d17f..616f76c 100644 (file)
@@ -50,3 +50,28 @@ var path = require('path');
     errorEmitted = true;
   });
 })();
+
+// SSL_accept/SSL_connect error handling
+(function() {
+  var cert = fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem'));
+  var key = fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem'));
+
+  var errorEmitted = false;
+
+  process.on('exit', function() {
+    assert.ok(errorEmitted);
+  });
+
+  var conn = tls.connect({
+    cert: cert,
+    key: key,
+    port: common.PORT,
+    ciphers: 'rick-128-roll'
+  }, function() {
+    assert.ok(false); // callback should never be executed
+  });
+
+  conn.on('error', function() {
+    errorEmitted = true;
+  });
+})();