Comparing version 0.1.0 to 0.1.1
40
index.js
@@ -22,3 +22,3 @@ /** | ||
exports.startTls = function(socket, onSecure) { | ||
var credentials, securePair, clearTextStream; | ||
var credentials, securePair, clearText; | ||
@@ -30,3 +30,3 @@ socket.ondata = null; | ||
clearTextStream = pipe(securePair, socket); | ||
clearText = pipe(securePair, socket); | ||
@@ -37,6 +37,6 @@ securePair.on('secure', function() { | ||
if (verifyError) { | ||
clearTextStream.authorized = false; | ||
clearTextStream.authorizationError = verifyError; | ||
clearText.authorized = false; | ||
clearText.authorizationError = verifyError; | ||
} else { | ||
clearTextStream.authorized = true; | ||
clearText.authorized = true; | ||
} | ||
@@ -47,3 +47,3 @@ | ||
clearTextStream._controlReleased = true; | ||
clearText._controlReleased = true; | ||
@@ -78,3 +78,3 @@ return securePair; | ||
function pipe(securePair, socket) { | ||
var clearTextStream, onError, onClose, eventsMap; | ||
var clearText, onError, onClose, eventsMap; | ||
@@ -86,16 +86,17 @@ securePair.encrypted.pipe(socket); | ||
clearTextStream = securePair.cleartext; | ||
clearText = securePair.cleartext; | ||
clearTextStream.socket = socket; | ||
clearTextStream.encrypted = securePair.encrypted; | ||
clearTextStream.authorized = false; | ||
clearText.socket = socket; | ||
clearText.encrypted = securePair.encrypted; | ||
clearText.authorized = false; | ||
onError = function(e) { | ||
if (clearTextStream._controlReleased) { | ||
clearTextStream.emit('error', e); | ||
// Forward event emissions from the socket to the clear text stream | ||
eventsMap = forwardEvents(['timeout', 'end', 'drain'], socket, clearText); | ||
onError = function(err) { | ||
if (clearText._controlReleased) { | ||
clearText.emit('error', err); | ||
} | ||
}; | ||
eventsMap = forwardEvents(['timeout', 'end', 'close', 'drain', 'error'], socket, clearTextStream); | ||
onClose = function() { | ||
@@ -110,3 +111,8 @@ socket.removeListener('error', onError); | ||
return clearTextStream; | ||
// It's possible for a SecurePair to emit an 'error' event (see SecurePair.prototype.error in tls.js in at least node v0.8.21). | ||
securePair.on('error', function(err) { | ||
clearText.emit('error', err); | ||
}); | ||
return clearText; | ||
} |
{ | ||
"name": "starttls", | ||
"description": "Upgrade a regular `net.Stream` connection to a secure `tls` connection.", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "homepage": "https://github.com/mattcg/starttls", |
@@ -7,2 +7,19 @@ # Start TLS # | ||
## Usage ## | ||
The only method, `startTls`, returns a [`SecurePair`](http://nodejs.org/api/tls.html#tls_class_securepair) and takes a [`Socket`](http://nodejs.org/api/net.html#net_class_net_socket) and an optional callback called on the [`secure`](http://nodejs.org/api/tls.html#tls_event_secure) event of the pair. | ||
```javascript | ||
var net = require('net'); | ||
var startTls = require('starttls').startTls; | ||
var port = 21; | ||
var socket = net.createConnection(port); | ||
socket.on('connect', function() { | ||
var securePair = startTls(socket, function() { | ||
securePair.cleartext.write('garbage'); | ||
}); | ||
}); | ||
``` | ||
## License ## | ||
@@ -9,0 +26,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4754
83
29