GeezerVison is showing github.com — tls: emit errors on close whilst async action · indutny/io.js@c359ada
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/_tls_wrap.js +15Lines changed: 15 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -61,6 +61,9 @@ function loadSession(self, hello, cb) { | 61 | 61 | if (err) | 62 | 62 | return cb(err); | 63 | 63 |
| | 64 | + if (!self._handle) | | 65 | + return cb(new Error('Socket is closed')); | | 66 | + | 64 | 67 | // NOTE: That we have disabled OpenSSL's internal session storage in | 65 | 68 | // `node_crypto.cc` and hence its safe to rely on getting servername only | 66 | 69 | // from clienthello or this place. | @@ -91,6 +94,9 @@ function loadSNI(self, servername, cb) { | 91 | 94 | if (err) | 92 | 95 | return cb(err); | 93 | 96 |
| | 97 | + if (!self._handle) | | 98 | + return cb(new Error('Socket is closed')); | | 99 | + | 94 | 100 | // TODO(indutny): eventually disallow raw `SecureContext` | 95 | 101 | if (context) | 96 | 102 | self._handle.sni_context = context.context || context; | @@ -127,6 +133,9 @@ function requestOCSP(self, hello, ctx, cb) { | 127 | 133 | if (err) | 128 | 134 | return cb(err); | 129 | 135 |
| | 136 | + if (!self._handle) | | 137 | + return cb(new Error('Socket is closed')); | | 138 | + | 130 | 139 | if (response) | 131 | 140 | self._handle.setOCSPResponse(response); | 132 | 141 | cb(null); | @@ -157,6 +166,9 @@ function oncertcb(info) { | 157 | 166 | if (err) | 158 | 167 | return self.destroy(err); | 159 | 168 |
| | 169 | + if (!self._handle) | | 170 | + return cb(new Error('Socket is closed')); | | 171 | + | 160 | 172 | self._handle.certCbDone(); | 161 | 173 | }); | 162 | 174 | }); | @@ -179,6 +191,9 @@ function onnewsession(key, session) { | 179 | 191 | return; | 180 | 192 | once = true; | 181 | 193 |
| | 194 | + if (!self._handle) | | 195 | + return cb(new Error('Socket is closed')); | | 196 | + | 182 | 197 | self._handle.newSessionDone(); | 183 | 198 |
| 184 | 199 | self._newSessionPending = false; | |
Collapse file Copy file name to clipboard +73Lines changed: 73 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +'use strict'; | | 2 | + | | 3 | +var common = require('../common'); | | 4 | + | | 5 | +var assert = require('assert'); | | 6 | +var path = require('path'); | | 7 | +var fs = require('fs'); | | 8 | +var constants = require('constants'); | | 9 | + | | 10 | +if (!common.hasCrypto) { | | 11 | + console.log('1..0 # Skipped: missing crypto'); | | 12 | + process.exit(); | | 13 | +} | | 14 | + | | 15 | +var tls = require('tls'); | | 16 | + | | 17 | +var options = { | | 18 | + secureOptions: constants.SSL_OP_NO_TICKET, | | 19 | + key: fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem')), | | 20 | + cert: fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem')) | | 21 | +}; | | 22 | + | | 23 | +var server = tls.createServer(options, function(c) { | | 24 | +}); | | 25 | + | | 26 | +var sessionCb = null; | | 27 | +var client = null; | | 28 | + | | 29 | +server.on('newSession', function(key, session, done) { | | 30 | + done(); | | 31 | +}); | | 32 | + | | 33 | +server.on('resumeSession', function(id, cb) { | | 34 | + sessionCb = cb; | | 35 | + | | 36 | + next(); | | 37 | +}); | | 38 | + | | 39 | +server.listen(1443, function() { | | 40 | + var clientOpts = { | | 41 | + port: 1443, | | 42 | + rejectUnauthorized: false, | | 43 | + session: false | | 44 | + }; | | 45 | + | | 46 | + var s1 = tls.connect(clientOpts, function() { | | 47 | + clientOpts.session = s1.getSession(); | | 48 | + console.log('1st secure'); | | 49 | + | | 50 | + s1.destroy(); | | 51 | + var s2 = tls.connect(clientOpts, function(s) { | | 52 | + console.log('2nd secure'); | | 53 | + | | 54 | + s2.destroy(); | | 55 | + }).on('connect', function() { | | 56 | + console.log('2nd connected'); | | 57 | + client = s2; | | 58 | + | | 59 | + next(); | | 60 | + }); | | 61 | + }); | | 62 | +}); | | 63 | + | | 64 | +function next() { | | 65 | + if (!client || !sessionCb) | | 66 | + return; | | 67 | + | | 68 | + client.destroy(); | | 69 | + setTimeout(function() { | | 70 | + sessionCb(); | | 71 | + server.close(); | | 72 | + }, 100); | | 73 | +} |
|