From f438bed1e64c596ffed1448f71652d0d83c6216d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8A=A0=E9=87=8C?= Date: Fri, 22 Aug 2014 17:00:20 +0800 Subject: [PATCH] optimize self-signed certs --- cert/gen-rootCA | 3 ++- lib/requestHandler.js | 12 +++++++----- package.json | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/cert/gen-rootCA b/cert/gen-rootCA index f3db271..b8f3658 100755 --- a/cert/gen-rootCA +++ b/cert/gen-rootCA @@ -3,7 +3,8 @@ outputPath=$1 cd $outputPath openssl genrsa -out rootCA.key 2048 -openssl req -x509 -new -nodes -key rootCA.key -days 36500 -out rootCA.crt +openssl req -x509 -new -nodes -key rootCA.key -days 36500 -out rootCA.crt \ + -subj "/C=CN/ST=SH/L=SH/O=AnyProxy/OU=Section/CN=AnyProxy/emailAddress=AnyProxy@AnyProxy" echo "=============" echo "rootCA generated at :" pwd diff --git a/lib/requestHandler.js b/lib/requestHandler.js index fd06af7..36053a7 100644 --- a/lib/requestHandler.js +++ b/lib/requestHandler.js @@ -20,7 +20,7 @@ var handleRule = { // } ] ,httpsConfig:{ - bypassAll : false, + bypassAll : true, interceptDomains:["^.*alibaba-inc\.com$"] } }; @@ -51,6 +51,7 @@ function userRequestHandler(req,userRes){ var hostTest = new RegExp(rule.host).test(host), pathTest = new RegExp(rule.path).test(path); + //TODO : CORS for local file if(hostTest && pathTest && (rule.localFile || rule.localDir) ){ console.log("==>meet the rules, will map to local file"); @@ -112,12 +113,13 @@ function connectReqHandler(req, socket, head){ targetPort= req.url.split(":")[1], httpsRule = handleRule.httpsConfig; - var shouldBypass = httpsRule.bypassAll; + var shouldBypass = !!httpsRule.bypassAll; if(!shouldBypass){ //read rules + shouldBypass = true; for(var index in httpsRule.interceptDomains){ var reg = new RegExp(httpsRule.interceptDomains[index]); if( reg.test(hostname) ){ - shouldBypass = true; + shouldBypass = false; break; } } @@ -126,7 +128,7 @@ function connectReqHandler(req, socket, head){ console.log(color.green("\nreceived https CONNECT request " + hostname)); if(shouldBypass){ - console.log("==>meet the rules, will bypass the man-in-the-middle proxy"); + console.log("==>will bypass the man-in-the-middle proxy"); try{ var conn = net.connect(targetPort, hostname, function(){ socket.write('HTTP/' + req.httpVersion + ' 200 OK\r\n\r\n', 'UTF-8', function() { @@ -144,7 +146,7 @@ function connectReqHandler(req, socket, head){ }else{ //TODO : remote port other than 433 - console.log("==>will forward to local https server"); + console.log("==>meet the rules, will forward to local https server"); //forward the https-request to local https server httpsServerMgrInstance.fetchPort(hostname,userRequestHandler,function(err,port){ diff --git a/package.json b/package.json index f78ac5a..9b5ee6b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "anyproxy", - "version": "1.2.5", + "version": "1.2.6", "description": "another proxy written in NODEJS, which can handle HTTPS requests and CROS perfectly", "main": "proxy.js", "bin": {