Skip to content

Commit

Permalink
Use object return types when possible on Firefox with auth. Fix #1172.
Browse files Browse the repository at this point in the history
  • Loading branch information
FelisCatus committed Sep 20, 2017
1 parent b1c261c commit 06e7ad6
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 22 deletions.
16 changes: 13 additions & 3 deletions omega-pac/src/profiles.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,20 @@ module.exports = exports =
if profile.bypassList
for cond in profile.bypassList
if Conditions.match(cond, request)
return [@pacResult(), cond]
return [@pacResult(), cond, {scheme: 'direct'}, null]
for s in @schemes when s.scheme == request.scheme and profile[s.prop]
return [@pacResult(profile[s.prop]), s.scheme]
return [@pacResult(profile.fallbackProxy), '']
return [
@pacResult(profile[s.prop]),
s.scheme,
profile[s.prop],
profile.auth?[s.prop] ? profile.auth?['all']
]
return [
@pacResult(profile.fallbackProxy),
'',
profile.fallbackProxy,
profile.auth?.fallbackProxy ? profile.auth?['all']
]
compile: (profile) ->
if ((not profile.bypassList or not profile.fallbackProxy) and
not profile.proxyForHttp and not profile.proxyForHttps and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,35 @@ FindProxyForURL = (function () {

if (Array.isArray(matchResult)) {
next = matchResult[0];
// TODO: Maybe also return user/pass if Mozilla supports it or it ends
// up standardized in WebExtensions in the future.
// MOZ: Mozilla has a bug tracked for user/pass in PAC return value.
// https://bugzilla.mozilla.org/show_bug.cgi?id=1319641
if (next.charCodeAt(0) !== 43) {
var proxy = matchResult[2];
var auth = matchResult[3];
if (proxy && !state.useLegacyStringReturn) {
var proxyInfo = {
type: proxy.scheme,
host: proxy.host,
port: proxy.port,
};
if (proxyInfo.type === 'socks5') {
// MOZ: SOCKS5 proxies are identified by "type": "socks".
// https://dxr.mozilla.org/mozilla-central/rev/ffe6cc09ccf38cca6f0e727837bbc6cb722d1e71/toolkit/components/extensions/ProxyScriptContext.jsm#51
proxyInfo.type = 'socks';
// Enable SOCKS5 remote DNS.
// TODO(catus): Maybe allow the users to configure this?
proxyInfo.proxyDNS = true;
}
if (auth) {
proxyInfo.username = auth.username;
proxyInfo.password = auth.password;
}
return [proxyInfo];
} else if (next.charCodeAt(0) !== 43) {
// MOZ: Legacy proxy support expects PAC-like string return type.
// TODO(catus): Remove support for string return type.
// MOZ: SOCKS5 proxies are supported under the prefix SOCKS.
// https://dxr.mozilla.org/mozilla-central/source/toolkit/components/extensions/ProxyScriptContext.jsm#178
// https://dxr.mozilla.org/mozilla-central/rev/ffe6cc09ccf38cca6f0e727837bbc6cb722d1e71/toolkit/components/extensions/ProxyScriptContext.jsm#51
// Note: We have to replace this because MOZ won't process the rest of
// the list if the syntax of the first item is not recognized.
next = next.replace(/SOCKS5 /g, 'SOCKS ');

return next;
return next.replace(/SOCKS5 /g, 'SOCKS ');
}
} else if (matchResult.profileName) {
next = OmegaPac.Profiles.nameAsKey(matchResult.profileName)
Expand Down
41 changes: 32 additions & 9 deletions omega-target-chromium-extension/src/module/options.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -199,22 +199,45 @@ class ChromeOptions extends OmegaTarget.Options
@_proxyScriptDisabled = true
else
@_proxyScriptState = state
@_initWebextProxyScript().then => @_proxyScriptStateChanged()
# Proxy authentication is not covered in WebExtensions standard now.
# MOZ: Mozilla has a bug tracked to implemented it in PAC return value.
# https://bugzilla.mozilla.org/show_bug.cgi?id=1319641
Promise.all([
browser.runtime.getBrowserInfo(),
@_initWebextProxyScript(),
]).then ([info]) =>
if info.vendor == 'Mozilla' and info.buildID < '20170918220054'
# MOZ: Legacy proxy support expects PAC-like string return type.
# TODO(catus): Remove support for string return type.
@log.error(
'WARNING: Your browser is outdated! SOCKS5 DNS/Auth unsupported!')
@log.error('Please update your browser ASAP!')
@log.error("useLegacyStringReturn=true for Build: #{info.buildID}.")
@_proxyScriptState.useLegacyStringReturn = true
@_proxyScriptStateChanged()
@_proxyAuth ?= new ProxyAuth(this)
@_proxyAuth.listen()
@_proxyAuth.setProxies(@_watchingProfiles)
return Promise.resolve()

_proxyScriptInitialized: false
_proxyScriptState: {}
_initWebextProxyScript: ->
if not @_proxyScriptInitialized
browser.proxy.onProxyError.addListener (err) =>
if err and err.message.indexOf('Invalid Proxy Rule: DIRECT') >= 0
# DIRECT cannot be parsed in Mozilla earlier due to a bug. Even though
# it throws, it actually falls back to direct connection so it works.
# https://bugzilla.mozilla.org/show_bug.cgi?id=1355198
return
if err?.message?
if err.message.indexOf('Invalid Proxy Rule: DIRECT') >= 0
# DIRECT cannot be parsed in Mozilla earlier due to a bug. Even
# though it throws, it actually falls back to direct connection
# so it works.
# https://bugzilla.mozilla.org/show_bug.cgi?id=1355198
return
if err.message.indexOf('Return type must be a string') >= 0
# MOZ: Legacy proxy support expects PAC-like string return type.
# TODO(catus): Remove support for string return type.
@log.error(
'WARNING: Your browser is outdated! Remote DNS is unsupported!')
@log.error('Please update your browser ASAP!')
@_proxyScriptState.useLegacyStringReturn = true
@_proxyScriptStateChanged()
return
@log.error(err)
browser.runtime.onMessage.addListener (message) =>
return unless message.event == 'proxyScriptLog'
Expand Down
7 changes: 6 additions & 1 deletion omega-web/src/omega/controllers/fixed_profile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ angular.module('omega').controller 'FixedProfileCtrl', ($scope, $modal,

$scope.proxyEditors = {}

$scope.authSupported = {"http": true, "https": true}
socks5AuthSupported = (browser?.proxy?.register?)
$scope.authSupported = {
"http": true,
"https": true,
"socks5": socks5AuthSupported,
}
$scope.isProxyAuthActive = (scheme) ->
return $scope.profile.auth?[proxyProperties[scheme]]?
$scope.editProxyAuth = (scheme) ->
Expand Down

0 comments on commit 06e7ad6

Please sign in to comment.