Skip to content

Instantly share code, notes, and snippets.

@indutny

indutny/1.patch Secret

Created November 13, 2013 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save indutny/9e082ee7aee5957b75ab to your computer and use it in GitHub Desktop.
Save indutny/9e082ee7aee5957b75ab to your computer and use it in GitHub Desktop.
commit 2cac7f469ba440a04715a7a1573c26f1b9939fd1
Author: Fedor Indutny <fedor.indutny@gmail.com>
Date: Wed Nov 13 16:58:46 2013 +0400
tls: handle `ssl.start()` errors
diff --git a/lib/tls.js b/lib/tls.js
index f575bd6..931dd0b 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.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;
+ });
+})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment