|
|
@ -3,14 +3,15 @@ var events = require('events'); |
|
|
|
var stream = require('stream'); |
|
|
|
var assert = process.assert; |
|
|
|
|
|
|
|
var debugLevel = parseInt(process.env.NODE_DEBUG, 16); |
|
|
|
|
|
|
|
var debugLevel = parseInt(process.env.NODE_DEBUG, 16); |
|
|
|
function debug () { |
|
|
|
if (debugLevel & 0x2) { |
|
|
|
util.error.apply(this, arguments); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* Lazy Loaded crypto object */ |
|
|
|
var SecureStream = null; |
|
|
|
|
|
|
@ -168,6 +169,7 @@ function SecurePair(credentials, isServer) { |
|
|
|
|
|
|
|
util.inherits(SecurePair, events.EventEmitter); |
|
|
|
|
|
|
|
|
|
|
|
exports.createSecurePair = function (credentials, isServer) { |
|
|
|
var pair = new SecurePair(credentials, isServer); |
|
|
|
return pair; |
|
|
@ -183,15 +185,15 @@ exports.createSecurePair = function(credentials, isServer) { |
|
|
|
* the ciphers. |
|
|
|
* |
|
|
|
* The four pipelines, using terminology of the client (server is just reversed): |
|
|
|
* 1) Encrypted Output stream (Writing encrypted data to peer) |
|
|
|
* 2) Encrypted Input stream (Reading encrypted data from peer) |
|
|
|
* 3) Cleartext Output stream (Decrypted content from the peer) |
|
|
|
* 4) Cleartext Input stream (Cleartext content to send to the peer) |
|
|
|
* (1) Encrypted Output stream (Writing encrypted data to peer) |
|
|
|
* (2) Encrypted Input stream (Reading encrypted data from peer) |
|
|
|
* (3) Cleartext Output stream (Decrypted content from the peer) |
|
|
|
* (4) Cleartext Input stream (Cleartext content to send to the peer) |
|
|
|
* |
|
|
|
* This function attempts to pull any available data out of the Cleartext |
|
|
|
* input stream (#4), and the Encrypted input stream (#2). Then it pushes |
|
|
|
* any data available from the cleartext output stream (#3), and finally |
|
|
|
* from the Encrypted output stream (#1) |
|
|
|
* input stream (4), and the Encrypted input stream (2). Then it pushes |
|
|
|
* any data available from the cleartext output stream (3), and finally |
|
|
|
* from the Encrypted output stream (1) |
|
|
|
* |
|
|
|
* It is called whenever we do something with OpenSSL -- post reciving content, |
|
|
|
* trying to flush, trying to change ciphers, or shutting down the connection. |
|
|
@ -310,8 +312,8 @@ SecurePair.prototype._cycle = function() { |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
SecurePair.prototype._destroy = function(err) |
|
|
|
{ |
|
|
|
|
|
|
|
SecurePair.prototype._destroy = function (err) { |
|
|
|
if (!this._done) { |
|
|
|
this._done = true; |
|
|
|
this._ssl.close(); |
|
|
@ -320,17 +322,17 @@ SecurePair.prototype._destroy = function(err) |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
SecurePair.prototype._error = function (err) |
|
|
|
{ |
|
|
|
|
|
|
|
SecurePair.prototype._error = function (err) { |
|
|
|
this.emit('error', err); |
|
|
|
}; |
|
|
|
|
|
|
|
SecurePair.prototype.getPeerCertificate = function (err) |
|
|
|
{ |
|
|
|
|
|
|
|
SecurePair.prototype.getPeerCertificate = function (err) { |
|
|
|
return this._ssl.getPeerCertificate(); |
|
|
|
}; |
|
|
|
|
|
|
|
SecurePair.prototype.getCipher = function (err) |
|
|
|
{ |
|
|
|
|
|
|
|
SecurePair.prototype.getCipher = function (err) { |
|
|
|
return this._ssl.getCurrentCipher(); |
|
|
|
}; |
|
|
|