From b4aa93819b67f71b4334d81c4b0c4b93ea377afc Mon Sep 17 00:00:00 2001 From: Lloyd Hilaiel <lhilaiel@browserid-dev1.vm1.labs.sjc1.mozilla.com> Date: Fri, 13 Jan 2012 13:37:03 -0800 Subject: [PATCH] add outbound HTTP proxy support to browserid - requires a proxy that can forward http to https traffic - closes #904 --- lib/configuration.js | 13 ++++++++++++- lib/primary.js | 35 +++++++++++++++++++++++++++-------- scripts/check_primary_support | 6 +++--- 3 files changed, 42 insertions(+), 12 deletions(-) diff --git a/lib/configuration.js b/lib/configuration.js index b91ac9758..4fc6b246a 100644 --- a/lib/configuration.js +++ b/lib/configuration.js @@ -110,9 +110,14 @@ g_configs.production = { // return a 503 if a compute process would take over 10s to complete max_compute_duration: 10, disable_primary_support: true + /* + , http_proxy: { + port: 3128, + host: "127.0.0.1" + } + */ }; - // local development configuration g_configs.local = { URL: 'http://127.0.0.1:10002', @@ -130,6 +135,12 @@ g_configs.local = { max_compute_processes: undefined, max_compute_duration: 10, disable_primary_support: false +/* + , http_proxy: { + port: 3128, + host: "127.0.0.1" + } +*/ }; // test environments are variations on local diff --git a/lib/primary.js b/lib/primary.js index 3ec678df4..cefa8edaf 100644 --- a/lib/primary.js +++ b/lib/primary.js @@ -40,6 +40,7 @@ const https = require('https'), +http = require('http'), logger = require('./logging.js').logger, urlparse = require('urlparse'), jwk = require('jwcrypto/jwk'), @@ -115,12 +116,7 @@ exports.checkSupport = function(domain, cb) { cb(null, cacheValue); } - // now we need to check to see if domain purports to being a primary for browserid - var req = https.get({ - host: domain, - path: WELL_KNOWN_URL, - agent: false - }, function (res) { + function handleResponse(res) { if (res.statusCode !== 200) { logger.debug(domain + ' is not a browserid primary - non-200 response code to ' + WELL_KNOWN_URL); return cacheAndReturn(false); @@ -142,7 +138,30 @@ exports.checkSupport = function(domain, cb) { return cacheAndReturn(false); } }); - }).on('error', function(e) { + }; + + // now we need to check to see if domain purports to being a primary for browserid + var httpProxy = config.get('http_proxy'); + + var req; + if (httpProxy && httpProxy.port && httpProxy.host) { + req = http.get({ + host: httpProxy.host, + port: httpProxy.port, + path: 'https://' + domain + WELL_KNOWN_URL, + headers: { + host: domain + } + }, handleResponse); + } else { + req = https.get({ + host: domain, + path: WELL_KNOWN_URL, + agent: false + }, handleResponse); + } + + req.on('error', function(e) { logger.debug(domain + ' is not a browserid primary: ' + e.toString()); cacheAndReturn(false); }); @@ -174,7 +193,7 @@ if (process.env['SHIMMED_PRIMARIES']) { publicKey: r.publicKey }; - console.log("inserted primary info for '" + domain + "' into cache, pointed at '" + origin + "'"); + winston.info("inserted primary info for '" + domain + "' into cache, pointed at '" + origin + "'"); }); } diff --git a/scripts/check_primary_support b/scripts/check_primary_support index 51044ed38..ef913d3bd 100755 --- a/scripts/check_primary_support +++ b/scripts/check_primary_support @@ -1,11 +1,11 @@ +#!/usr/bin/env node + /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#!/usr/bin/env node - const -primary = require('../lib/browserid/primary'), +primary = require('../lib/primary'), logging = require('../lib/logging.js'); logging.enableConsoleLogging(); -- GitLab