Skip to content

Commit

Permalink
Implement Linux support via UNIX socket proxy (#93)
Browse files Browse the repository at this point in the history
This is a companion PR to mozilla-mobile/mozilla-vpn-client#9952 that
implements Linux support by connecting to the SOCKS proxy as a systemd
service. Basically all we do here is check if the platform is `linux`
and set the bypass proxy to `{type: "socks", host:
"file:/var/run/mozillavpn.proxy", port: 1234}` The port number here
isn't used, but it seems to be required in order to be parsed as a valid
proxy.

Update! Now it supports connecting to the Windows proxy service too.
Similar logic, we just check the platform and generate a fixed proxy
config.
  • Loading branch information
oskirby authored Nov 22, 2024
1 parent 6c25992 commit 2715649
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/background/proxyHandler/proxyHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,31 @@ export class ProxyHandler extends Component {
constructor(receiver, controller) {
super(receiver);
this.controller = controller;
browser.runtime.getPlatformInfo((info) => {
this.#mPlatformOs = info.os;
if (info.os === "linux") {
// Linux provides bypass via a UNIX domain socket.
this.#mLocalProxyInfo.value = [
{
type: "socks",
host: "file:/var/run/mozillavpn.proxy",
port: 1234,
},
];
} else if (info.os === "win") {
// Windows uses a service on a well-known TCP port.
this.#mLocalProxyInfo.value = [
{
type: "socks",
host: "localhost",
port: 8123,
},
];
} else {
// Not supported on this platform
this.#mLocalProxyInfo.value = [];
}
});
}

/** @type {VPNState | undefined} */
Expand All @@ -46,6 +71,7 @@ export class ProxyHandler extends Component {
#mProxyMap = property(new Map());
#mLocalProxyInfo = property([]);
#mCurrentExitRelays = property([]);
#mPlatformOs = "unknown";

/** @type {IBindable<Map<String, SiteContext>>} */
get siteContexts() {
Expand Down Expand Up @@ -108,9 +134,6 @@ export class ProxyHandler extends Component {
*/
processClientStateChanges(vpnState) {
console.log(`Processing client state change ${vpnState}`);
this.#mLocalProxyInfo.value = vpnState.loophole
? [ProxyUtils.parseProxy(vpnState.loophole)]
: [];

if (this.servers.length == 0) {
console.log("No servers, unable to get exit location proxy info");
Expand Down

0 comments on commit 2715649

Please sign in to comment.