bugfix for internal https

This commit is contained in:
OttoMao 2015-02-10 15:30:39 +08:00
parent d51cb0ce4b
commit e5d0b1bf4d
4 changed files with 22 additions and 7 deletions

View File

@ -1,3 +1,7 @@
10 Feb 2015: anyproxy 3.2.1:
* bugfix for 3.2.0
10 Feb 2015: anyproxy 3.2.0: 10 Feb 2015: anyproxy 3.2.0:
* using SNI when intercepting https requests * using SNI when intercepting https requests

View File

@ -6,10 +6,13 @@ var getPort = require('./getPort'),
fs = require('fs'), fs = require('fs'),
net = require('net'), net = require('net'),
tls = require('tls'), tls = require('tls'),
crypto = require('crypto'),
color = require('colorful'), color = require('colorful'),
certMgr = require("./certMgr"), certMgr = require("./certMgr"),
asyncTask = require("async-task-mgr"); asyncTask = require("async-task-mgr");
var createSecureContext = tls.createSecureContext || crypto.createSecureContext;
//using sni to avoid multiple ports //using sni to avoid multiple ports
function SNIPrepareCert(serverName,SNICallback){ function SNIPrepareCert(serverName,SNICallback){
var keyContent, crtContent,ctx; var keyContent, crtContent,ctx;
@ -28,7 +31,7 @@ function SNIPrepareCert(serverName,SNICallback){
}, },
function(callback){ function(callback){
try{ try{
ctx = tls.createSecureContext({ ctx = createSecureContext({
key :keyContent, key :keyContent,
cert :crtContent cert :crtContent
}); });
@ -43,7 +46,8 @@ function SNIPrepareCert(serverName,SNICallback){
console.log(color.yellow(color.bold("[internal https]")) + color.yellow(tipText)); console.log(color.yellow(color.bold("[internal https]")) + color.yellow(tipText));
SNICallback(null,ctx); SNICallback(null,ctx);
}else{ }else{
console.log("err occurred when prepare certs for SNI - " + e); console.log("err occurred when prepare certs for SNI - " + err);
console.log("you may have to upgrade your Node.js to the lastest version");
} }
}); });
} }
@ -57,9 +61,16 @@ module.exports =function(config){
throw(new Error("please assign a port")); throw(new Error("please assign a port"));
} }
https.createServer({ certMgr.getCertificate("anyproxy_internal_https_server",function(err,keyContent,crtContent){
SNICallback : SNIPrepareCert
},config.handler).listen(config.port); https.createServer({
SNICallback : SNIPrepareCert ,
key : keyContent,
cert : crtContent
},config.handler).listen(config.port);
});
} }

View File

@ -303,7 +303,7 @@ function connectReqHandler(req, socket, head){
callback(); callback();
}else{ }else{
proxyPort = 443; proxyPort = (targetPort == 8003)?8003:443; //ws
proxyHost = host; proxyHost = host;
callback(); callback();

View File

@ -1,6 +1,6 @@
{ {
"name": "anyproxy", "name": "anyproxy",
"version": "3.1.2", "version": "3.2.1",
"description": "A fully configurable proxy in NodeJS, which can handle HTTPS requests perfectly.", "description": "A fully configurable proxy in NodeJS, which can handle HTTPS requests perfectly.",
"main": "proxy.js", "main": "proxy.js",
"bin": { "bin": {