forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tls_wrap: fix error cb when fatal TLS Alert recvd
SSL_read() returns 0 when fatal TLS Alert is received. Fix to invoke ssl error callback in this case. PR-URL: nodejs#1661 Reviewed-By: Fedor Indutny <[email protected]>
- Loading branch information
1 parent
0e9be82
commit 4ba3d68
Showing
2 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
var common = require('../common'); | ||
var assert = require('assert'); | ||
|
||
if (!common.opensslCli) { | ||
console.error('Skipping because node compiled without OpenSSL CLI.'); | ||
process.exit(0); | ||
} | ||
|
||
if (!common.hasCrypto) { | ||
console.log('1..0 # Skipped: missing crypto'); | ||
process.exit(); | ||
} | ||
|
||
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 opts = { | ||
key: loadPEM('agent2-key'), | ||
cert: loadPEM('agent2-cert') | ||
}; | ||
|
||
var max_iter = 20; | ||
var iter = 0; | ||
|
||
var server = tls.createServer(opts, function(s) { | ||
s.pipe(s); | ||
s.on('error', function(e) { | ||
// ignore error | ||
}); | ||
}); | ||
|
||
server.listen(common.PORT, function() { | ||
sendClient(); | ||
}); | ||
|
||
|
||
function sendClient() { | ||
var client = tls.connect(common.PORT, { | ||
rejectUnauthorized: false | ||
}); | ||
client.on('data', function(chunk) { | ||
if (iter++ === 2) sendBADTLSRecord(); | ||
if (iter < max_iter) { | ||
client.write('a'); | ||
return; | ||
} | ||
client.end(); | ||
server.close(); | ||
success = true; | ||
}); | ||
client.write('a'); | ||
client.on('error', function(e) { | ||
// ignore error | ||
}); | ||
client.on('close', function() { | ||
server.close(); | ||
}); | ||
} | ||
|
||
|
||
function sendBADTLSRecord() { | ||
var BAD_RECORD = new Buffer([0xff, 0xff, 0xff, 0xff, 0xff, 0xff]); | ||
var socket = net.connect(common.PORT); | ||
var client = tls.connect({ | ||
socket: socket, | ||
rejectUnauthorized: false | ||
}, function() { | ||
socket.write(BAD_RECORD); | ||
socket.end(); | ||
}); | ||
client.on('error', function(e) { | ||
// ignore error | ||
}); | ||
} | ||
|
||
process.on('exit', function() { | ||
assert(iter === max_iter); | ||
assert(success); | ||
}); |