From 65b127572f274758eb2403fec4349350384de899 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Wed, 13 Nov 2013 16:58:46 +0400 Subject: [PATCH] tls: handle `ssl.start()` errors --- lib/tls.js | 4 ++++ test/simple/test-tls-connect.js | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/lib/tls.js b/lib/tls.js index f575bd6..2077b8f 100644 --- a/lib/tls.js +++ b/lib/tls.js @@ -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(); } }); } diff --git a/test/simple/test-tls-connect.js b/test/simple/test-tls-connect.js index fe2d17f..616f76c 100644 --- a/test/simple/test-tls-connect.js +++ b/test/simple/test-tls-connect.js @@ -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; + }); +})(); -- 2.7.4