TLS: don't use events when control hasn't been inverted
This commit is contained in:
parent
0ec57ea34c
commit
a0c55dfe09
44
lib/tls.js
44
lib/tls.js
@ -138,33 +138,6 @@ function SecurePair(credentials, isServer, requestCert, rejectUnauthorized) {
|
|||||||
self._destroy(err);
|
self._destroy(err);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.cleartext.on('end', function(err) {
|
|
||||||
debug('clearIn end');
|
|
||||||
if (!self._done) {
|
|
||||||
self._ssl.shutdown();
|
|
||||||
self._cycle();
|
|
||||||
}
|
|
||||||
self._destroy(err);
|
|
||||||
});
|
|
||||||
|
|
||||||
this.cleartext.on('close', function() {
|
|
||||||
debug('source close');
|
|
||||||
self.emit('close');
|
|
||||||
self._destroy();
|
|
||||||
});
|
|
||||||
|
|
||||||
this.cleartext.on('drain', function() {
|
|
||||||
debug('source drain');
|
|
||||||
self._cycle();
|
|
||||||
self.encrypted.resume();
|
|
||||||
});
|
|
||||||
|
|
||||||
this.encrypted.on('drain', function() {
|
|
||||||
debug('target drain');
|
|
||||||
self._cycle();
|
|
||||||
self.cleartext.resume();
|
|
||||||
});
|
|
||||||
|
|
||||||
process.nextTick(function() {
|
process.nextTick(function() {
|
||||||
self._ssl.start();
|
self._ssl.start();
|
||||||
self._cycle();
|
self._cycle();
|
||||||
@ -267,6 +240,7 @@ SecurePair.prototype._cycle = function() {
|
|||||||
// pair.encrypted.write(d)
|
// pair.encrypted.write(d)
|
||||||
// });
|
// });
|
||||||
//
|
//
|
||||||
|
var encPending = this._encInPending.length > 0;
|
||||||
while (this._encInPending.length > 0) {
|
while (this._encInPending.length > 0) {
|
||||||
tmp = this._encInPending.shift();
|
tmp = this._encInPending.shift();
|
||||||
|
|
||||||
@ -285,11 +259,19 @@ SecurePair.prototype._cycle = function() {
|
|||||||
assert(rv === tmp.length);
|
assert(rv === tmp.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we've cleared all of incoming encrypted data, emit drain.
|
||||||
|
if (encPending && this._encInPending.length === 0) {
|
||||||
|
debug('encrypted drain');
|
||||||
|
this.encrypted.emit('drain');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Pull in any clear data coming from the application.
|
// Pull in any clear data coming from the application.
|
||||||
// This arrives via some code like this:
|
// This arrives via some code like this:
|
||||||
//
|
//
|
||||||
// pair.cleartext.write("hello world");
|
// pair.cleartext.write("hello world");
|
||||||
//
|
//
|
||||||
|
var clearPending = this._clearInPending.length > 0;
|
||||||
while (this._clearInPending.length > 0) {
|
while (this._clearInPending.length > 0) {
|
||||||
tmp = this._clearInPending.shift();
|
tmp = this._clearInPending.shift();
|
||||||
try {
|
try {
|
||||||
@ -307,6 +289,13 @@ SecurePair.prototype._cycle = function() {
|
|||||||
assert(rv === tmp.length);
|
assert(rv === tmp.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we've cleared all of incoming cleartext data, emit drain.
|
||||||
|
if (clearPending && this._clearInPending.length === 0) {
|
||||||
|
debug('cleartext drain');
|
||||||
|
this.cleartext.emit('drain');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Move decrypted, clear data out into the application.
|
// Move decrypted, clear data out into the application.
|
||||||
// From the user's perspective this occurs as a 'data' event
|
// From the user's perspective this occurs as a 'data' event
|
||||||
// on the pair.cleartext.
|
// on the pair.cleartext.
|
||||||
@ -361,7 +350,6 @@ SecurePair.prototype._destroy = function(err) {
|
|||||||
this._ssl = null;
|
this._ssl = null;
|
||||||
this.encrypted.emit('close');
|
this.encrypted.emit('close');
|
||||||
this.cleartext.emit('close');
|
this.cleartext.emit('close');
|
||||||
this.emit('end', err);
|
|
||||||
}
|
}
|
||||||
this._cycle();
|
this._cycle();
|
||||||
};
|
};
|
||||||
|
@ -112,7 +112,6 @@ function runClient (options, cb) {
|
|||||||
|
|
||||||
// To test use: openssl s_client -connect localhost:8000
|
// To test use: openssl s_client -connect localhost:8000
|
||||||
var client = spawn('openssl', args);
|
var client = spawn('openssl', args);
|
||||||
console.error(args);
|
|
||||||
|
|
||||||
var out = '';
|
var out = '';
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user