Skip to content

Commit

Permalink
Additional fixes for new TLS.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregory Brail committed Sep 11, 2014
1 parent 5e12561 commit 09a2999
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,9 @@ private boolean doWrap(Context cx)
}
} while (result.getStatus() == SSLEngineResult.Status.BUFFER_OVERFLOW);

if ((qc != null) && !bb.hasRemaining()) {
// Finished processing the current chunk
if ((qc != null) && !bb.hasRemaining() && initFinished) {
// Finished processing the current chunk, but don't deliver until
// handshake is done in case client ended before sending any data
outgoingChunks.remove();
if (qc.callback != null) {
qc.callback.call(cx, this, this, ScriptRuntime.emptyArgs);
Expand Down Expand Up @@ -549,7 +550,7 @@ private void handleEncodingError(Context cx, QueuedChunk qc, SSLException ssle)
}
Scriptable err = Utils.makeErrorObject(cx, this, cause.toString());
error = err;
if (handshaking) {
if (!initFinished) {
// Always make this in to an "error" event
verifyError = err;
if (onError != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ CleartextStream.prototype._write = function(chunk, encoding, cb) {

// Data from SSLEngine.wrap will end up here
CleartextStream.prototype._onwrap = function(chunk, shutdown) {
if (!this.pair.ssl) {
if (this._destroyed || !this.pair.ssl) {
// Arrived late after close -- ignore
return;
}
Expand Down Expand Up @@ -908,7 +908,7 @@ EncryptedStream.prototype._write = function(chunk, encoding, cb) {
};

EncryptedStream.prototype._onunwrap = function(chunk, shutdown) {
if (!this.pair.ssl) {
if (this._destroyed || !this.pair.ssl) {
// Arrived late after close -- ignore
return;
}
Expand All @@ -935,12 +935,16 @@ EncryptedStream.prototype._read = function() {
EncryptedStream.prototype._onEnd = function() {
debug('EncryptedStream end received');
this._ended = true;
if (!this._closed) {
this._done();
}
if (this.onend) {
debug('onend');
this.onend();
if (!this.pair._secureEstablished) {
this.pair.emit('error', new Error('Socket hung up'));
} else {
if (!this._closed) {
this._done();
}
if (this.onend) {
debug('onend');
this.onend();
}
}
};

Expand Down

0 comments on commit 09a2999

Please sign in to comment.