1
0
mirror of https://github.com/alibaba/anyproxy.git synced 2025-05-10 14:58:27 +00:00

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

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

@ -6,10 +6,13 @@ var getPort = require('./getPort'),
fs = require('fs'),
net = require('net'),
tls = require('tls'),
crypto = require('crypto'),
color = require('colorful'),
certMgr = require("./certMgr"),
asyncTask = require("async-task-mgr");
var createSecureContext = tls.createSecureContext || crypto.createSecureContext;
//using sni to avoid multiple ports
function SNIPrepareCert(serverName,SNICallback){
var keyContent, crtContent,ctx;
@ -28,7 +31,7 @@ function SNIPrepareCert(serverName,SNICallback){
},
function(callback){
try{
ctx = tls.createSecureContext({
ctx = createSecureContext({
key :keyContent,
cert :crtContent
});
@ -43,7 +46,8 @@ function SNIPrepareCert(serverName,SNICallback){
console.log(color.yellow(color.bold("[internal https]")) + color.yellow(tipText));
SNICallback(null,ctx);
}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"));
}
https.createServer({
SNICallback : SNIPrepareCert
},config.handler).listen(config.port);
certMgr.getCertificate("anyproxy_internal_https_server",function(err,keyContent,crtContent){
https.createServer({
SNICallback : SNIPrepareCert ,
key : keyContent,
cert : crtContent
},config.handler).listen(config.port);
});
}

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

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