Skip to content

Commit 434f689

Browse files
committed
Add basic WebRTC leak code from webrtc/samples
1 parent 8b5ed32 commit 434f689

File tree

9 files changed

+353
-0
lines changed

9 files changed

+353
-0
lines changed

_locales/en/messages.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"NETLI_APPDESC": {
3+
"message": "Cypherpunk Privacy Suite"
4+
},
5+
"NETLI_APPNAME": {
6+
"message": "Cypherpunk Privacy Suite"
7+
},
8+
"NETLI_DEFAULT_PUBLIC_AND_PRIVATE_INTERFACES_RADIO": {
9+
"message": "\u003Cstrong>Use my default public and private IP addresses:\u003C/strong> This option forces Chrome to use the same network path for media as for normal web traffic, except when a web proxy is present. For machines behind a NAT, Chrome will also use the default private address to enhance connectivity. To prevent degraded performance, Chrome will attempt to send media directly instead of using the proxy."
10+
},
11+
"NETLI_DEFAULT_PUBLIC_INTERFACE_ONLY_RADIO": {
12+
"message": "\u003Cstrong>Use only my default public IP address:\u003C/strong> This option is the same as \u003Cem>Use my default public and private IP addresses\u003C/em> except that Chrome will not use the private default address."
13+
},
14+
"NETLI_DEFAULT_RADIO": {
15+
"message": "\u003Cstrong>Give me the best media experience:\u003C/strong> This option allows Chrome to explore all network paths to find the best way to send and receive media, which may be different from normal web traffic."
16+
},
17+
"NETLI_DISABLE_NON_PROXIED_UDP_RADIO": {
18+
"message": "\u003Cstrong>Use my proxy server (if present):\u003C/strong> This option forces Chrome to use the same network path for media as for normal web traffic, including use of a web proxy. Chrome will always attempt to send media through the proxy, which will typically hurt media performance and increase the load on the proxy; furthermore, this behavior may be incompatible with some applications."
19+
},
20+
"NETLI_OPTIONS": {
21+
"message": "WebRTC Network Limiter Options"
22+
},
23+
"NETLI_OPTION_NOT_SUPPORTED": {
24+
"message": "Grayed out options require newer verion of Chrome."
25+
}
26+
}

background.html

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<script src="utils.js"></script>
2+
<script src="eventPage.js"></script>

eventPage.js

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3+
*
4+
* Use of this source code is governed by a BSD-style license
5+
* that can be found in the LICENSE file in the root of the source
6+
* tree.
7+
*/
8+
9+
// This file sets the policy when the extension is installed and registered for
10+
// chrome.runtime.onInstalled event to convert the booleans in pre-M48 version
11+
// to IPHandlingPolicy when chrome is upgraded to M48.
12+
13+
'use strict';
14+
15+
// If this is installed in a pre-M48 version of Chrome, the only thing to do
16+
// here is to disable MultipleRoute.
17+
var pn = chrome.privacy.network;
18+
var pi = chrome.privacy.IPHandlingPolicy;
19+
20+
if (!browserSupportsIPHandlingPolicy()) {
21+
pn.webRTCMultipleRoutesEnabled.set({
22+
value: false
23+
});
24+
}
25+
26+
// This function resets the 2 booleans to default values so we can ignore them
27+
// as if they were not set in future chrome.runtime.onInstalled event. This is
28+
// to avoid repeated conversions and overwrite the current setting.
29+
function resetOldBooleans(callback) {
30+
pn.webRTCNonProxiedUdpEnabled.set({
31+
value: true
32+
}, function() {
33+
pn.webRTCMultipleRoutesEnabled.set({
34+
value: true
35+
}, function() {
36+
callback('Successfully reset the booleans');
37+
});
38+
});
39+
}
40+
41+
// Converts the old booleans to the new policy in Preferences and resets the 2
42+
// previous booleans to the default. Future chrome updates could trigger this
43+
// function again but they will either stop the conversion if
44+
// webRTCIPHandlingPolicy is not "default" or for the case of "default", since
45+
// the previous booleans have been reset to default, it'll be translate to
46+
// "default" again.
47+
function convertBooleansToPolicy(isInstall, callback) {
48+
if (!browserSupportsIPHandlingPolicy()) {
49+
return;
50+
}
51+
52+
pn.webRTCIPHandlingPolicy.get({}, function(details) {
53+
if (details.value !== chrome.privacy.IPHandlingPolicy.DEFAULT) {
54+
if (callback) {
55+
callback(
56+
'webRTCIPHandlingPolicy has a non-default value, stop now.'
57+
);
58+
}
59+
return;
60+
}
61+
62+
getPolicyFromBooleans(function(policy) {
63+
if (policy === pi.DEFAULT && isInstall) {
64+
// It's safe to use the enum value here since
65+
// browserSupportsIPHandlingPolicy must be true.
66+
policy = pi.DEFAULT_PUBLIC_AND_PRIVATE_INTERFACES;
67+
}
68+
pn.webRTCIPHandlingPolicy.set({
69+
value: policy
70+
}, resetOldBooleans(callback));
71+
});
72+
});
73+
}
74+
75+
function onInstall(details) {
76+
if (details.reason === 'install' /* extension is installed */ ||
77+
details.reason === 'update' /* extension is upgraded */ ||
78+
details.reason === 'chrome_update' /* chrome is upgraded */ ) {
79+
convertBooleansToPolicy(
80+
details.reason === 'install',
81+
function(status) {
82+
console.log(status);
83+
});
84+
}
85+
}
86+
87+
chrome.runtime.onInstalled.addListener(onInstall);

img/icon_128.png

13.5 KB
Loading

img/icon_16.png

632 Bytes
Loading

manifest.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"background": {
3+
"page": "background.html",
4+
"persistent": false
5+
},
6+
"default_locale": "en",
7+
"description": "__MSG_NETLI_APPDESC__",
8+
"icons": {
9+
"128": "img/icon_128.png",
10+
"16": "img/icon_16.png"
11+
},
12+
"manifest_version": 2,
13+
"minimum_chrome_version": "42.0.2311.135",
14+
"name": "__MSG_NETLI_APPNAME__",
15+
"options_ui": {
16+
"chrome_style": true,
17+
"page": "options.html"
18+
},
19+
"permissions": [ "privacy" ],
20+
"version": "0.0.1"
21+
}

options.html

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<!doctype html>
2+
<html>
3+
<body>
4+
<p id="Mode0">
5+
<input type="radio" name="ip_policy_selection" id="default" value="default">
6+
<label for="default">
7+
<span i18n-content="netli_default_radio"></span>
8+
</label>
9+
<p id="Mode1">
10+
<input type="radio" name="ip_policy_selection"
11+
id="default_public_and_private_interfaces"
12+
value="default_public_and_private_interfaces">
13+
<label for="default_public_and_private_interfaces">
14+
<span i18n-content="netli_default_public_and_private_interfaces_radio"></span>
15+
</label>
16+
<p id="Mode2">
17+
<input type="radio" name="ip_policy_selection"
18+
id="default_public_interface_only"
19+
value="default_public_interface_only">
20+
<label for="default_public_interface_only">
21+
<span i18n-content="netli_default_public_interface_only_radio"></span>
22+
</label>
23+
<p id="Mode3">
24+
<input type="radio" name="ip_policy_selection"
25+
id="disable_non_proxied_udp" value="disable_non_proxied_udp">
26+
<label for="disable_non_proxied_udp" id="for_disable_non_proxied_udp">
27+
<span i18n-content="netli_disable_non_proxied_udp_radio"></span>
28+
</label>
29+
<p>
30+
<label id="not_supported">
31+
<span i18n-content="netli_option_not_supported"></span>
32+
</label>
33+
<script src="utils.js"></script>
34+
<script src="options.js"></script>
35+
</body>
36+
</html>

options.js

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/*
2+
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3+
*
4+
* Use of this source code is governed by a BSD-style license
5+
* that can be found in the LICENSE file in the root of the source
6+
* tree.
7+
*/
8+
9+
'use strict';
10+
11+
var pn = chrome.privacy.network;
12+
var pi = chrome.privacy.IPHandlingPolicy;
13+
14+
var mapPolicyToRadioId = {};
15+
mapPolicyToRadioId[pi.DEFAULT] = 0;
16+
mapPolicyToRadioId[pi.DEFAULT_PUBLIC_AND_PRIVATE_INTERFACES] = 1;
17+
mapPolicyToRadioId[pi.DEFAULT_PUBLIC_INTERFACE_ONLY] = 2;
18+
mapPolicyToRadioId[pi.DISABLE_NON_PROXIED_UDP] = 3;
19+
20+
var mapRadioIdToPolicy = {};
21+
if (!browserSupportsIPHandlingPolicy()) {
22+
// radio id => [|webRTCMultipleRoutesEnabled|, |webRTCNonProxiedUdpEnabled|]
23+
// The [1] option won't exist if pn.webRTCIPHandlingPolicy is undefined.
24+
mapRadioIdToPolicy[0] = {allowMultipleRoutes: true, allowUdp: true};
25+
mapRadioIdToPolicy[2] = {allowMultipleRoutes: false, allowUdp: true};
26+
mapRadioIdToPolicy[3] = {allowMultipleRoutes: false, allowUdp: false};
27+
} else {
28+
mapRadioIdToPolicy[0] = pi.DEFAULT;
29+
mapRadioIdToPolicy[1] = pi.DEFAULT_PUBLIC_AND_PRIVATE_INTERFACES;
30+
mapRadioIdToPolicy[2] = pi.DEFAULT_PUBLIC_INTERFACE_ONLY;
31+
mapRadioIdToPolicy[3] = pi.DISABLE_NON_PROXIED_UDP;
32+
}
33+
34+
// Saves options.
35+
function saveOptions() {
36+
var radios = document.getElementsByName('ip_policy_selection');
37+
for (var i = 0; i < radios.length; i++) {
38+
if (radios[i].checked) {
39+
break;
40+
}
41+
}
42+
43+
if (browserSupportsIPHandlingPolicy()) {
44+
pn.webRTCIPHandlingPolicy.set({
45+
value: mapRadioIdToPolicy[i]
46+
});
47+
} else {
48+
var oldBools = mapRadioIdToPolicy[i];
49+
pn.webRTCMultipleRoutesEnabled.set({
50+
value: oldBools.allowMultipleRoutes
51+
}, function() {
52+
if (browserSupportsNonProxiedUdpBoolean()) {
53+
pn.webRTCNonProxiedUdpEnabled.set({
54+
value: oldBools.allowUdp
55+
});
56+
}
57+
});
58+
}
59+
}
60+
61+
function restoreRadios(policy) {
62+
var radios = document.getElementsByName('ip_policy_selection');
63+
radios[mapPolicyToRadioId[policy]].checked = true;
64+
}
65+
66+
function restoreOption() {
67+
if (browserSupportsIPHandlingPolicy()) {
68+
pn.webRTCIPHandlingPolicy.get({}, function(details) {
69+
restoreRadios(details.value);
70+
});
71+
} else {
72+
getPolicyFromBooleans(function(policy) {
73+
restoreRadios(policy);
74+
});
75+
}
76+
}
77+
78+
var supportedIPPolicyModes = {
79+
// DEFAULT
80+
Mode0: true,
81+
// DEFAULT_PUBLIC_AND_PRIVATE_INTERFACES
82+
Mode1: browserSupportsIPHandlingPolicy(),
83+
// DEFAULT_PUBLIC_INTERFACE_ONLY
84+
Mode2: true,
85+
// NON_PROXIED_UDP
86+
Mode3: browserSupportsNonProxiedUdpBoolean()
87+
};
88+
89+
document.addEventListener('DOMContentLoaded', restoreOption);
90+
document.getElementById('default').
91+
addEventListener('click', saveOptions);
92+
document.getElementById('default_public_and_private_interfaces').
93+
addEventListener('click', saveOptions);
94+
document.getElementById('default_public_interface_only').
95+
addEventListener('click', saveOptions);
96+
document.getElementById('disable_non_proxied_udp').
97+
addEventListener('click', saveOptions);
98+
99+
document.title = chrome.i18n.getMessage('netli_options');
100+
var i18nElements = document.querySelectorAll('*[i18n-content]');
101+
for (var i = 0; i < i18nElements.length; i++) {
102+
var elem = i18nElements[i];
103+
var msg = elem.getAttribute('i18n-content');
104+
elem.innerHTML = chrome.i18n.getMessage(msg);
105+
}
106+
107+
var hideBanner = true;
108+
for (i = 0; i < Object.keys(supportedIPPolicyModes).length; i++) {
109+
var key = 'Mode' + i;
110+
if (!supportedIPPolicyModes[key]) {
111+
var section = document.getElementById(key);
112+
section.style.color = 'gray';
113+
section.querySelector('input').disabled = true;
114+
hideBanner = false;
115+
}
116+
}
117+
118+
if (hideBanner) {
119+
document.getElementById('not_supported').innerHTML = '';
120+
}

utils.js

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3+
*
4+
* Use of this source code is governed by a BSD-style license
5+
* that can be found in the LICENSE file in the root of the source
6+
* tree.
7+
*/
8+
9+
/* exported getPolicyFromBooleans */
10+
11+
'use strict';
12+
13+
var pn = chrome.privacy.network;
14+
var pi = null;
15+
16+
function browserSupportsIPHandlingPolicy() {
17+
return pn.webRTCIPHandlingPolicy !== undefined;
18+
}
19+
20+
function browserSupportsNonProxiedUdpBoolean() {
21+
return pn.webRTCNonProxiedUdpEnabled !== undefined;
22+
}
23+
24+
// Handle the case when this is installed in pre-M48.
25+
if (!browserSupportsIPHandlingPolicy()) {
26+
chrome.privacy.IPHandlingPolicy = {};
27+
chrome.privacy.IPHandlingPolicy.DEFAULT = 0;
28+
chrome.privacy.IPHandlingPolicy.DEFAULT_PUBLIC_AND_PRIVATE_INTERFACES = 1;
29+
chrome.privacy.IPHandlingPolicy.DEFAULT_PUBLIC_INTERFACE_ONLY = 2;
30+
chrome.privacy.IPHandlingPolicy.DISABLE_NON_PROXIED_UDP = 3;
31+
}
32+
33+
pi = chrome.privacy.IPHandlingPolicy;
34+
35+
// Helper function to convert the parameters to policy synchronously.
36+
function convertToPolicy(allowMultiRoute, allowUdp) {
37+
if (!allowUdp) {
38+
return pi.DISABLE_NON_PROXIED_UDP;
39+
}
40+
41+
if (!allowMultiRoute) {
42+
return pi.DEFAULT_PUBLIC_INTERFACE_ONLY;
43+
}
44+
45+
return pi.DEFAULT;
46+
}
47+
48+
// This function just returns the new policy value based on the 2 booleans
49+
// without changing any preferences.
50+
function getPolicyFromBooleans(callback) {
51+
pn.webRTCMultipleRoutesEnabled.get({}, function(allowMultiRoute) {
52+
if (!browserSupportsNonProxiedUdpBoolean()) {
53+
callback(convertToPolicy(allowMultiRoute.value, true));
54+
} else {
55+
pn.webRTCNonProxiedUdpEnabled.get({}, function(allowUdp) {
56+
callback(convertToPolicy(allowMultiRoute.value,
57+
allowUdp.value));
58+
});
59+
}
60+
});
61+
}

0 commit comments

Comments
 (0)