Browse Source

tls: support unix domain socket/named pipe in tls.connect

v0.8.9-release
Shigeki Ohtsu 13 years ago
committed by Ben Noordhuis
parent
commit
f347077e78
  1. 1
      lib/net.js
  2. 45
      lib/tls.js
  3. 49
      test/simple/test-tls-connect-pipe.js

1
lib/net.js

@ -106,6 +106,7 @@ function normalizeConnectArgs(args) {
var cb = args[args.length - 1]; var cb = args[args.length - 1];
return (typeof cb === 'function') ? [options, cb] : [options]; return (typeof cb === 'function') ? [options, cb] : [options];
} }
exports._normalizeConnectArgs = normalizeConnectArgs;
/* called when creating new Socket, or when re-using a closed Socket */ /* called when creating new Socket, or when re-using a closed Socket */

45
lib/tls.js

@ -1183,34 +1183,24 @@ Server.prototype.SNICallback = function(servername) {
// }); // });
// //
// //
exports.connect = function(/* [port, host], options, cb */) { function normalizeConnectArgs(listArgs) {
var options, port, host, cb; var args = net._normalizeConnectArgs(listArgs);
var options = args[0];
if (typeof arguments[0] === 'object') { var cb = args[1];
options = arguments[0];
} else if (typeof arguments[1] === 'object') { if (typeof listArgs[1] === 'object') {
options = arguments[1]; options = util._extend(options, listArgs[1]);
port = arguments[0]; } else if (typeof listArgs[2] === 'object') {
} else if (typeof arguments[2] === 'object') { options = util._extend(options, listArgs[2]);
options = arguments[2];
port = arguments[0];
host = arguments[1];
} else {
// This is what happens when user passes no `options` argument, we can't
// throw `TypeError` here because it would be incompatible with old API
if (typeof arguments[0] === 'number') {
port = arguments[0];
}
if (typeof arguments[1] === 'string') {
host = arguments[1];
}
} }
options = util._extend({ port: port, host: host }, options || {}); return (cb) ? [options, cb] : [options];
}
if (typeof arguments[arguments.length - 1] === 'function') { exports.connect = function(/* [port, host], options, cb */) {
cb = arguments[arguments.length - 1]; var args = normalizeConnectArgs(arguments);
} var options = args[0];
var cb = args[1];
var socket = options.socket ? options.socket : new net.Stream(); var socket = options.socket ? options.socket : new net.Stream();
@ -1235,11 +1225,12 @@ exports.connect = function(/* [port, host], options, cb */) {
} }
if (!options.socket) { if (!options.socket) {
socket.connect({ var connect_opt = (options.path && !options.port) ? {path: options.path} : {
port: options.port, port: options.port,
host: options.host, host: options.host,
localAddress: options.localAddress localAddress: options.localAddress
}); };
socket.connect(connect_opt);
} }
pair.on('secure', function() { pair.on('secure', function() {

49
test/simple/test-tls-connect-pipe.js

@ -0,0 +1,49 @@
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
var common = require('../common');
var assert = require('assert');
var tls = require('tls');
var fs = require('fs');
var clientConnected = 0;
var serverConnected = 0;
var options = {
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
};
var server = tls.Server(options, function(socket) {
++serverConnected;
server.close();
});
server.listen(common.PIPE, function() {
var client = tls.connect(common.PIPE, function() {
++clientConnected;
client.end();
});
});
process.on('exit', function() {
assert.equal(clientConnected, 1);
assert.equal(serverConnected, 1);
});
Loading…
Cancel
Save