Comparing version 0.0.1 to 0.0.2
@@ -91,3 +91,3 @@ 'use strict'; | ||
function onCloseOrRemove(err) { | ||
self.removeSocket(); | ||
self.removeSocket(socket); | ||
socket.removeListener('free', onFree); | ||
@@ -190,6 +190,11 @@ socket.removeListener('close', onCloseOrRemove); | ||
TunnelingAgent.prototype.createSocket.call(self, options, function(socket) { | ||
var hostHeader = options.request.getHeader('host'); | ||
var tlsOptions = mergeOptions({}, self.options, { | ||
socket: socket, | ||
servername: hostHeader ? hostHeader.replace(/:.*$/, '') : options.host | ||
}); | ||
// 0 is dummy port for v0.6 | ||
var secureSocket = tls.connect(0, mergeOptions({}, self.options, { | ||
socket: socket | ||
})); | ||
var secureSocket = tls.connect(0, tlsOptions); | ||
self.sockets[self.sockets.indexOf(socket)] = secureSocket; | ||
cb(secureSocket); | ||
@@ -196,0 +201,0 @@ }); |
{ | ||
"name": "tunnel", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Node HTTP/HTTPS Agents for tunneling proxies", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
228
README.md
@@ -5,16 +5,18 @@ # node-tunnel - HTTP/HTTPS Agents for tunneling proxies | ||
var tunnel = require('tunnel'); | ||
```javascript | ||
var tunnel = require('tunnel'); | ||
var myAgent = tunnel.httpsOverHttp({ | ||
proxy: { | ||
host: 'localhost', | ||
port: 3128 | ||
} | ||
}); | ||
var tunnelingAgent = tunnel.httpsOverHttp({ | ||
proxy: { | ||
host: 'localhost', | ||
port: 3128 | ||
} | ||
}); | ||
var req = https.request({ | ||
host: 'example.com', | ||
port: 443, | ||
agent: myAgent | ||
}); | ||
var req = https.request({ | ||
host: 'example.com', | ||
port: 443, | ||
agent: tunnelingAgent | ||
}); | ||
``` | ||
@@ -29,126 +31,144 @@ ## Installation | ||
var myAgent = tunnel.httpOverHttp({ | ||
maxSockets: poolSize, // Defaults to 5 | ||
```javascript | ||
var tunnelingAgent = tunnel.httpOverHttp({ | ||
maxSockets: poolSize, // Defaults to 5 | ||
proxy: { // Proxy settings | ||
host: proxyHost, // Defaults to 'localhost' | ||
port: proxyPort, // Defaults to 80 | ||
proxy: { // Proxy settings | ||
host: proxyHost, // Defaults to 'localhost' | ||
port: proxyPort, // Defaults to 80 | ||
localAddress: localAddress, // Local interface if necessary | ||
// Basic authorization for proxy server if necessary | ||
proxyAuth: 'user:password', | ||
// Basic authorization for proxy server if necessary | ||
proxyAuth: 'user:password', | ||
// Header fields for proxy server if necessary | ||
headers: { | ||
'User-Agent': 'Node' | ||
} | ||
} | ||
}); | ||
// Header fields for proxy server if necessary | ||
headers: { | ||
'User-Agent': 'Node' | ||
} | ||
} | ||
}); | ||
var req = http.request({ | ||
host: 'example.com', | ||
port: 80, | ||
agent: myAgent | ||
}); | ||
var req = http.request({ | ||
host: 'example.com', | ||
port: 80, | ||
agent: tunnelingAgent | ||
}); | ||
``` | ||
### HTTPS over HTTP tunneling | ||
var myAgent = tunnel.httpsOverHttp({ | ||
maxSockets: poolSize, // Defaults to 5 | ||
```javascript | ||
var tunnelingAgent = tunnel.httpsOverHttp({ | ||
maxSockets: poolSize, // Defaults to 5 | ||
// CA for origin server if necessary | ||
ca: [ fs.readFileSync('origin-server-ca.pem')], | ||
// CA for origin server if necessary | ||
ca: [ fs.readFileSync('origin-server-ca.pem')], | ||
// Client certification for origin server if necessary | ||
key: fs.readFileSync('origin-server-key.pem'), | ||
cert: fs.readFileSync('origin-server-cert.pem'), | ||
// Client certification for origin server if necessary | ||
key: fs.readFileSync('origin-server-key.pem'), | ||
cert: fs.readFileSync('origin-server-cert.pem'), | ||
proxy: { // Proxy settings | ||
host: proxyHost, // Defaults to 'localhost' | ||
port: proxyPort, // Defaults to 80 | ||
proxy: { // Proxy settings | ||
host: proxyHost, // Defaults to 'localhost' | ||
port: proxyPort, // Defaults to 80 | ||
localAddress: localAddress, // Local interface if necessary | ||
// Basic authorization for proxy server if necessary | ||
proxyAuth: 'user:password', | ||
// Basic authorization for proxy server if necessary | ||
proxyAuth: 'user:password', | ||
// Header fields for proxy server if necessary | ||
headers: { | ||
'User-Agent': 'Node' | ||
}, | ||
} | ||
}); | ||
// Header fields for proxy server if necessary | ||
headers: { | ||
'User-Agent': 'Node' | ||
}, | ||
} | ||
}); | ||
var req = https.request({ | ||
host: 'example.com', | ||
port: 443, | ||
agent: myAgent | ||
}); | ||
var req = https.request({ | ||
host: 'example.com', | ||
port: 443, | ||
agent: tunnelingAgent | ||
}); | ||
``` | ||
### HTTP over HTTPS tunneling | ||
var myAgent = tunnel.httpOverHttps({ | ||
maxSockets: poolSize, // Defaults to 5 | ||
```javascript | ||
var tunnelingAgent = tunnel.httpOverHttps({ | ||
maxSockets: poolSize, // Defaults to 5 | ||
proxy: { // Proxy settings | ||
host: proxyHost, // Defaults to 'localhost' | ||
port: proxyPort, // Defaults to 443 | ||
proxy: { // Proxy settings | ||
host: proxyHost, // Defaults to 'localhost' | ||
port: proxyPort, // Defaults to 443 | ||
localAddress: localAddress, // Local interface if necessary | ||
// Basic authorization for proxy server if necessary | ||
proxyAuth: 'user:password', | ||
// Basic authorization for proxy server if necessary | ||
proxyAuth: 'user:password', | ||
// Header fields for proxy server if necessary | ||
headers: { | ||
'User-Agent': 'Node' | ||
}, | ||
// Header fields for proxy server if necessary | ||
headers: { | ||
'User-Agent': 'Node' | ||
}, | ||
// CA for proxy server if necessary | ||
ca: [ fs.readFileSync('origin-server-ca.pem')], | ||
// CA for proxy server if necessary | ||
ca: [ fs.readFileSync('origin-server-ca.pem')], | ||
// Client certification for proxy server if necessary | ||
key: fs.readFileSync('origin-server-key.pem'), | ||
cert: fs.readFileSync('origin-server-cert.pem'), | ||
} | ||
}); | ||
// Server name for verification if necessary | ||
servername: 'example.com', | ||
var req = http.request({ | ||
host: 'example.com', | ||
port: 80, | ||
agent: myAgent | ||
}); | ||
// Client certification for proxy server if necessary | ||
key: fs.readFileSync('origin-server-key.pem'), | ||
cert: fs.readFileSync('origin-server-cert.pem'), | ||
} | ||
}); | ||
var req = http.request({ | ||
host: 'example.com', | ||
port: 80, | ||
agent: tunnelingAgent | ||
}); | ||
``` | ||
### HTTPS over HTTPS tunneling | ||
var myAgent = tunnel.httpsOverHttps({ | ||
maxSockets: poolSize, // Defaults to 5 | ||
```javascript | ||
var tunnelingAgent = tunnel.httpsOverHttps({ | ||
maxSockets: poolSize, // Defaults to 5 | ||
// CA for origin server if necessary | ||
ca: [ fs.readFileSync('origin-server-ca.pem')], | ||
// CA for origin server if necessary | ||
ca: [ fs.readFileSync('origin-server-ca.pem')], | ||
// Client certification for origin server if necessary | ||
key: fs.readFileSync('origin-server-key.pem'), | ||
cert: fs.readFileSync('origin-server-cert.pem'), | ||
// Client certification for origin server if necessary | ||
key: fs.readFileSync('origin-server-key.pem'), | ||
cert: fs.readFileSync('origin-server-cert.pem'), | ||
proxy: { // Proxy settings | ||
host: proxyHost, // Defaults to 'localhost' | ||
port: proxyPort, // Defaults to 443 | ||
proxy: { // Proxy settings | ||
host: proxyHost, // Defaults to 'localhost' | ||
port: proxyPort, // Defaults to 443 | ||
localAddress: localAddress, // Local interface if necessary | ||
// Basic authorization for proxy server if necessary | ||
proxyAuth: 'user:password', | ||
// Basic authorization for proxy server if necessary | ||
proxyAuth: 'user:password', | ||
// Header fields for proxy server if necessary | ||
headers: { | ||
'User-Agent': 'Node' | ||
} | ||
// Header fields for proxy server if necessary | ||
headers: { | ||
'User-Agent': 'Node' | ||
} | ||
// CA for proxy server if necessary | ||
ca: [ fs.readFileSync('origin-server-ca.pem')], | ||
// CA for proxy server if necessary | ||
ca: [ fs.readFileSync('origin-server-ca.pem')], | ||
// Client certification for proxy server if necessary | ||
key: fs.readFileSync('origin-server-key.pem'), | ||
cert: fs.readFileSync('origin-server-cert.pem'), | ||
} | ||
}); | ||
// Server name for verification if necessary | ||
servername: 'example.com', | ||
var req = https.request({ | ||
host: 'example.com', | ||
port: 443, | ||
agent: myAgent | ||
}); | ||
// Client certification for proxy server if necessary | ||
key: fs.readFileSync('origin-server-key.pem'), | ||
cert: fs.readFileSync('origin-server-cert.pem'), | ||
} | ||
}); | ||
var req = https.request({ | ||
host: 'example.com', | ||
port: 443, | ||
agent: tunnelingAgent | ||
}); | ||
``` |
@@ -102,4 +102,4 @@ var http = require('http'); | ||
agent.sockets.should.have.lengthOf(0); | ||
agent.requests.should.have.lengthOf(0); | ||
agent.sockets.should.be.empty; | ||
agent.requests.should.be.empty; | ||
@@ -106,0 +106,0 @@ done(); |
@@ -116,4 +116,4 @@ var http = require('http'); | ||
var name = 'localhost:' + serverPort; | ||
agent.sockets.should.not.have.ownProperty(name); | ||
agent.requests.should.not.have.ownProperty(name); | ||
agent.sockets.should.be.empty; | ||
agent.requests.should.be.empty; | ||
@@ -120,0 +120,0 @@ done(); |
@@ -115,4 +115,4 @@ var http = require('http'); | ||
var name = 'localhost:' + serverPort; | ||
agent.sockets.should.not.have.ownProperty(name); | ||
agent.requests.should.not.have.ownProperty(name); | ||
agent.sockets.should.be.empty; | ||
agent.requests.should.be.empty; | ||
@@ -119,0 +119,0 @@ done(); |
@@ -19,2 +19,3 @@ var http = require('http'); | ||
var proxyConnect = 0; | ||
var clientRequest = 0; | ||
var clientConnect = 0; | ||
@@ -26,5 +27,5 @@ var clientError = 0; | ||
server = https.createServer({ | ||
key: readPem('agent2-key'), | ||
cert: readPem('agent2-cert'), | ||
ca: [ readPem('ca1-cert') ], // ca for agent1 | ||
key: readPem('agent1-key'), // agent1 is signed by ca1 | ||
cert: readPem('agent1-cert'), | ||
ca: [ readPem('ca2-cert') ], // ca for agent3 | ||
requestCert: true, | ||
@@ -43,5 +44,5 @@ rejectUnauthorized: true | ||
proxy = https.createServer({ | ||
key: readPem('agent4-key'), | ||
cert: readPem('agent4-cert'), | ||
ca: [ readPem('ca2-cert') ], // ca for agent3 | ||
key: readPem('agent3-key'), // agent3 is signed by ca2 | ||
cert: readPem('agent3-cert'), | ||
ca: [ readPem('ca1-cert') ], // ca for agent1 | ||
requestCert: true, | ||
@@ -77,7 +78,11 @@ rejectUnauthorized: true | ||
function setupClient() { | ||
function doRequest(name, options) { | ||
function doRequest(name, options, host) { | ||
tunnel.debug('CLIENT: Making HTTPS request (%s)', name); | ||
++clientRequest; | ||
var agent = tunnel.httpsOverHttps(options); | ||
var req = https.get({ | ||
port: serverPort, | ||
headers: { | ||
host: host ? host : 'localhost', | ||
}, | ||
agent: agent | ||
@@ -90,3 +95,3 @@ }, function(res) { | ||
req.on('error', function(err) { | ||
tunnel.debug('CLIENT: failed HTTP response (%s)', name); | ||
tunnel.debug('CLIENT: failed HTTP response (%s)', name, err); | ||
++clientError; | ||
@@ -96,3 +101,3 @@ req.emit('finish'); | ||
req.on('finish', function() { | ||
if (clientConnect + clientError === 4) { | ||
if (clientConnect + clientError === clientRequest) { | ||
proxy.close(); | ||
@@ -106,40 +111,98 @@ server.close(); | ||
maxSockets: 1, | ||
ca: [ readPem('ca1-cert') ], // ca for origin server (agent1) | ||
rejectUnauthorized: true, | ||
// no certificate for origin server | ||
proxy: { | ||
port: proxyPort | ||
port: proxyPort, | ||
servername: 'agent3', | ||
ca: [ readPem('ca2-cert') ], // ca for proxy server (agent3) | ||
rejectUnauthorized: true | ||
// no certificate for proxy | ||
} | ||
}); | ||
}, 'agent1'); | ||
doRequest('no cert proxy', { // invalid | ||
maxSockets: 1, | ||
ca: [ readPem('ca1-cert') ], // ca for origin server (agent1) | ||
rejectUnauthorized: true, | ||
// client certification for origin server | ||
key: readPem('agent1-key'), | ||
cert: readPem('agent1-cert'), | ||
key: readPem('agent3-key'), | ||
cert: readPem('agent3-cert'), | ||
proxy: { | ||
port: proxyPort | ||
port: proxyPort, | ||
servername: 'agent3', | ||
ca: [ readPem('ca2-cert') ], // ca for proxy server (agent3) | ||
rejectUnauthorized: true | ||
// no certificate for proxy | ||
} | ||
}); | ||
}, 'agent1'); | ||
doRequest('no cert origin', { // invalid | ||
maxSockets: 1, | ||
ca: [ readPem('ca1-cert') ], // ca for origin server (agent1) | ||
rejectUnauthorized: true, | ||
// no certificate for origin server | ||
proxy: { | ||
port: proxyPort, | ||
servername: 'agent3', | ||
ca: [ readPem('ca2-cert') ], // ca for proxy server (agent3) | ||
rejectUnauthorized: true, | ||
// client certification for proxy | ||
key: readPem('agent3-key'), | ||
cert: readPem('agent3-cert') | ||
key: readPem('agent1-key'), | ||
cert: readPem('agent1-cert') | ||
} | ||
}, 'agent1'); | ||
doRequest('invalid proxy server name', { // invalid | ||
maxSockets: 1, | ||
ca: [ readPem('ca1-cert') ], // ca for origin server (agent1) | ||
rejectUnauthorized: true, | ||
// client certification for origin server | ||
key: readPem('agent3-key'), | ||
cert: readPem('agent3-cert'), | ||
proxy: { | ||
port: proxyPort, | ||
ca: [ readPem('ca2-cert') ], // ca for agent3 | ||
rejectUnauthorized: true, | ||
// client certification for proxy | ||
key: readPem('agent1-key'), | ||
cert: readPem('agent1-cert') | ||
} | ||
}, 'agent1'); | ||
doRequest('invalid origin server name', { // invalid | ||
maxSockets: 1, | ||
ca: [ readPem('ca1-cert') ], // ca for agent1 | ||
rejectUnauthorized: true, | ||
// client certification for origin server | ||
key: readPem('agent3-key'), | ||
cert: readPem('agent3-cert'), | ||
proxy: { | ||
port: proxyPort, | ||
servername: 'agent3', | ||
ca: [ readPem('ca2-cert') ], // ca for proxy server (agent3) | ||
rejectUnauthorized: true, | ||
// client certification for proxy | ||
key: readPem('agent1-key'), | ||
cert: readPem('agent1-cert') | ||
} | ||
}); | ||
doRequest('valid', { // valid | ||
maxSockets: 1, | ||
ca: [ readPem('ca1-cert') ], // ca for origin server (agent1) | ||
rejectUnauthorized: true, | ||
// client certification for origin server | ||
key: readPem('agent1-key'), | ||
cert: readPem('agent1-cert'), | ||
key: readPem('agent3-key'), | ||
cert: readPem('agent3-cert'), | ||
proxy: { | ||
port: proxyPort, | ||
servername: 'agent3', | ||
ca: [ readPem('ca2-cert') ], // ca for proxy server (agent3) | ||
rejectUnauthorized: true, | ||
// client certification for proxy | ||
key: readPem('agent3-key'), | ||
cert: readPem('agent3-cert') | ||
key: readPem('agent1-key'), | ||
cert: readPem('agent1-cert') | ||
} | ||
}); | ||
}, 'agent1'); | ||
} | ||
@@ -149,5 +212,5 @@ | ||
serverConnect.should.equal(1); | ||
proxyConnect.should.equal(2); | ||
proxyConnect.should.equal(3); | ||
clientConnect.should.equal(1); | ||
clientError.should.equal(3); | ||
clientError.should.equal(5); | ||
@@ -154,0 +217,0 @@ done(); |
@@ -123,4 +123,4 @@ var http = require('http'); | ||
var name = 'localhost:' + serverPort; | ||
agent.sockets.should.not.have.ownProperty(name); | ||
agent.requests.should.not.have.ownProperty(name); | ||
agent.sockets.should.be.empty; | ||
agent.requests.should.be.empty; | ||
@@ -127,0 +127,0 @@ done(); |
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
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
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
51000
39
829
173
1