Style changes.
This commit is contained in:
parent
bc47353bbe
commit
79ecc8e9b7
@ -18,10 +18,9 @@ var SecureStream = null;
|
|||||||
* Provides a pair of streams to do encrypted communication.
|
* Provides a pair of streams to do encrypted communication.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function SecurePair(credentials, is_server)
|
function SecurePair(credentials, isServer) {
|
||||||
{
|
|
||||||
if (!(this instanceof SecurePair)) {
|
if (!(this instanceof SecurePair)) {
|
||||||
return new SecurePair(credentials, is_server);
|
return new SecurePair(credentials, isServer);
|
||||||
}
|
}
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
@ -36,9 +35,9 @@ function SecurePair(credentials, is_server)
|
|||||||
events.EventEmitter.call(this);
|
events.EventEmitter.call(this);
|
||||||
|
|
||||||
this._secureEstablished = false;
|
this._secureEstablished = false;
|
||||||
this._is_server = is_server ? true : false;
|
this._isServer = isServer ? true : false;
|
||||||
this._enc_write_state = true;
|
this._encWriteState = true;
|
||||||
this._clear_write_state = true;
|
this._clearWriteState = true;
|
||||||
this._done = false;
|
this._done = false;
|
||||||
|
|
||||||
var crypto = require("crypto");
|
var crypto = require("crypto");
|
||||||
@ -49,17 +48,17 @@ function SecurePair(credentials, is_server)
|
|||||||
this.credentials = credentials;
|
this.credentials = credentials;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this._is_server) {
|
if (!this._isServer) {
|
||||||
/* For clients, we will always have either a given ca list or be using default one */
|
/* For clients, we will always have either a given ca list or be using default one */
|
||||||
this.credentials.shouldVerify = true;
|
this.credentials.shouldVerify = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._secureEstablished = false;
|
this._secureEstablished = false;
|
||||||
this._encIn_pending = [];
|
this._encInPending = [];
|
||||||
this._clearIn_pending = [];
|
this._clearInPending = [];
|
||||||
|
|
||||||
this._ssl = new SecureStream(this.credentials.context,
|
this._ssl = new SecureStream(this.credentials.context,
|
||||||
this._is_server ? true : false,
|
this._isServer ? true : false,
|
||||||
this.credentials.shouldVerify);
|
this.credentials.shouldVerify);
|
||||||
|
|
||||||
|
|
||||||
@ -72,19 +71,19 @@ function SecurePair(credentials, is_server)
|
|||||||
|
|
||||||
this.cleartext.write = function(data) {
|
this.cleartext.write = function(data) {
|
||||||
debug('clearIn data');
|
debug('clearIn data');
|
||||||
self._clearIn_pending.push(data);
|
self._clearInPending.push(data);
|
||||||
self._cycle();
|
self._cycle();
|
||||||
return self._cleartext_write_state;
|
return self._cleartextWriteState;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.cleartext.pause = function() {
|
this.cleartext.pause = function() {
|
||||||
debug('paused cleartext');
|
debug('paused cleartext');
|
||||||
self._cleartext_write_state = false;
|
self._cleartextWriteState = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.cleartext.resume = function() {
|
this.cleartext.resume = function() {
|
||||||
debug('resumed cleartext');
|
debug('resumed cleartext');
|
||||||
self._cleartext_write_state = true;
|
self._cleartextWriteState = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.cleartext.end = function(err) {
|
this.cleartext.end = function(err) {
|
||||||
@ -98,19 +97,19 @@ function SecurePair(credentials, is_server)
|
|||||||
|
|
||||||
this.encrypted.write = function(data) {
|
this.encrypted.write = function(data) {
|
||||||
debug('encIn data');
|
debug('encIn data');
|
||||||
self._encIn_pending.push(data);
|
self._encInPending.push(data);
|
||||||
self._cycle();
|
self._cycle();
|
||||||
return self._encrypted_write_state;
|
return self._encryptedWriteState;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.encrypted.pause = function() {
|
this.encrypted.pause = function() {
|
||||||
debug('pause encrypted');
|
debug('pause encrypted');
|
||||||
self._encrypted_write_state = false;
|
self._encryptedWriteState = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.encrypted.resume = function() {
|
this.encrypted.resume = function() {
|
||||||
debug('resume encrypted');
|
debug('resume encrypted');
|
||||||
self._encrypted_write_state = true;
|
self._encryptedWriteState = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.encrypted.end = function(err) {
|
this.encrypted.end = function(err) {
|
||||||
@ -169,9 +168,8 @@ function SecurePair(credentials, is_server)
|
|||||||
|
|
||||||
util.inherits(SecurePair, events.EventEmitter);
|
util.inherits(SecurePair, events.EventEmitter);
|
||||||
|
|
||||||
exports.createSecurePair = function(credentials, is_server)
|
exports.createSecurePair = function(credentials, isServer) {
|
||||||
{
|
var pair = new SecurePair(credentials, isServer);
|
||||||
var pair = new SecurePair(credentials, is_server);
|
|
||||||
return pair;
|
return pair;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -215,8 +213,8 @@ SecurePair.prototype._cycle = function() {
|
|||||||
var chunk = null;
|
var chunk = null;
|
||||||
var pool = null;
|
var pool = null;
|
||||||
|
|
||||||
while (this._encIn_pending.length > 0) {
|
while (this._encInPending.length > 0) {
|
||||||
tmp = this._encIn_pending.shift();
|
tmp = this._encInPending.shift();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
debug('writng from encIn');
|
debug('writng from encIn');
|
||||||
@ -226,15 +224,15 @@ SecurePair.prototype._cycle = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (rv === 0) {
|
if (rv === 0) {
|
||||||
this._encIn_pending.unshift(tmp);
|
this._encInPending.unshift(tmp);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(rv === tmp.length);
|
assert(rv === tmp.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (this._clearIn_pending.length > 0) {
|
while (this._clearInPending.length > 0) {
|
||||||
tmp = this._clearIn_pending.shift();
|
tmp = this._clearInPending.shift();
|
||||||
try {
|
try {
|
||||||
debug('writng from clearIn');
|
debug('writng from clearIn');
|
||||||
rv = this._ssl.clearIn(tmp, 0, tmp.length);
|
rv = this._ssl.clearIn(tmp, 0, tmp.length);
|
||||||
@ -243,7 +241,7 @@ SecurePair.prototype._cycle = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (rv === 0) {
|
if (rv === 0) {
|
||||||
this._clearIn_pending.unshift(tmp);
|
this._clearInPending.unshift(tmp);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,7 +287,7 @@ SecurePair.prototype._cycle = function() {
|
|||||||
self.cleartext.emit('data', chunk);
|
self.cleartext.emit('data', chunk);
|
||||||
},
|
},
|
||||||
function(bytesRead) {
|
function(bytesRead) {
|
||||||
return bytesRead > 0 && self._cleartext_write_state === true;
|
return bytesRead > 0 && self._cleartextWriteState === true;
|
||||||
});
|
});
|
||||||
|
|
||||||
mover(
|
mover(
|
||||||
@ -301,7 +299,7 @@ SecurePair.prototype._cycle = function() {
|
|||||||
self.encrypted.emit('data', chunk);
|
self.encrypted.emit('data', chunk);
|
||||||
},
|
},
|
||||||
function(bytesRead) {
|
function(bytesRead) {
|
||||||
return bytesRead > 0 && self._encrypted_write_state === true;
|
return bytesRead > 0 && self._encryptedWriteState === true;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!this._secureEstablished && this._ssl.isInitFinished()) {
|
if (!this._secureEstablished && this._ssl.isInitFinished()) {
|
||||||
|
@ -244,8 +244,7 @@ Handle<Value> SecureContext::Close(const Arguments& args) {
|
|||||||
|
|
||||||
char ssl_error_buf[512];
|
char ssl_error_buf[512];
|
||||||
|
|
||||||
static int serr(SSL *ssl, const char* func, int rv)
|
static int serr(SSL *ssl, const char* func, int rv) {
|
||||||
{
|
|
||||||
if (rv >= 0) {
|
if (rv >= 0) {
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
@ -256,11 +255,9 @@ static int serr(SSL *ssl, const char* func, int rv)
|
|||||||
ERR_error_string_n(ERR_get_error(), &ssl_error_buf[0], sizeof(ssl_error_buf));
|
ERR_error_string_n(ERR_get_error(), &ssl_error_buf[0], sizeof(ssl_error_buf));
|
||||||
/* fprintf(stderr, "[%p] SSL: %s failed: (%d:%d) %s\n", ssl, func, err, rv, buf); */
|
/* fprintf(stderr, "[%p] SSL: %s failed: (%d:%d) %s\n", ssl, func, err, rv, buf); */
|
||||||
return rv;
|
return rv;
|
||||||
}
|
} else if (err == SSL_ERROR_WANT_WRITE) {
|
||||||
else if (err == SSL_ERROR_WANT_WRITE) {
|
|
||||||
/* fprintf(stderr, "[%p] SSL: %s want write\n", ssl, func); */
|
/* fprintf(stderr, "[%p] SSL: %s want write\n", ssl, func); */
|
||||||
}
|
} else if (err == SSL_ERROR_WANT_READ) {
|
||||||
else if (err == SSL_ERROR_WANT_READ) {
|
|
||||||
/* fprintf(stderr, "[%p] SSL: %s want read\n", ssl, func); */
|
/* fprintf(stderr, "[%p] SSL: %s want read\n", ssl, func); */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -516,9 +513,11 @@ Handle<Value> SecureStream::ClearIn(const Arguments& args) {
|
|||||||
} else {
|
} else {
|
||||||
s = serr(ss->ssl_, "SSL_connect:ClearIn", SSL_connect(ss->ssl_));
|
s = serr(ss->ssl_, "SSL_connect:ClearIn", SSL_connect(ss->ssl_));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s < 0) {
|
if (s < 0) {
|
||||||
return ThrowException(Exception::Error(v8::String::New(ssl_error_buf)));
|
return ThrowException(Exception::Error(v8::String::New(ssl_error_buf)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return scope.Close(Integer::New(0));
|
return scope.Close(Integer::New(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -602,13 +601,14 @@ Handle<Value> SecureStream::Start(const Arguments& args) {
|
|||||||
} else {
|
} else {
|
||||||
rv = serr(ss->ssl_, "SSL_connect:Start", SSL_connect(ss->ssl_));
|
rv = serr(ss->ssl_, "SSL_connect:Start", SSL_connect(ss->ssl_));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rv < 0) {
|
if (rv < 0) {
|
||||||
return ThrowException(Exception::Error(v8::String::New(ssl_error_buf)));
|
return ThrowException(Exception::Error(v8::String::New(ssl_error_buf)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rv == 1) {
|
if (rv == 1) {
|
||||||
return True();
|
return True();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return False();
|
return False();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user