add download link for rootCA.crt, bugfix

This commit is contained in:
OttoMao 2014-11-06 13:55:43 +08:00
parent f685d82dd9
commit 0db6b1861a
6 changed files with 34 additions and 5 deletions

View File

@ -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

View File

@ -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;

View File

@ -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": {

View File

@ -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",

View File

@ -15,6 +15,7 @@
<a href="#" class="J_clearBtn"><span class="topBtn">Clear Logs(Ctrl+X)</span></a>
<a href="#" class="J_statusBtn"><span class="topBtn">Stop</span></a>
<a href="#" class="J_statusBtn btn_disable"><span class="topBtn">Resume</span></a>
<a href="/fetchCrtFile" target="_blank"><span class="topBtn">Fetch rootCA.crt</span></a>
<a href="http://localhost:{{proxyConfigPort}}"><span class="topBtn">Config Local Response(beta)</span></a>
</div>
<div class="ruleDesc">

View File

@ -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 <strong>anyproxy --root</strong> to generate one");
}
});
//make qr code
app.get("/qr",function(req,res){
var qr = qrCode.qrcode(4, 'M'),