using SNI when intercepting https requests

This commit is contained in:
OttoMao
2015-02-10 12:03:21 +08:00
parent 6d84a95165
commit d51cb0ce4b
6 changed files with 105 additions and 187 deletions

View File

@@ -9,11 +9,11 @@ var http = require("http"),
color = require("colorful"),
Buffer = require('buffer').Buffer,
util = require("./util"),
getPort = require("./getPort"),
Stream = require("stream"),
httpsServerMgr = require("./httpsServerMgr");
var httpsServerMgrInstance = new httpsServerMgr(),
defaultRule = require("./rule_default.js"),
var defaultRule = require("./rule_default.js"),
userRule = defaultRule; //init
function userRequestHandler(req,userRes){
@@ -270,26 +270,40 @@ function connectReqHandler(req, socket, head){
};
resourceInfoId = GLOBAL.recorder.appendRecord(resourceInfo);
var proxyPort, proxyHost;
var proxyPort,
proxyHost,
internalHttpsPort,
httpsServerMgrInstance;
async.series([
//find port
//check if internal https server exists
function(callback){
if(internalHttpsPort){
callback();
}else{
getPort(function(port){
internalHttpsPort = port;
httpsServerMgrInstance = new httpsServerMgr({
port :port,
handler :userRequestHandler
});
callback();
});
}
},
//determine the target server
function(callback){
if(shouldIntercept){
//TODO : remote port other than 433
httpsServerMgrInstance.fetchPort(host,userRequestHandler,function(err,port){
if(!err && port){
proxyPort = port;
proxyHost = "127.0.0.1";
callback();
}else{
callback(err);
}
});
proxyPort = internalHttpsPort;
proxyHost = "127.0.0.1";
callback();
}else{
proxyPort = targetPort;
proxyPort = 443;
proxyHost = host;
callback();
@@ -305,7 +319,6 @@ function connectReqHandler(req, socket, head){
if(GLOBAL._throttle && !shouldIntercept ){
var readable = conn.pipe(GLOBAL._throttle.throttle());
readable.pipe(socket);
socket.pipe(conn);
}else{
conn.pipe(socket);