From 0db6b1861a15a43a030de11efabcaa0002fd2539 Mon Sep 17 00:00:00 2001 From: OttoMao Date: Thu, 6 Nov 2014 13:55:43 +0800 Subject: [PATCH] add download link for rootCA.crt, bugfix --- README.md | 1 + lib/certMgr.js | 13 ++++++++++++- package.json | 2 +- proxy.js | 4 +++- web/index.html | 1 + webServer.js | 18 ++++++++++++++++-- 6 files changed, 34 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 5aec734..a78182a 100644 --- a/README.md +++ b/README.md @@ -207,6 +207,7 @@ Using https features #### about certs * root certs and temperary certs are stored at ``path.join(util.getUserHome(),"/.anyproxy_certs/")`` +* to get the rootCA.crt file , you may either find it in local dir or download it via anyproxy web interface * to clear all the temperary certificates ``anyproxy --clear`` Others diff --git a/lib/certMgr.js b/lib/certMgr.js index 1151fa7..1c2b159 100644 --- a/lib/certMgr.js +++ b/lib/certMgr.js @@ -72,7 +72,7 @@ function checkRootCA(){ if(!isRootCAFileExists()){ console.log(color.red("can not find rootCA.crt or rootCA.key")); console.log(color.red("you may generate one by the following methods")); - console.log(color.red("\twhen using globally : sudo anyproxy --root")); + console.log(color.red("\twhen using globally : anyproxy --root")); console.log(color.red("\twhen using as a module : require(\"anyproxy\").generateRootCA();")); process.exit(0); } @@ -110,6 +110,7 @@ function generateRootCA(){ if(code == 0){ console.log(color.green("rootCA generated")); console.log(color.green(color.bold("please trust the rootCA.crt in " + certDir))); + console.log(color.green(color.bold("or you may get it via anyproxy webinterface"))); process.exit(0); }else{ console.log(color.red("fail to generate root CA")); @@ -120,6 +121,16 @@ function generateRootCA(){ } } + +function getRootCAFilePath(){ + if(isRootCAFileExists()){ + return path.join(certDir,"rootCA.crt"); + }else{ + return ""; + } +} + +module.exports.getRootCAFilePath = getRootCAFilePath; module.exports.generateRootCA = generateRootCA; module.exports.getCertificate = getCertificate; module.exports.createCert = createCert; diff --git a/package.json b/package.json index 8275741..f856e55 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "anyproxy", - "version": "2.7.6", + "version": "2.8.0", "description": "A fully configurable proxy in NodeJS, which can handle HTTPS requests perfectly.", "main": "proxy.js", "bin": { diff --git a/proxy.js b/proxy.js index 8cdf2a3..d130db7 100644 --- a/proxy.js +++ b/proxy.js @@ -146,10 +146,12 @@ function proxyServer(option){ //TODO : uncaught exception //kill web server when father process exits - process.on("exit",function(){ + process.on("exit uncaughtException",function(){ child_webServer.kill(); + process.exit(); }); + GLOBAL.recorder.on("update",function(data){ child_webServer.send({ type: "update", diff --git a/web/index.html b/web/index.html index 68232fb..bb97e28 100644 --- a/web/index.html +++ b/web/index.html @@ -15,6 +15,7 @@ Clear Logs(Ctrl+X) Stop Resume + Fetch rootCA.crt Config Local Response(beta)
diff --git a/webServer.js b/webServer.js index 4fd2209..de50889 100644 --- a/webServer.js +++ b/webServer.js @@ -3,6 +3,7 @@ var express = require("express"), url = require('url'), fs = require("fs"), util = require("./lib/util"), + certMgr = require("./lib/certMgr"), events = require("events"), inherits = require("util").inherits, entities = require("entities"), @@ -10,8 +11,10 @@ var express = require("express"), WebSocketServer = require('ws').Server; function proxyWebServer(port,webSocketPort,proxyConfigPort,ruleSummary,ipAddress){ - var self = this, - myAbsAddress = "http://" + ipAddress + ":" + port +"/"; + + var self = this, + myAbsAddress = "http://" + ipAddress + ":" + port +"/", + crtFilePath = certMgr.getRootCAFilePath(); if(arguments.length < 3){ throw new Error("please assign ports"); @@ -46,6 +49,17 @@ function proxyWebServer(port,webSocketPort,proxyConfigPort,ruleSummary,ipAddress }); }); + app.get("/fetchCrtFile",function(req,res){ + if(crtFilePath){ + res.setHeader("Content-Type","application/x-x509-ca-cert"); + res.setHeader("Content-Disposition",'attachment; filename="rootCA.crt"'); + res.end(fs.readFileSync(crtFilePath,{encoding:null})); + }else{ + res.setHeader("Content-Type","text/html"); + res.end("can not file rootCA ,plase use anyproxy --root to generate one"); + } + }); + //make qr code app.get("/qr",function(req,res){ var qr = qrCode.qrcode(4, 'M'),