diff --git a/README.md b/README.md index 9ca8ffc..6166a8f 100644 --- a/README.md +++ b/README.md @@ -78,9 +78,10 @@ To use a proxy for local testing - * proxyPort: Port for the proxy, defaults to 3128 when -proxyHost is used * proxyUser: Username for connecting to proxy (Basic Auth Only) * proxyPass: Password for USERNAME, will be ignored if USERNAME is empty or not specified +* useCaCertificate: Path to ca cert file, if required ```js -bs_local_args = { 'key': '', 'proxyHost': '127.0.0.1', 'proxyPort': '8000', 'proxyUser': 'user', 'proxyPass': 'password' } +bs_local_args = { 'key': '', 'proxyHost': '127.0.0.1', 'proxyPort': '8000', 'proxyUser': 'user', 'proxyPass': 'password', 'useCaCertificate': '/Users/test/cert.pem' } ``` #### Local Proxy diff --git a/lib/Local.js b/lib/Local.js index fd58429..9d8d086 100644 --- a/lib/Local.js +++ b/lib/Local.js @@ -183,6 +183,11 @@ function Local(){ } break; + case 'useCaCertificate': + if(value) + this.useCaCertificate = value; + break; + case 'proxyHost': if(value) this.proxyHost = value; @@ -245,6 +250,9 @@ function Local(){ conf.proxyHost = this.proxyHost; conf.proxyPort = this.proxyPort; } + if (this.useCaCertificate) { + conf.useCaCertificate = this.useCaCertificate; + } if(!callback) { return this.binary.binaryPath(conf); } @@ -284,6 +292,10 @@ function Local(){ } if(this.onlyAutomateFlag) args.push(this.onlyAutomateFlag); + if (this.useCaCertificate) { + args.push('--use-ca-certificate'); + args.push(this.useCaCertificate); + } if(this.proxyHost){ args.push('--proxy-host'); args.push(this.proxyHost); diff --git a/lib/LocalBinary.js b/lib/LocalBinary.js index a019979..9f7f672 100644 --- a/lib/LocalBinary.js +++ b/lib/LocalBinary.js @@ -73,6 +73,11 @@ function LocalBinary(){ opts = [path.join(__dirname, 'download.js'), binaryPath, this.httpPath]; if(conf.proxyHost && conf.proxyPort) { opts.push(conf.proxyHost, conf.proxyPort); + if (conf.useCaCertificate) { + opts.push(conf.useCaCertificate); + } + } else if (conf.useCaCertificate) { + opts.push(undefined, undefined, conf.useCaCertificate); } try{ @@ -113,6 +118,13 @@ function LocalBinary(){ port: conf.proxyPort }); } + if (conf.useCaCertificate) { + try { + options.ca = fs.readFileSync(conf.useCaCertificate); + } catch(err) { + console.log("failed to read cert file", err) + } + } https.get(options, function (response) { response.pipe(fileStream); diff --git a/lib/download.js b/lib/download.js index 14b9179..34f93a8 100644 --- a/lib/download.js +++ b/lib/download.js @@ -3,7 +3,7 @@ const https = require('https'), HttpsProxyAgent = require('https-proxy-agent'), url = require('url'); -const binaryPath = process.argv[2],httpPath = process.argv[3], proxyHost = process.argv[4], proxyPort = process.argv[5]; +const binaryPath = process.argv[2], httpPath = process.argv[3], proxyHost = process.argv[4], proxyPort = process.argv[5], useCaCertificate = process.argv[6]; var fileStream = fs.createWriteStream(binaryPath); @@ -13,6 +13,13 @@ if(proxyHost && proxyPort) { host: proxyHost, port: proxyPort }); + if (useCaCertificate) { + try { + options.ca = fs.readFileSync(useCaCertificate); + } catch(err) { + console.log("failed to read cert file", err) + } + } } https.get(options, function (response) {