Remove proxy/ subdirectory
We're moving all web proxy code to a different repsitory.
|
@ -1,8 +0,0 @@
|
|||
build/
|
||||
test/
|
||||
webext/snowflake.js
|
||||
snowflake-library.js
|
||||
|
||||
# FIXME: Whittle these away
|
||||
spec/
|
||||
shims.js
|
|
@ -1,13 +0,0 @@
|
|||
{
|
||||
"env": {
|
||||
"browser": true,
|
||||
"es6": true
|
||||
},
|
||||
"extends": "eslint:recommended",
|
||||
"rules": {
|
||||
"indent": ["error", 2, {
|
||||
"SwitchCase": 1,
|
||||
"MemberExpression": 0
|
||||
}]
|
||||
}
|
||||
}
|
143
proxy/README.md
|
@ -1,143 +0,0 @@
|
|||
This is the browser proxy component of Snowflake.
|
||||
|
||||
### Embedding
|
||||
|
||||
See https://snowflake.torproject.org/ for more info:
|
||||
```
|
||||
<iframe src="https://snowflake.torproject.org/embed.html" width="88" height="16" frameborder="0" scrolling="no"></iframe>
|
||||
```
|
||||
|
||||
### Building the badge / snowflake.torproject.org
|
||||
|
||||
```
|
||||
npm install
|
||||
npm run build
|
||||
```
|
||||
|
||||
which outputs to the `build/` directory.
|
||||
|
||||
### Building the webextension
|
||||
|
||||
```
|
||||
npm install
|
||||
npm run webext
|
||||
```
|
||||
|
||||
and then load the `webext/` directory as an unpacked extension.
|
||||
* https://developer.mozilla.org/en-US/docs/Tools/about:debugging#Loading_a_temporary_extension
|
||||
* https://developer.chrome.com/extensions/getstarted#manifest
|
||||
|
||||
### Testing
|
||||
|
||||
Unit testing with Jasmine are available with:
|
||||
```
|
||||
npm install
|
||||
npm test
|
||||
```
|
||||
|
||||
To run locally, start an http server in `build/` and navigate to `/embed.html`.
|
||||
|
||||
### Preparing to deploy
|
||||
|
||||
Background information:
|
||||
* https://bugs.torproject.org/23947#comment:8
|
||||
* https://help.torproject.org/tsa/doc/static-sites/
|
||||
* https://help.torproject.org/tsa/doc/ssh-jump-host/
|
||||
|
||||
You need to be in LDAP group "snowflake" and have set up an SSH key with your LDAP account.
|
||||
In your ~/.ssh/config file, you should have something like:
|
||||
|
||||
```
|
||||
Host staticiforme
|
||||
HostName staticiforme.torproject.org
|
||||
User <your user name>
|
||||
ProxyJump people.torproject.org
|
||||
IdentityFile ~/.ssh/tor
|
||||
```
|
||||
|
||||
### Deploying
|
||||
|
||||
```
|
||||
npm install
|
||||
npm run build
|
||||
```
|
||||
|
||||
Do a "dry run" rsync with `-n` to check that only expected files are being changed. If you don't understand why a file would be updated, you can add the `-i` option to see the reason.
|
||||
|
||||
```
|
||||
rsync -n --chown=:snowflake --chmod ug=rw,D+x --perms --delete -crv build/ staticiforme:/srv/snowflake.torproject.org/htdocs/
|
||||
```
|
||||
|
||||
If it looks good, then repeat the rsync without `-n`.
|
||||
|
||||
```
|
||||
rsync --chown=:snowflake --chmod ug=rw,D+x --perms --delete -crv build/ staticiforme:/srv/snowflake.torproject.org/htdocs/
|
||||
```
|
||||
|
||||
You can ignore errors of the form `rsync: failed to set permissions on "<dirname>/": Operation not permitted (1)`.
|
||||
|
||||
Then run the command to copy the new files to the live web servers:
|
||||
|
||||
```
|
||||
ssh staticiforme 'static-update-component snowflake.torproject.org'
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
With no parameters,
|
||||
snowflake uses the default relay `snowflake.freehaven.net:443` and
|
||||
uses automatic signaling with the default broker at
|
||||
`https://snowflake-broker.freehaven.net/`.
|
||||
|
||||
### Reuse as a library
|
||||
|
||||
The badge and the webextension make use of the same underlying library and
|
||||
only differ in their UI. That same library can be produced for use with other
|
||||
interfaces, such as [Cupcake][1], by running,
|
||||
|
||||
```
|
||||
npm install
|
||||
npm run library
|
||||
```
|
||||
|
||||
which outputs a `./snowflake-library.js`.
|
||||
|
||||
You'd then want to create a subclass of `UI` to perform various actions as
|
||||
the state of the snowflake changes,
|
||||
|
||||
```
|
||||
class MyUI extends UI {
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
See `WebExtUI` in `init-webext.js` and `BadgeUI` in `init-badge.js` for
|
||||
examples.
|
||||
|
||||
Finally, initialize the snowflake with,
|
||||
|
||||
```
|
||||
var log = function(msg) {
|
||||
return console.log('Snowflake: ' + msg);
|
||||
};
|
||||
var dbg = log;
|
||||
|
||||
var config = new Config("myui"); // NOTE: Set a unique proxy type for metrics
|
||||
var ui = new MyUI(); // NOTE: Using the class defined above
|
||||
var broker = new Broker(config.brokerUrl);
|
||||
|
||||
var snowflake = new Snowflake(config, ui, broker);
|
||||
|
||||
snowflake.setRelayAddr(config.relayAddr);
|
||||
snowflake.beginWebRTC();
|
||||
```
|
||||
|
||||
This minimal setup is pretty much what's currently in `init-node.js`.
|
||||
|
||||
When configuring the snowflake, set a unique `proxyType` (first argument
|
||||
to `Config`) that will be used when recording metrics at the broker. Also,
|
||||
it would be helpful to get in touch with the [Anti-Censorship Team][2] at the
|
||||
Tor Project to let them know about your tool.
|
||||
|
||||
[1]: https://chrome.google.com/webstore/detail/cupcake/dajjbehmbnbppjkcnpdkaniapgdppdnc
|
||||
[2]: https://trac.torproject.org/projects/tor/wiki/org/teams/AntiCensorshipTeam
|
134
proxy/broker.js
|
@ -1,134 +0,0 @@
|
|||
/* global log, dbg, snowflake */
|
||||
|
||||
/*
|
||||
Communication with the snowflake broker.
|
||||
|
||||
Browser snowflakes must register with the broker in order
|
||||
to get assigned to clients.
|
||||
*/
|
||||
|
||||
// Represents a broker running remotely.
|
||||
class Broker {
|
||||
|
||||
// When interacting with the Broker, snowflake must generate a unique session
|
||||
// ID so the Broker can keep track of each proxy's signalling channels.
|
||||
// On construction, this Broker object does not do anything until
|
||||
// |getClientOffer| is called.
|
||||
constructor(config) {
|
||||
this.getClientOffer = this.getClientOffer.bind(this);
|
||||
this._postRequest = this._postRequest.bind(this);
|
||||
|
||||
this.config = config
|
||||
this.url = config.brokerUrl;
|
||||
this.clients = 0;
|
||||
if (0 === this.url.indexOf('localhost', 0)) {
|
||||
// Ensure url has the right protocol + trailing slash.
|
||||
this.url = 'http://' + this.url;
|
||||
}
|
||||
if (0 !== this.url.indexOf('http', 0)) {
|
||||
this.url = 'https://' + this.url;
|
||||
}
|
||||
if ('/' !== this.url.substr(-1)) {
|
||||
this.url += '/';
|
||||
}
|
||||
}
|
||||
|
||||
// Promises some client SDP Offer.
|
||||
// Registers this Snowflake with the broker using an HTTP POST request, and
|
||||
// waits for a response containing some client offer that the Broker chooses
|
||||
// for this proxy..
|
||||
// TODO: Actually support multiple clients.
|
||||
getClientOffer(id) {
|
||||
return new Promise((fulfill, reject) => {
|
||||
var xhr;
|
||||
xhr = new XMLHttpRequest();
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.DONE !== xhr.readyState) {
|
||||
return;
|
||||
}
|
||||
switch (xhr.status) {
|
||||
case Broker.CODE.OK:
|
||||
var response = JSON.parse(xhr.responseText);
|
||||
if (response.Status == Broker.STATUS.MATCH) {
|
||||
return fulfill(response.Offer); // Should contain offer.
|
||||
} else if (response.Status == Broker.STATUS.TIMEOUT) {
|
||||
return reject(Broker.MESSAGE.TIMEOUT);
|
||||
} else {
|
||||
log('Broker ERROR: Unexpected ' + response.Status);
|
||||
return reject(Broker.MESSAGE.UNEXPECTED);
|
||||
}
|
||||
default:
|
||||
log('Broker ERROR: Unexpected ' + xhr.status + ' - ' + xhr.statusText);
|
||||
snowflake.ui.setStatus(' failure. Please refresh.');
|
||||
return reject(Broker.MESSAGE.UNEXPECTED);
|
||||
}
|
||||
};
|
||||
this._xhr = xhr; // Used by spec to fake async Broker interaction
|
||||
var data = {"Version": "1.1", "Sid": id, "Type": this.config.proxyType}
|
||||
return this._postRequest(xhr, 'proxy', JSON.stringify(data));
|
||||
});
|
||||
}
|
||||
|
||||
// Assumes getClientOffer happened, and a WebRTC SDP answer has been generated.
|
||||
// Sends it back to the broker, which passes it to back to the original client.
|
||||
sendAnswer(id, answer) {
|
||||
var xhr;
|
||||
dbg(id + ' - Sending answer back to broker...\n');
|
||||
dbg(answer.sdp);
|
||||
xhr = new XMLHttpRequest();
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.DONE !== xhr.readyState) {
|
||||
return;
|
||||
}
|
||||
switch (xhr.status) {
|
||||
case Broker.CODE.OK:
|
||||
dbg('Broker: Successfully replied with answer.');
|
||||
return dbg(xhr.responseText);
|
||||
default:
|
||||
dbg('Broker ERROR: Unexpected ' + xhr.status + ' - ' + xhr.statusText);
|
||||
return snowflake.ui.setStatus(' failure. Please refresh.');
|
||||
}
|
||||
};
|
||||
var data = {"Version": "1.0", "Sid": id, "Answer": JSON.stringify(answer)};
|
||||
return this._postRequest(xhr, 'answer', JSON.stringify(data));
|
||||
}
|
||||
|
||||
// urlSuffix for the broker is different depending on what action
|
||||
// is desired.
|
||||
_postRequest(xhr, urlSuffix, payload) {
|
||||
var err;
|
||||
try {
|
||||
xhr.open('POST', this.url + urlSuffix);
|
||||
} catch (error) {
|
||||
err = error;
|
||||
/*
|
||||
An exception happens here when, for example, NoScript allows the domain
|
||||
on which the proxy badge runs, but not the domain to which it's trying
|
||||
to make the HTTP xhr. The exception message is like "Component
|
||||
returned failure code: 0x805e0006 [nsIXMLHttpRequest.open]" on Firefox.
|
||||
*/
|
||||
log('Broker: exception while connecting: ' + err.message);
|
||||
return;
|
||||
}
|
||||
return xhr.send(payload);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Broker.CODE = {
|
||||
OK: 200,
|
||||
BAD_REQUEST: 400,
|
||||
INTERNAL_SERVER_ERROR: 500
|
||||
};
|
||||
|
||||
Broker.STATUS = {
|
||||
MATCH: "client match",
|
||||
TIMEOUT: "no match"
|
||||
};
|
||||
|
||||
Broker.MESSAGE = {
|
||||
TIMEOUT: 'Timed out waiting for a client offer.',
|
||||
UNEXPECTED: 'Unexpected status.'
|
||||
};
|
||||
|
||||
Broker.prototype.clients = 0;
|
|
@ -1,40 +0,0 @@
|
|||
|
||||
class Config {
|
||||
constructor(proxyType) {
|
||||
this.proxyType = proxyType || '';
|
||||
}
|
||||
}
|
||||
|
||||
Config.prototype.brokerUrl = 'snowflake-broker.freehaven.net';
|
||||
|
||||
Config.prototype.relayAddr = {
|
||||
host: 'snowflake.freehaven.net',
|
||||
port: '443'
|
||||
};
|
||||
|
||||
// Original non-wss relay:
|
||||
// host: '192.81.135.242'
|
||||
// port: 9902
|
||||
Config.prototype.cookieName = "snowflake-allow";
|
||||
|
||||
// Bytes per second. Set to undefined to disable limit.
|
||||
Config.prototype.rateLimitBytes = void 0;
|
||||
|
||||
Config.prototype.minRateLimit = 10 * 1024;
|
||||
|
||||
Config.prototype.rateLimitHistory = 5.0;
|
||||
|
||||
Config.prototype.defaultBrokerPollInterval = 300.0 * 1000;
|
||||
|
||||
Config.prototype.maxNumClients = 1;
|
||||
|
||||
Config.prototype.proxyType = "";
|
||||
|
||||
// TODO: Different ICE servers.
|
||||
Config.prototype.pcConfig = {
|
||||
iceServers: [
|
||||
{
|
||||
urls: ['stun:stun.l.google.com:19302']
|
||||
}
|
||||
]
|
||||
};
|
|
@ -1,223 +0,0 @@
|
|||
/* global Util, Params, Config, UI, Broker, Snowflake, Popup, Parse, availableLangs, WS */
|
||||
|
||||
/*
|
||||
UI
|
||||
*/
|
||||
|
||||
class Messages {
|
||||
constructor(json) {
|
||||
this.json = json;
|
||||
}
|
||||
getMessage(m, ...rest) {
|
||||
let message = this.json[m].message;
|
||||
return message.replace(/\$(\d+)/g, (...args) => {
|
||||
return rest[Number(args[1]) - 1];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
let messages = null;
|
||||
|
||||
class BadgeUI extends UI {
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.popup = new Popup();
|
||||
}
|
||||
|
||||
setStatus() {}
|
||||
|
||||
missingFeature(missing) {
|
||||
this.popup.setEnabled(false);
|
||||
this.popup.setActive(false);
|
||||
this.popup.setStatusText(messages.getMessage('popupStatusOff'));
|
||||
this.setIcon('off');
|
||||
this.popup.setStatusDesc(missing, true);
|
||||
this.popup.hideButton();
|
||||
}
|
||||
|
||||
turnOn() {
|
||||
const clients = this.active ? 1 : 0;
|
||||
this.popup.setChecked(true);
|
||||
if (clients > 0) {
|
||||
this.popup.setStatusText(messages.getMessage('popupStatusOn', String(clients)));
|
||||
this.setIcon('running');
|
||||
} else {
|
||||
this.popup.setStatusText(messages.getMessage('popupStatusReady'));
|
||||
this.setIcon('on');
|
||||
}
|
||||
// FIXME: Share stats from webext
|
||||
this.popup.setStatusDesc('');
|
||||
this.popup.setEnabled(true);
|
||||
this.popup.setActive(this.active);
|
||||
}
|
||||
|
||||
turnOff() {
|
||||
this.popup.setChecked(false);
|
||||
this.popup.setStatusText(messages.getMessage('popupStatusOff'));
|
||||
this.setIcon('off');
|
||||
this.popup.setStatusDesc('');
|
||||
this.popup.setEnabled(false);
|
||||
this.popup.setActive(false);
|
||||
}
|
||||
|
||||
setActive(connected) {
|
||||
super.setActive(connected);
|
||||
this.turnOn();
|
||||
}
|
||||
|
||||
setIcon(status) {
|
||||
document.getElementById('icon').href = `assets/toolbar-${status}.ico`;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
BadgeUI.prototype.popup = null;
|
||||
|
||||
|
||||
/*
|
||||
Entry point.
|
||||
*/
|
||||
|
||||
// Defaults to opt-in.
|
||||
var COOKIE_NAME = "snowflake-allow";
|
||||
var COOKIE_LIFETIME = "Thu, 01 Jan 2038 00:00:00 GMT";
|
||||
var COOKIE_EXPIRE = "Thu, 01 Jan 1970 00:00:01 GMT";
|
||||
|
||||
function setSnowflakeCookie(val, expires) {
|
||||
document.cookie = `${COOKIE_NAME}=${val}; path=/; expires=${expires};`;
|
||||
}
|
||||
|
||||
const defaultLang = 'en_US';
|
||||
|
||||
// Resolve as in,
|
||||
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Internationalization#Localized_string_selection
|
||||
function getLang() {
|
||||
let lang = navigator.language || defaultLang;
|
||||
lang = lang.replace(/-/g, '_');
|
||||
if (availableLangs.has(lang)) {
|
||||
return lang;
|
||||
}
|
||||
lang = lang.split('_')[0];
|
||||
if (availableLangs.has(lang)) {
|
||||
return lang;
|
||||
}
|
||||
return defaultLang;
|
||||
}
|
||||
|
||||
var debug, snowflake, config, broker, ui, log, dbg, init, update, silenceNotifications, query;
|
||||
|
||||
(function() {
|
||||
|
||||
snowflake = null;
|
||||
|
||||
query = new URLSearchParams(location.search);
|
||||
|
||||
debug = Params.getBool(query, 'debug', false);
|
||||
|
||||
silenceNotifications = Params.getBool(query, 'silent', false);
|
||||
|
||||
// Log to both console and UI if applicable.
|
||||
// Requires that the snowflake and UI objects are hooked up in order to
|
||||
// log to console.
|
||||
log = function(msg) {
|
||||
console.log('Snowflake: ' + msg);
|
||||
return snowflake != null ? snowflake.ui.log(msg) : void 0;
|
||||
};
|
||||
|
||||
dbg = function(msg) {
|
||||
if (debug) { log(msg); }
|
||||
};
|
||||
|
||||
update = function() {
|
||||
const cookies = Parse.cookie(document.cookie);
|
||||
if (cookies[COOKIE_NAME] !== '1') {
|
||||
ui.turnOff();
|
||||
snowflake.disable();
|
||||
log('Currently not active.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Util.hasWebRTC()) {
|
||||
ui.missingFeature(messages.getMessage('popupWebRTCOff'));
|
||||
snowflake.disable();
|
||||
return;
|
||||
}
|
||||
|
||||
WS.probeWebsocket(config.relayAddr)
|
||||
.then(
|
||||
() => {
|
||||
ui.turnOn();
|
||||
dbg('Contacting Broker at ' + broker.url);
|
||||
log('Starting snowflake');
|
||||
snowflake.setRelayAddr(config.relayAddr);
|
||||
snowflake.beginWebRTC();
|
||||
},
|
||||
() => {
|
||||
ui.missingFeature(messages.getMessage('popupBridgeUnreachable'));
|
||||
snowflake.disable();
|
||||
log('Could not connect to bridge.');
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
init = function() {
|
||||
ui = new BadgeUI();
|
||||
|
||||
if (!Util.hasCookies()) {
|
||||
ui.missingFeature(messages.getMessage('badgeCookiesOff'));
|
||||
return;
|
||||
}
|
||||
|
||||
config = new Config("badge");
|
||||
if ('off' !== query.get('ratelimit')) {
|
||||
config.rateLimitBytes = Params.getByteCount(query, 'ratelimit', config.rateLimitBytes);
|
||||
}
|
||||
broker = new Broker(config);
|
||||
snowflake = new Snowflake(config, ui, broker);
|
||||
log('== snowflake proxy ==');
|
||||
update();
|
||||
|
||||
document.getElementById('enabled').addEventListener('change', (event) => {
|
||||
if (event.target.checked) {
|
||||
setSnowflakeCookie('1', COOKIE_LIFETIME);
|
||||
} else {
|
||||
setSnowflakeCookie('', COOKIE_EXPIRE);
|
||||
}
|
||||
update();
|
||||
})
|
||||
};
|
||||
|
||||
// Notification of closing tab with active proxy.
|
||||
window.onbeforeunload = function() {
|
||||
if (
|
||||
!silenceNotifications &&
|
||||
snowflake !== null &&
|
||||
ui.active
|
||||
) {
|
||||
return Snowflake.MESSAGE.CONFIRMATION;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
window.onunload = function() {
|
||||
if (snowflake !== null) { snowflake.disable(); }
|
||||
return null;
|
||||
};
|
||||
|
||||
window.onload = function() {
|
||||
fetch(`./_locales/${getLang()}/messages.json`)
|
||||
.then((res) => {
|
||||
if (!res.ok) { return; }
|
||||
return res.json();
|
||||
})
|
||||
.then((json) => {
|
||||
messages = new Messages(json);
|
||||
Popup.fill(document.body, (m) => {
|
||||
return messages.getMessage(m);
|
||||
});
|
||||
init();
|
||||
});
|
||||
}
|
||||
|
||||
}());
|
|
@ -1,27 +0,0 @@
|
|||
/* global Config, UI, Broker, Snowflake */
|
||||
|
||||
/*
|
||||
Entry point.
|
||||
*/
|
||||
|
||||
var config = new Config("node");
|
||||
|
||||
var ui = new UI();
|
||||
|
||||
var broker = new Broker(config);
|
||||
|
||||
var snowflake = new Snowflake(config, ui, broker);
|
||||
|
||||
var log = function(msg) {
|
||||
return console.log('Snowflake: ' + msg);
|
||||
};
|
||||
|
||||
var dbg = log;
|
||||
|
||||
log('== snowflake proxy ==');
|
||||
|
||||
dbg('Contacting Broker at ' + broker.url);
|
||||
|
||||
snowflake.setRelayAddr(config.relayAddr);
|
||||
|
||||
snowflake.beginWebRTC();
|
|
@ -1,125 +0,0 @@
|
|||
/* global TESTING, Util, Params, Config, UI, Broker, Snowflake */
|
||||
|
||||
/*
|
||||
UI
|
||||
*/
|
||||
|
||||
class DebugUI extends UI {
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
// Setup other DOM handlers if it's debug mode.
|
||||
this.$status = document.getElementById('status');
|
||||
this.$msglog = document.getElementById('msglog');
|
||||
this.$msglog.value = '';
|
||||
}
|
||||
|
||||
// Status bar
|
||||
setStatus(msg) {
|
||||
var txt;
|
||||
txt = document.createTextNode('Status: ' + msg);
|
||||
while (this.$status.firstChild) {
|
||||
this.$status.removeChild(this.$status.firstChild);
|
||||
}
|
||||
return this.$status.appendChild(txt);
|
||||
}
|
||||
|
||||
setActive(connected) {
|
||||
super.setActive(connected);
|
||||
return this.$msglog.className = connected ? 'active' : '';
|
||||
}
|
||||
|
||||
log(msg) {
|
||||
// Scroll to latest
|
||||
this.$msglog.value += msg + '\n';
|
||||
return this.$msglog.scrollTop = this.$msglog.scrollHeight;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// DOM elements references.
|
||||
DebugUI.prototype.$msglog = null;
|
||||
|
||||
DebugUI.prototype.$status = null;
|
||||
|
||||
/*
|
||||
Entry point.
|
||||
*/
|
||||
|
||||
var snowflake, query, debug, ui, silenceNotifications, log, dbg, init;
|
||||
|
||||
(function() {
|
||||
|
||||
if (((typeof TESTING === "undefined" || TESTING === null) || !TESTING) && !Util.featureDetect()) {
|
||||
console.log('webrtc feature not detected. shutting down');
|
||||
return;
|
||||
}
|
||||
|
||||
snowflake = null;
|
||||
|
||||
query = new URLSearchParams(location.search);
|
||||
|
||||
debug = Params.getBool(query, 'debug', false);
|
||||
|
||||
silenceNotifications = Params.getBool(query, 'silent', false);
|
||||
|
||||
// Log to both console and UI if applicable.
|
||||
// Requires that the snowflake and UI objects are hooked up in order to
|
||||
// log to console.
|
||||
log = function(msg) {
|
||||
console.log('Snowflake: ' + msg);
|
||||
return snowflake != null ? snowflake.ui.log(msg) : void 0;
|
||||
};
|
||||
|
||||
dbg = function(msg) {
|
||||
if (debug || ((snowflake != null ? snowflake.ui : void 0) instanceof DebugUI)) {
|
||||
return log(msg);
|
||||
}
|
||||
};
|
||||
|
||||
init = function() {
|
||||
var broker, config, ui;
|
||||
config = new Config("testing");
|
||||
if ('off' !== query['ratelimit']) {
|
||||
config.rateLimitBytes = Params.getByteCount(query, 'ratelimit', config.rateLimitBytes);
|
||||
}
|
||||
ui = null;
|
||||
if (document.getElementById('status') !== null) {
|
||||
ui = new DebugUI();
|
||||
} else {
|
||||
ui = new UI();
|
||||
}
|
||||
broker = new Broker(config);
|
||||
snowflake = new Snowflake(config, ui, broker);
|
||||
log('== snowflake proxy ==');
|
||||
if (Util.snowflakeIsDisabled(config.cookieName)) {
|
||||
// Do not activate the proxy if any number of conditions are true.
|
||||
log('Currently not active.');
|
||||
return;
|
||||
}
|
||||
// Otherwise, begin setting up WebRTC and acting as a proxy.
|
||||
dbg('Contacting Broker at ' + broker.url);
|
||||
snowflake.setRelayAddr(config.relayAddr);
|
||||
return snowflake.beginWebRTC();
|
||||
};
|
||||
|
||||
// Notification of closing tab with active proxy.
|
||||
window.onbeforeunload = function() {
|
||||
if (
|
||||
!silenceNotifications &&
|
||||
snowflake !== null &&
|
||||
ui.active
|
||||
) {
|
||||
return Snowflake.MESSAGE.CONFIRMATION;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
window.onunload = function() {
|
||||
if (snowflake !== null) { snowflake.disable(); }
|
||||
return null;
|
||||
};
|
||||
|
||||
window.onload = init;
|
||||
|
||||
}());
|
|
@ -1,203 +0,0 @@
|
|||
/* global Util, chrome, Config, UI, Broker, Snowflake, WS */
|
||||
/* eslint no-unused-vars: 0 */
|
||||
|
||||
/*
|
||||
UI
|
||||
*/
|
||||
|
||||
class WebExtUI extends UI {
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.onConnect = this.onConnect.bind(this);
|
||||
this.onMessage = this.onMessage.bind(this);
|
||||
this.onDisconnect = this.onDisconnect.bind(this);
|
||||
this.initStats();
|
||||
chrome.runtime.onConnect.addListener(this.onConnect);
|
||||
}
|
||||
|
||||
initStats() {
|
||||
this.stats = [0];
|
||||
setInterval((() => {
|
||||
this.stats.unshift(0);
|
||||
this.stats.splice(24);
|
||||
this.postActive();
|
||||
}), 60 * 60 * 1000);
|
||||
}
|
||||
|
||||
initToggle() {
|
||||
// First, check if we have our status stored
|
||||
(new Promise((resolve) => {
|
||||
chrome.storage.local.get(["snowflake-enabled"], resolve);
|
||||
}))
|
||||
.then((result) => {
|
||||
let enabled = this.enabled;
|
||||
if (result['snowflake-enabled'] !== void 0) {
|
||||
enabled = result['snowflake-enabled'];
|
||||
} else {
|
||||
log("Toggle state not yet saved");
|
||||
}
|
||||
// If it isn't enabled, stop
|
||||
if (!enabled) {
|
||||
this.setEnabled(enabled);
|
||||
return;
|
||||
}
|
||||
// Otherwise, do feature checks
|
||||
if (!Util.hasWebRTC()) {
|
||||
this.missingFeature = 'popupWebRTCOff';
|
||||
this.setEnabled(false);
|
||||
return;
|
||||
}
|
||||
WS.probeWebsocket(config.relayAddr)
|
||||
.then(
|
||||
() => {
|
||||
this.setEnabled(true);
|
||||
},
|
||||
() => {
|
||||
log('Could not connect to bridge.');
|
||||
this.missingFeature = 'popupBridgeUnreachable';
|
||||
this.setEnabled(false);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
postActive() {
|
||||
this.setIcon();
|
||||
if (!this.port) { return; }
|
||||
this.port.postMessage({
|
||||
active: this.active,
|
||||
total: this.stats.reduce((function(t, c) {
|
||||
return t + c;
|
||||
}), 0),
|
||||
enabled: this.enabled,
|
||||
missingFeature: this.missingFeature,
|
||||
});
|
||||
}
|
||||
|
||||
onConnect(port) {
|
||||
this.port = port;
|
||||
port.onDisconnect.addListener(this.onDisconnect);
|
||||
port.onMessage.addListener(this.onMessage);
|
||||
this.postActive();
|
||||
}
|
||||
|
||||
onMessage(m) {
|
||||
(new Promise((resolve) => {
|
||||
chrome.storage.local.set({ "snowflake-enabled": m.enabled }, resolve);
|
||||
}))
|
||||
.then(() => {
|
||||
log("Stored toggle state");
|
||||
this.initToggle();
|
||||
});
|
||||
}
|
||||
|
||||
onDisconnect() {
|
||||
this.port = null;
|
||||
}
|
||||
|
||||
setActive(connected) {
|
||||
super.setActive(connected);
|
||||
if (connected) {
|
||||
this.stats[0] += 1;
|
||||
}
|
||||
this.postActive();
|
||||
}
|
||||
|
||||
setEnabled(enabled) {
|
||||
this.enabled = enabled;
|
||||
this.postActive();
|
||||
update();
|
||||
}
|
||||
|
||||
setIcon() {
|
||||
let path = null;
|
||||
if (!this.enabled) {
|
||||
path = {
|
||||
48: "assets/toolbar-off-48.png",
|
||||
96: "assets/toolbar-off-96.png"
|
||||
};
|
||||
} else if (this.active) {
|
||||
path = {
|
||||
48: "assets/toolbar-running-48.png",
|
||||
96: "assets/toolbar-running-96.png"
|
||||
};
|
||||
} else {
|
||||
path = {
|
||||
48: "assets/toolbar-on-48.png",
|
||||
96: "assets/toolbar-on-96.png"
|
||||
};
|
||||
}
|
||||
chrome.browserAction.setIcon({
|
||||
path: path,
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
WebExtUI.prototype.port = null;
|
||||
|
||||
WebExtUI.prototype.stats = null;
|
||||
|
||||
WebExtUI.prototype.enabled = true;
|
||||
|
||||
/*
|
||||
Entry point.
|
||||
*/
|
||||
|
||||
var debug, snowflake, config, broker, ui, log, dbg, init, update, silenceNotifications;
|
||||
|
||||
(function () {
|
||||
|
||||
silenceNotifications = false;
|
||||
debug = false;
|
||||
snowflake = null;
|
||||
config = null;
|
||||
broker = null;
|
||||
ui = null;
|
||||
|
||||
// Log to both console and UI if applicable.
|
||||
// Requires that the snowflake and UI objects are hooked up in order to
|
||||
// log to console.
|
||||
log = function(msg) {
|
||||
console.log('Snowflake: ' + msg);
|
||||
return snowflake != null ? snowflake.ui.log(msg) : void 0;
|
||||
};
|
||||
|
||||
dbg = function(msg) {
|
||||
if (debug) {
|
||||
return log(msg);
|
||||
}
|
||||
};
|
||||
|
||||
init = function() {
|
||||
config = new Config("webext");
|
||||
ui = new WebExtUI();
|
||||
broker = new Broker(config);
|
||||
snowflake = new Snowflake(config, ui, broker);
|
||||
log('== snowflake proxy ==');
|
||||
ui.initToggle();
|
||||
};
|
||||
|
||||
update = function() {
|
||||
if (!ui.enabled) {
|
||||
// Do not activate the proxy if any number of conditions are true.
|
||||
snowflake.disable();
|
||||
log('Currently not active.');
|
||||
return;
|
||||
}
|
||||
// Otherwise, begin setting up WebRTC and acting as a proxy.
|
||||
dbg('Contacting Broker at ' + broker.url);
|
||||
log('Starting snowflake');
|
||||
snowflake.setRelayAddr(config.relayAddr);
|
||||
return snowflake.beginWebRTC();
|
||||
};
|
||||
|
||||
window.onunload = function() {
|
||||
if (snowflake !== null) { snowflake.disable(); }
|
||||
return null;
|
||||
};
|
||||
|
||||
window.onload = init;
|
||||
|
||||
}());
|
201
proxy/make.js
|
@ -1,201 +0,0 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/* global require, process */
|
||||
|
||||
var { writeFileSync, readdirSync, statSync } = require('fs');
|
||||
var { execSync, spawn } = require('child_process');
|
||||
var cldr = require('cldr');
|
||||
|
||||
// All files required.
|
||||
var FILES = [
|
||||
'broker.js',
|
||||
'config.js',
|
||||
'proxypair.js',
|
||||
'snowflake.js',
|
||||
'ui.js',
|
||||
'util.js',
|
||||
'websocket.js',
|
||||
'shims.js'
|
||||
];
|
||||
|
||||
var FILES_SPEC = [
|
||||
'spec/broker.spec.js',
|
||||
'spec/init.spec.js',
|
||||
'spec/proxypair.spec.js',
|
||||
'spec/snowflake.spec.js',
|
||||
'spec/ui.spec.js',
|
||||
'spec/util.spec.js',
|
||||
'spec/websocket.spec.js'
|
||||
];
|
||||
|
||||
var STATIC = 'static';
|
||||
|
||||
var SHARED_FILES = [
|
||||
'embed.html',
|
||||
'embed.css',
|
||||
'popup.js',
|
||||
'assets',
|
||||
'_locales',
|
||||
];
|
||||
|
||||
var concatJS = function(outDir, init, outFile, pre) {
|
||||
var files = FILES;
|
||||
if (init) {
|
||||
files = files.concat(`init-${init}.js`);
|
||||
}
|
||||
var outPath = `${outDir}/${outFile}`;
|
||||
writeFileSync(outPath, pre, 'utf8');
|
||||
execSync(`cat ${files.join(' ')} >> ${outPath}`);
|
||||
};
|
||||
|
||||
var copyTranslations = function(outDir) {
|
||||
execSync('git submodule update --init -- translation')
|
||||
execSync(`cp -rf translation/* ${outDir}/_locales/`);
|
||||
};
|
||||
|
||||
var getDisplayName = function(locale) {
|
||||
var code = locale.split("_")[0];
|
||||
try {
|
||||
var name = cldr.extractLanguageDisplayNames(code)[code];
|
||||
}
|
||||
catch(e) {
|
||||
return '';
|
||||
}
|
||||
if (name === undefined) {
|
||||
return '';
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
var availableLangs = function() {
|
||||
let out = "const availableLangs = new Set([\n";
|
||||
let dirs = readdirSync('translation').filter((f) => {
|
||||
const s = statSync(`translation/${f}`);
|
||||
return s.isDirectory();
|
||||
});
|
||||
dirs.push('en_US');
|
||||
dirs.sort();
|
||||
dirs = dirs.map(d => ` '${d}',`);
|
||||
out += dirs.join("\n");
|
||||
out += "\n]);\n\n";
|
||||
return out;
|
||||
};
|
||||
|
||||
var translatedLangs = function() {
|
||||
let out = "const availableLangs = {\n";
|
||||
let dirs = readdirSync('translation').filter((f) => {
|
||||
const s = statSync(`translation/${f}`);
|
||||
return s.isDirectory();
|
||||
});
|
||||
dirs.push('en_US');
|
||||
dirs.sort();
|
||||
dirs = dirs.map(d => `'${d}': {"name": '${getDisplayName(d)}'},`);
|
||||
out += dirs.join("\n");
|
||||
out += "\n};\n\n";
|
||||
return out;
|
||||
};
|
||||
var tasks = new Map();
|
||||
|
||||
var task = function(key, msg, func) {
|
||||
tasks.set(key, {
|
||||
msg, func
|
||||
});
|
||||
};
|
||||
|
||||
task('test', 'snowflake unit tests', function() {
|
||||
var jasmineFiles, outFile, proc;
|
||||
execSync('mkdir -p test');
|
||||
execSync('jasmine init >&-');
|
||||
// Simply concat all the files because we're not using node exports.
|
||||
jasmineFiles = FILES.concat('init-testing.js', FILES_SPEC);
|
||||
outFile = 'test/bundle.spec.js';
|
||||
execSync('echo "TESTING = true" > ' + outFile);
|
||||
execSync('cat ' + jasmineFiles.join(' ') + ' | cat >> ' + outFile);
|
||||
proc = spawn('jasmine', ['test/bundle.spec.js'], {
|
||||
stdio: 'inherit'
|
||||
});
|
||||
proc.on("exit", function(code) {
|
||||
process.exit(code);
|
||||
});
|
||||
});
|
||||
|
||||
task('build', 'build the snowflake proxy', function() {
|
||||
const outDir = 'build';
|
||||
execSync(`rm -rf ${outDir}`);
|
||||
execSync(`cp -r ${STATIC}/ ${outDir}/`);
|
||||
copyTranslations(outDir);
|
||||
concatJS(outDir, 'badge', 'embed.js', availableLangs());
|
||||
writeFileSync(`${outDir}/index.js`, translatedLangs(), 'utf8');
|
||||
execSync(`cat ${STATIC}/index.js >> ${outDir}/index.js`);
|
||||
console.log('Snowflake prepared.');
|
||||
});
|
||||
|
||||
task('webext', 'build the webextension', function() {
|
||||
const outDir = 'webext';
|
||||
execSync(`git clean -f -x -d ${outDir}/`);
|
||||
execSync(`cp -r ${STATIC}/{${SHARED_FILES.join(',')}} ${outDir}/`, { shell: '/bin/bash' });
|
||||
copyTranslations(outDir);
|
||||
concatJS(outDir, 'webext', 'snowflake.js', '');
|
||||
console.log('Webextension prepared.');
|
||||
});
|
||||
|
||||
task('node', 'build the node binary', function() {
|
||||
execSync('mkdir -p build');
|
||||
concatJS('build', 'node', 'snowflake.js', '');
|
||||
console.log('Node prepared.');
|
||||
});
|
||||
|
||||
task('pack-webext', 'pack the webextension for deployment', function() {
|
||||
try {
|
||||
execSync(`rm -f source.zip`);
|
||||
execSync(`rm -f webext/webext.zip`);
|
||||
} catch (error) {
|
||||
//Usually this happens because the zip files were removed previously
|
||||
console.log('Error removing zip files');
|
||||
}
|
||||
execSync(`git submodule update --remote`);
|
||||
var version = process.argv[3];
|
||||
console.log(version);
|
||||
var manifest = require('./webext/manifest.json')
|
||||
manifest.version = version;
|
||||
writeFileSync('./webext/manifest.json', JSON.stringify(manifest, null, 2), 'utf8');
|
||||
execSync(`git commit -am "bump version to ${version}"`);
|
||||
try {
|
||||
execSync(`git tag webext-${version}`);
|
||||
} catch (error) {
|
||||
console.log('Error creating git tag');
|
||||
// Revert changes
|
||||
execSync(`git reset HEAD~`);
|
||||
execSync(`git checkout ./webext/manifest.json`);
|
||||
execSync(`git submodule update`);
|
||||
return;
|
||||
}
|
||||
execSync(`git archive -o source.zip HEAD .`);
|
||||
execSync(`npm run webext`);
|
||||
execSync(`cd webext && zip -Xr webext.zip ./*`);
|
||||
});
|
||||
|
||||
task('clean', 'remove all built files', function() {
|
||||
execSync('rm -rf build test spec/support');
|
||||
});
|
||||
|
||||
task('library', 'build the library', function() {
|
||||
concatJS('.', '', 'snowflake-library.js', '');
|
||||
console.log('Library prepared.');
|
||||
});
|
||||
|
||||
var cmd = process.argv[2];
|
||||
|
||||
if (tasks.has(cmd)) {
|
||||
var t = tasks.get(cmd);
|
||||
console.log(t.msg);
|
||||
t.func();
|
||||
} else {
|
||||
console.error('Command not supported.');
|
||||
|
||||
console.log('Commands:');
|
||||
|
||||
tasks.forEach(function(value, key) {
|
||||
console.log(key + ' - ' + value.msg);
|
||||
})
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
{
|
||||
"name": "snowflake-pt",
|
||||
"version": "0.0.0-git",
|
||||
"description": "Snowflake is a WebRTC pluggable transport for Tor.",
|
||||
"main": "build/snowflake.js",
|
||||
"directories": {
|
||||
"test": "test"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node make.js test",
|
||||
"build": "node make.js build",
|
||||
"webext": "node make.js webext",
|
||||
"library": "node make.js library",
|
||||
"pack-webext": "node make.js pack-webext",
|
||||
"clean": "node make.js clean",
|
||||
"prepublish": "node make.js node",
|
||||
"start": "node build/snowflake.js",
|
||||
"lint": "eslint . --ext .js"
|
||||
},
|
||||
"bin": {
|
||||
"snowflake": "build/snowflake.js"
|
||||
},
|
||||
"author": "Serene Han",
|
||||
"license": "BSD-3-Clause",
|
||||
"devDependencies": {
|
||||
"eslint": "^6.0.1",
|
||||
"jasmine": "2.5.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"cldr": "^5.4.1",
|
||||
"wrtc": "^0.0.61",
|
||||
"ws": "^3.3.1",
|
||||
"xmlhttprequest": "^1.8.0"
|
||||
}
|
||||
}
|
|
@ -1,249 +0,0 @@
|
|||
/* global snowflake, log, dbg, Util, PeerConnection, Parse, WS */
|
||||
|
||||
/*
|
||||
Represents a single:
|
||||
|
||||
client <-- webrtc --> snowflake <-- websocket --> relay
|
||||
|
||||
Every ProxyPair has a Snowflake ID, which is necessary when responding to the
|
||||
Broker with an WebRTC answer.
|
||||
*/
|
||||
|
||||
class ProxyPair {
|
||||
|
||||
/*
|
||||
Constructs a ProxyPair where:
|
||||
- @relayAddr is the destination relay
|
||||
- @rateLimit specifies a rate limit on traffic
|
||||
*/
|
||||
constructor(relayAddr, rateLimit, pcConfig) {
|
||||
this.prepareDataChannel = this.prepareDataChannel.bind(this);
|
||||
this.connectRelay = this.connectRelay.bind(this);
|
||||
this.onClientToRelayMessage = this.onClientToRelayMessage.bind(this);
|
||||
this.onRelayToClientMessage = this.onRelayToClientMessage.bind(this);
|
||||
this.onError = this.onError.bind(this);
|
||||
this.flush = this.flush.bind(this);
|
||||
|
||||
this.relayAddr = relayAddr;
|
||||
this.rateLimit = rateLimit;
|
||||
this.pcConfig = pcConfig;
|
||||
this.id = Util.genSnowflakeID();
|
||||
this.c2rSchedule = [];
|
||||
this.r2cSchedule = [];
|
||||
}
|
||||
|
||||
// Prepare a WebRTC PeerConnection and await for an SDP offer.
|
||||
begin() {
|
||||
this.pc = new PeerConnection(this.pcConfig, {
|
||||
optional: [
|
||||
{
|
||||
DtlsSrtpKeyAgreement: true
|
||||
},
|
||||
{
|
||||
RtpDataChannels: false
|
||||
}
|
||||
]
|
||||
});
|
||||
this.pc.onicecandidate = (evt) => {
|
||||
// Browser sends a null candidate once the ICE gathering completes.
|
||||
if (null === evt.candidate) {
|
||||
// TODO: Use a promise.all to tell Snowflake about all offers at once,
|
||||
// once multiple proxypairs are supported.
|
||||
dbg('Finished gathering ICE candidates.');
|
||||
return snowflake.broker.sendAnswer(this.id, this.pc.localDescription);
|
||||
}
|
||||
};
|
||||
// OnDataChannel triggered remotely from the client when connection succeeds.
|
||||
return this.pc.ondatachannel = (dc) => {
|
||||
var channel;
|
||||
channel = dc.channel;
|
||||
dbg('Data Channel established...');
|
||||
this.prepareDataChannel(channel);
|
||||
return this.client = channel;
|
||||
};
|
||||
}
|
||||
|
||||
receiveWebRTCOffer(offer) {
|
||||
if ('offer' !== offer.type) {
|
||||
log('Invalid SDP received -- was not an offer.');
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
this.pc.setRemoteDescription(offer);
|
||||
} catch (error) {
|
||||
log('Invalid SDP message.');
|
||||
return false;
|
||||
}
|
||||
dbg('SDP ' + offer.type + ' successfully received.');
|
||||
return true;
|
||||
}
|
||||
|
||||
// Given a WebRTC DataChannel, prepare callbacks.
|
||||
prepareDataChannel(channel) {
|
||||
channel.onopen = () => {
|
||||
log('WebRTC DataChannel opened!');
|
||||
snowflake.ui.setActive(true);
|
||||
// This is the point when the WebRTC datachannel is done, so the next step
|
||||
// is to establish websocket to the server.
|
||||
return this.connectRelay();
|
||||
};
|
||||
channel.onclose = () => {
|
||||
log('WebRTC DataChannel closed.');
|
||||
snowflake.ui.setStatus('disconnected by webrtc.');
|
||||
snowflake.ui.setActive(false);
|
||||
this.flush();
|
||||
return this.close();
|
||||
};
|
||||
channel.onerror = function() {
|
||||
return log('Data channel error!');
|
||||
};
|
||||
channel.binaryType = "arraybuffer";
|
||||
return channel.onmessage = this.onClientToRelayMessage;
|
||||
}
|
||||
|
||||
// Assumes WebRTC datachannel is connected.
|
||||
connectRelay() {
|
||||
var params, peer_ip, ref;
|
||||
dbg('Connecting to relay...');
|
||||
// Get a remote IP address from the PeerConnection, if possible. Add it to
|
||||
// the WebSocket URL's query string if available.
|
||||
// MDN marks remoteDescription as "experimental". However the other two
|
||||
// options, currentRemoteDescription and pendingRemoteDescription, which
|
||||
// are not marked experimental, were undefined when I tried them in Firefox
|
||||
// 52.2.0.
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/remoteDescription
|
||||
peer_ip = Parse.ipFromSDP((ref = this.pc.remoteDescription) != null ? ref.sdp : void 0);
|
||||
params = [];
|
||||
if (peer_ip != null) {
|
||||
params.push(["client_ip", peer_ip]);
|
||||
}
|
||||
var relay = this.relay = WS.makeWebsocket(this.relayAddr, params);
|
||||
this.relay.label = 'websocket-relay';
|
||||
this.relay.onopen = () => {
|
||||
if (this.timer) {
|
||||
clearTimeout(this.timer);
|
||||
this.timer = 0;
|
||||
}
|
||||
log(relay.label + ' connected!');
|
||||
return snowflake.ui.setStatus('connected');
|
||||
};
|
||||
this.relay.onclose = () => {
|
||||
log(relay.label + ' closed.');
|
||||
snowflake.ui.setStatus('disconnected.');
|
||||
snowflake.ui.setActive(false);
|
||||
this.flush();
|
||||
return this.close();
|
||||
};
|
||||
this.relay.onerror = this.onError;
|
||||
this.relay.onmessage = this.onRelayToClientMessage;
|
||||
// TODO: Better websocket timeout handling.
|
||||
return this.timer = setTimeout((() => {
|
||||
if (0 === this.timer) {
|
||||
return;
|
||||
}
|
||||
log(relay.label + ' timed out connecting.');
|
||||
return relay.onclose();
|
||||
}), 5000);
|
||||
}
|
||||
|
||||
// WebRTC --> websocket
|
||||
onClientToRelayMessage(msg) {
|
||||
dbg('WebRTC --> websocket data: ' + msg.data.byteLength + ' bytes');
|
||||
this.c2rSchedule.push(msg.data);
|
||||
return this.flush();
|
||||
}
|
||||
|
||||
// websocket --> WebRTC
|
||||
onRelayToClientMessage(event) {
|
||||
dbg('websocket --> WebRTC data: ' + event.data.byteLength + ' bytes');
|
||||
this.r2cSchedule.push(event.data);
|
||||
return this.flush();
|
||||
}
|
||||
|
||||
onError(event) {
|
||||
var ws;
|
||||
ws = event.target;
|
||||
log(ws.label + ' error.');
|
||||
return this.close();
|
||||
}
|
||||
|
||||
// Close both WebRTC and websocket.
|
||||
close() {
|
||||
if (this.timer) {
|
||||
clearTimeout(this.timer);
|
||||
this.timer = 0;
|
||||
}
|
||||
if (this.webrtcIsReady()) {
|
||||
this.client.close();
|
||||
}
|
||||
if (this.peerConnOpen()) {
|
||||
this.pc.close();
|
||||
}
|
||||
if (this.relayIsReady()) {
|
||||
this.relay.close();
|
||||
}
|
||||
this.onCleanup();
|
||||
}
|
||||
|
||||
// Send as much data in both directions as the rate limit currently allows.
|
||||
flush() {
|
||||
var busy, checkChunks;
|
||||
if (this.flush_timeout_id) {
|
||||
clearTimeout(this.flush_timeout_id);
|
||||
}
|
||||
this.flush_timeout_id = null;
|
||||
busy = true;
|
||||
checkChunks = () => {
|
||||
var chunk;
|
||||
busy = false;
|
||||
// WebRTC --> websocket
|
||||
if (this.relayIsReady() && this.relay.bufferedAmount < this.MAX_BUFFER && this.c2rSchedule.length > 0) {
|
||||
chunk = this.c2rSchedule.shift();
|
||||
this.rateLimit.update(chunk.byteLength);
|
||||
this.relay.send(chunk);
|
||||
busy = true;
|
||||
}
|
||||
// websocket --> WebRTC
|
||||
if (this.webrtcIsReady() && this.client.bufferedAmount < this.MAX_BUFFER && this.r2cSchedule.length > 0) {
|
||||
chunk = this.r2cSchedule.shift();
|
||||
this.rateLimit.update(chunk.byteLength);
|
||||
this.client.send(chunk);
|
||||
return busy = true;
|
||||
}
|
||||
};
|
||||
while (busy && !this.rateLimit.isLimited()) {
|
||||
checkChunks();
|
||||
}
|
||||
if (this.r2cSchedule.length > 0 || this.c2rSchedule.length > 0 || (this.relayIsReady() && this.relay.bufferedAmount > 0) || (this.webrtcIsReady() && this.client.bufferedAmount > 0)) {
|
||||
return this.flush_timeout_id = setTimeout(this.flush, this.rateLimit.when() * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
webrtcIsReady() {
|
||||
return null !== this.client && 'open' === this.client.readyState;
|
||||
}
|
||||
|
||||
relayIsReady() {
|
||||
return (null !== this.relay) && (WebSocket.OPEN === this.relay.readyState);
|
||||
}
|
||||
|
||||
isClosed(ws) {
|
||||
return void 0 === ws || WebSocket.CLOSED === ws.readyState;
|
||||
}
|
||||
|
||||
peerConnOpen() {
|
||||
return (null !== this.pc) && ('closed' !== this.pc.connectionState);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ProxyPair.prototype.MAX_BUFFER = 10 * 1024 * 1024;
|
||||
|
||||
ProxyPair.prototype.pc = null;
|
||||
ProxyPair.prototype.client = null; // WebRTC Data channel
|
||||
ProxyPair.prototype.relay = null; // websocket
|
||||
|
||||
ProxyPair.prototype.timer = 0;
|
||||
ProxyPair.prototype.flush_timeout_id = null;
|
||||
|
||||
ProxyPair.prototype.onCleanup = null;
|
|
@ -1,31 +0,0 @@
|
|||
/* global module, require */
|
||||
|
||||
/*
|
||||
WebRTC shims for multiple browsers.
|
||||
*/
|
||||
|
||||
if (typeof module !== "undefined" && module !== null ? module.exports : void 0) {
|
||||
window = {};
|
||||
document = {
|
||||
getElementById: function() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
chrome = {};
|
||||
location = { search: '' };
|
||||
({ URLSearchParams } = require('url'));
|
||||
if ((typeof TESTING === "undefined" || TESTING === null) || !TESTING) {
|
||||
webrtc = require('wrtc');
|
||||
PeerConnection = webrtc.RTCPeerConnection;
|
||||
IceCandidate = webrtc.RTCIceCandidate;
|
||||
SessionDescription = webrtc.RTCSessionDescription;
|
||||
WebSocket = require('ws');
|
||||
({ XMLHttpRequest } = require('xmlhttprequest'));
|
||||
}
|
||||
} else {
|
||||
PeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
|
||||
IceCandidate = window.RTCIceCandidate || window.mozRTCIceCandidate;
|
||||
SessionDescription = window.RTCSessionDescription || window.mozRTCSessionDescription;
|
||||
WebSocket = window.WebSocket;
|
||||
XMLHttpRequest = window.XMLHttpRequest;
|
||||
}
|
|
@ -1,165 +0,0 @@
|
|||
/* global log, dbg, DummyRateLimit, BucketRateLimit, SessionDescription, ProxyPair */
|
||||
|
||||
/*
|
||||
A JavaScript WebRTC snowflake proxy
|
||||
|
||||
Uses WebRTC from the client, and Websocket to the server.
|
||||
|
||||
Assume that the webrtc client plugin is always the offerer, in which case
|
||||
this proxy must always act as the answerer.
|
||||
|
||||
TODO: More documentation
|
||||
*/
|
||||
|
||||
// Minimum viable snowflake for now - just 1 client.
|
||||
class Snowflake {
|
||||
|
||||
// Prepare the Snowflake with a Broker (to find clients) and optional UI.
|
||||
constructor(config, ui, broker) {
|
||||
this.receiveOffer = this.receiveOffer.bind(this);
|
||||
|
||||
this.config = config;
|
||||
this.ui = ui;
|
||||
this.broker = broker;
|
||||
this.proxyPairs = [];
|
||||
if (void 0 === this.config.rateLimitBytes) {
|
||||
this.rateLimit = new DummyRateLimit();
|
||||
} else {
|
||||
this.rateLimit = new BucketRateLimit(this.config.rateLimitBytes * this.config.rateLimitHistory, this.config.rateLimitHistory);
|
||||
}
|
||||
this.retries = 0;
|
||||
}
|
||||
|
||||
// Set the target relay address spec, which is expected to be websocket.
|
||||
// TODO: Should potentially fetch the target from broker later, or modify
|
||||
// entirely for the Tor-independent version.
|
||||
setRelayAddr(relayAddr) {
|
||||
this.relayAddr = relayAddr;
|
||||
log('Using ' + relayAddr.host + ':' + relayAddr.port + ' as Relay.');
|
||||
return true;
|
||||
}
|
||||
|
||||
// Initialize WebRTC PeerConnection, which requires beginning the signalling
|
||||
// process. |pollBroker| automatically arranges signalling.
|
||||
beginWebRTC() {
|
||||
this.pollBroker();
|
||||
return this.pollInterval = setInterval((() => {
|
||||
return this.pollBroker();
|
||||
}), this.config.defaultBrokerPollInterval);
|
||||
}
|
||||
|
||||
// Regularly poll Broker for clients to serve until this snowflake is
|
||||
// serving at capacity, at which point stop polling.
|
||||
pollBroker() {
|
||||
var msg, pair, recv;
|
||||
// Poll broker for clients.
|
||||
pair = this.makeProxyPair();
|
||||
if (!pair) {
|
||||
log('At client capacity.');
|
||||
return;
|
||||
}
|
||||
log('Polling broker..');
|
||||
// Do nothing until a new proxyPair is available.
|
||||
msg = 'Polling for client ... ';
|
||||
if (this.retries > 0) {
|
||||
msg += '[retries: ' + this.retries + ']';
|
||||
}
|
||||
this.ui.setStatus(msg);
|
||||
recv = this.broker.getClientOffer(pair.id);
|
||||
recv.then((desc) => {
|
||||
if (!this.receiveOffer(pair, desc)) {
|
||||
return pair.close();
|
||||
}
|
||||
//set a timeout for channel creation
|
||||
return setTimeout((() => {
|
||||
if (!pair.webrtcIsReady()) {
|
||||
log('proxypair datachannel timed out waiting for open');
|
||||
return pair.close();
|
||||
}
|
||||
}), 20000); // 20 second timeout
|
||||
}, function() {
|
||||
//on error, close proxy pair
|
||||
return pair.close();
|
||||
});
|
||||
return this.retries++;
|
||||
}
|
||||
|
||||
// Receive an SDP offer from some client assigned by the Broker,
|
||||
// |pair| - an available ProxyPair.
|
||||
receiveOffer(pair, desc) {
|
||||
var e, offer, sdp;
|
||||
try {
|
||||
offer = JSON.parse(desc);
|
||||
dbg('Received:\n\n' + offer.sdp + '\n');
|
||||
sdp = new SessionDescription(offer);
|
||||
if (pair.receiveWebRTCOffer(sdp)) {
|
||||
this.sendAnswer(pair);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
e = error;
|
||||
log('ERROR: Unable to receive Offer: ' + e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
sendAnswer(pair) {
|
||||
var fail, next;
|
||||
next = function(sdp) {
|
||||
dbg('webrtc: Answer ready.');
|
||||
return pair.pc.setLocalDescription(sdp).catch(fail);
|
||||
};
|
||||
fail = function() {
|
||||
pair.close();
|
||||
return dbg('webrtc: Failed to create or set Answer');
|
||||
};
|
||||
return pair.pc.createAnswer().then(next).catch(fail);
|
||||
}
|
||||
|
||||
makeProxyPair() {
|
||||
if (this.proxyPairs.length >= this.config.maxNumClients) {
|
||||
return null;
|
||||
}
|
||||
var pair;
|
||||
pair = new ProxyPair(this.relayAddr, this.rateLimit, this.config.pcConfig);
|
||||
this.proxyPairs.push(pair);
|
||||
|
||||
log('Snowflake IDs: ' + (this.proxyPairs.map(function(p) {
|
||||
return p.id;
|
||||
})).join(' | '));
|
||||
|
||||
pair.onCleanup = () => {
|
||||
var ind;
|
||||
// Delete from the list of proxy pairs.
|
||||
ind = this.proxyPairs.indexOf(pair);
|
||||
if (ind > -1) {
|
||||
return this.proxyPairs.splice(ind, 1);
|
||||
}
|
||||
};
|
||||
pair.begin();
|
||||
return pair;
|
||||
}
|
||||
|
||||
// Stop all proxypairs.
|
||||
disable() {
|
||||
var results;
|
||||
log('Disabling Snowflake.');
|
||||
clearInterval(this.pollInterval);
|
||||
results = [];
|
||||
while (this.proxyPairs.length > 0) {
|
||||
results.push(this.proxyPairs.pop().close());
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Snowflake.prototype.relayAddr = null;
|
||||
Snowflake.prototype.rateLimit = null;
|
||||
Snowflake.prototype.pollInterval = null;
|
||||
|
||||
Snowflake.MESSAGE = {
|
||||
CONFIRMATION: 'You\'re currently serving a Tor user via Snowflake.'
|
||||
};
|
|
@ -1,131 +0,0 @@
|
|||
/* global expect, it, describe, spyOn, Broker */
|
||||
|
||||
/*
|
||||
jasmine tests for Snowflake broker
|
||||
*/
|
||||
|
||||
// fake xhr
|
||||
// class XMLHttpRequest
|
||||
class XMLHttpRequest {
|
||||
constructor() {
|
||||
this.onreadystatechange = null;
|
||||
}
|
||||
open() {}
|
||||
setRequestHeader() {}
|
||||
send() {}
|
||||
};
|
||||
|
||||
XMLHttpRequest.prototype.DONE = 1;
|
||||
|
||||
|
||||
describe('Broker', function() {
|
||||
|
||||
it('can be created', function() {
|
||||
var b;
|
||||
var config = new Config;
|
||||
config.brokerUrl = 'fake';
|
||||
b = new Broker(config);
|
||||
expect(b.url).toEqual('https://fake/');
|
||||
expect(b.id).not.toBeNull();
|
||||
});
|
||||
|
||||
describe('getClientOffer', function() {
|
||||
|
||||
it('polls and promises a client offer', function(done) {
|
||||
var b, poll;
|
||||
var config = new Config;
|
||||
config.brokerUrl = 'fake';
|
||||
b = new Broker(config);
|
||||
// fake successful request and response from broker.
|
||||
spyOn(b, '_postRequest').and.callFake(function() {
|
||||
b._xhr.readyState = b._xhr.DONE;
|
||||
b._xhr.status = Broker.CODE.OK;
|
||||
b._xhr.responseText = '{"Status":"client match","Offer":"fake offer"}';
|
||||
return b._xhr.onreadystatechange();
|
||||
});
|
||||
poll = b.getClientOffer();
|
||||
expect(poll).not.toBeNull();
|
||||
expect(b._postRequest).toHaveBeenCalled();
|
||||
return poll.then(function(desc) {
|
||||
expect(desc).toEqual('fake offer');
|
||||
return done();
|
||||
}).catch(function() {
|
||||
fail('should not reject on Broker.CODE.OK');
|
||||
return done();
|
||||
});
|
||||
});
|
||||
|
||||
it('rejects if the broker timed-out', function(done) {
|
||||
var b, poll;
|
||||
var config = new Config;
|
||||
config.brokerUrl = 'fake';
|
||||
b = new Broker(config);
|
||||
// fake timed-out request from broker
|
||||
spyOn(b, '_postRequest').and.callFake(function() {
|
||||
b._xhr.readyState = b._xhr.DONE;
|
||||
b._xhr.status = Broker.CODE.OK;
|
||||
b._xhr.responseText = '{"Status":"no match"}';
|
||||
return b._xhr.onreadystatechange();
|
||||
});
|
||||
poll = b.getClientOffer();
|
||||
expect(poll).not.toBeNull();
|
||||
expect(b._postRequest).toHaveBeenCalled();
|
||||
return poll.then(function(desc) {
|
||||
fail('should not fulfill with "Status: no match"');
|
||||
return done();
|
||||
}, function(err) {
|
||||
expect(err).toBe(Broker.MESSAGE.TIMEOUT);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
|
||||
it('rejects on any other status', function(done) {
|
||||
var b, poll;
|
||||
var config = new Config;
|
||||
config.brokerUrl = 'fake';
|
||||
b = new Broker(config);
|
||||
// fake timed-out request from broker
|
||||
spyOn(b, '_postRequest').and.callFake(function() {
|
||||
b._xhr.readyState = b._xhr.DONE;
|
||||
b._xhr.status = 1337;
|
||||
return b._xhr.onreadystatechange();
|
||||
});
|
||||
poll = b.getClientOffer();
|
||||
expect(poll).not.toBeNull();
|
||||
expect(b._postRequest).toHaveBeenCalled();
|
||||
return poll.then(function(desc) {
|
||||
fail('should not fulfill on non-OK status');
|
||||
return done();
|
||||
}, function(err) {
|
||||
expect(err).toBe(Broker.MESSAGE.UNEXPECTED);
|
||||
expect(b._xhr.status).toBe(1337);
|
||||
return done();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('responds to the broker with answer', function() {
|
||||
var config = new Config;
|
||||
config.brokerUrl = 'fake';
|
||||
var b = new Broker(config);
|
||||
spyOn(b, '_postRequest');
|
||||
b.sendAnswer('fake id', 123);
|
||||
expect(b._postRequest).toHaveBeenCalledWith(jasmine.any(Object), 'answer', '{"Version":"1.0","Sid":"fake id","Answer":"123"}');
|
||||
});
|
||||
|
||||
it('POST XMLHttpRequests to the broker', function() {
|
||||
var config = new Config;
|
||||
config.brokerUrl = 'fake';
|
||||
var b = new Broker(config);
|
||||
b._xhr = new XMLHttpRequest();
|
||||
spyOn(b._xhr, 'open');
|
||||
spyOn(b._xhr, 'setRequestHeader');
|
||||
spyOn(b._xhr, 'send');
|
||||
b._postRequest(b._xhr, 'test', 'data');
|
||||
expect(b._xhr.open).toHaveBeenCalled();
|
||||
expect(b._xhr.send).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
});
|
|
@ -1,34 +0,0 @@
|
|||
/* global expect, it, describe, Snowflake, UI */
|
||||
|
||||
// Fake snowflake to interact with
|
||||
|
||||
var snowflake = {
|
||||
ui: new UI,
|
||||
broker: {
|
||||
sendAnswer: function() {}
|
||||
}
|
||||
};
|
||||
|
||||
describe('Init', function() {
|
||||
|
||||
it('gives a dialog when closing, only while active', function() {
|
||||
silenceNotifications = false;
|
||||
ui.setActive(true);
|
||||
var msg = window.onbeforeunload();
|
||||
expect(ui.active).toBe(true);
|
||||
expect(msg).toBe(Snowflake.MESSAGE.CONFIRMATION);
|
||||
ui.setActive(false);
|
||||
msg = window.onbeforeunload();
|
||||
expect(ui.active).toBe(false);
|
||||
expect(msg).toBe(null);
|
||||
});
|
||||
|
||||
it('does not give a dialog when silent flag is on', function() {
|
||||
silenceNotifications = true;
|
||||
ui.setActive(true);
|
||||
var msg = window.onbeforeunload();
|
||||
expect(ui.active).toBe(true);
|
||||
expect(msg).toBe(null);
|
||||
});
|
||||
|
||||
});
|
|
@ -1,163 +0,0 @@
|
|||
/* global expect, it, describe, spyOn */
|
||||
|
||||
/*
|
||||
jasmine tests for Snowflake proxypair
|
||||
*/
|
||||
|
||||
// Replacement for MessageEvent constructor.
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent/MessageEvent
|
||||
var MessageEvent = function(type, init) {
|
||||
return init;
|
||||
};
|
||||
|
||||
// Asymmetic matcher that checks that two arrays have the same contents.
|
||||
var arrayMatching = function(sample) {
|
||||
return {
|
||||
asymmetricMatch: function(other) {
|
||||
var _, a, b, i, j, len;
|
||||
a = new Uint8Array(sample);
|
||||
b = new Uint8Array(other);
|
||||
if (a.length !== b.length) {
|
||||
return false;
|
||||
}
|
||||
for (i = j = 0, len = a.length; j < len; i = ++j) {
|
||||
_ = a[i];
|
||||
if (a[i] !== b[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
},
|
||||
jasmineToString: function() {
|
||||
return '<arrayMatchine(' + jasmine.pp(sample) + ')>';
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
describe('ProxyPair', function() {
|
||||
|
||||
var config, destination, fakeRelay, pp, rateLimit;
|
||||
fakeRelay = Parse.address('0.0.0.0:12345');
|
||||
rateLimit = new DummyRateLimit;
|
||||
config = new Config;
|
||||
destination = [];
|
||||
|
||||
// Using the mock PeerConnection definition from spec/snowflake.spec.js
|
||||
var pp = new ProxyPair(fakeRelay, rateLimit, config.pcConfig);
|
||||
|
||||
beforeEach(function() {
|
||||
return pp.begin();
|
||||
});
|
||||
|
||||
it('begins webrtc connection', function() {
|
||||
return expect(pp.pc).not.toBeNull();
|
||||
});
|
||||
|
||||
describe('accepts WebRTC offer from some client', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
return pp.begin();
|
||||
});
|
||||
|
||||
it('rejects invalid offers', function() {
|
||||
expect(typeof pp.pc.setRemoteDescription).toBe("function");
|
||||
expect(pp.pc).not.toBeNull();
|
||||
expect(pp.receiveWebRTCOffer({})).toBe(false);
|
||||
expect(pp.receiveWebRTCOffer({
|
||||
type: 'answer'
|
||||
})).toBe(false);
|
||||
});
|
||||
|
||||
it('accepts valid offers', function() {
|
||||
expect(pp.pc).not.toBeNull();
|
||||
expect(pp.receiveWebRTCOffer({
|
||||
type: 'offer',
|
||||
sdp: 'foo'
|
||||
})).toBe(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('responds with a WebRTC answer correctly', function() {
|
||||
spyOn(snowflake.broker, 'sendAnswer');
|
||||
pp.pc.onicecandidate({
|
||||
candidate: null
|
||||
});
|
||||
expect(snowflake.broker.sendAnswer).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('handles a new data channel correctly', function() {
|
||||
expect(pp.client).toBeNull();
|
||||
pp.pc.ondatachannel({
|
||||
channel: {}
|
||||
});
|
||||
expect(pp.client).not.toBeNull();
|
||||
expect(pp.client.onopen).not.toBeNull();
|
||||
expect(pp.client.onclose).not.toBeNull();
|
||||
expect(pp.client.onerror).not.toBeNull();
|
||||
expect(pp.client.onmessage).not.toBeNull();
|
||||
});
|
||||
|
||||
it('connects to the relay once datachannel opens', function() {
|
||||
spyOn(pp, 'connectRelay');
|
||||
pp.active = true;
|
||||
pp.client.onopen();
|
||||
expect(pp.connectRelay).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('connects to a relay', function() {
|
||||
pp.connectRelay();
|
||||
expect(pp.relay.onopen).not.toBeNull();
|
||||
expect(pp.relay.onclose).not.toBeNull();
|
||||
expect(pp.relay.onerror).not.toBeNull();
|
||||
expect(pp.relay.onmessage).not.toBeNull();
|
||||
});
|
||||
|
||||
describe('flushes data between client and relay', function() {
|
||||
|
||||
it('proxies data from client to relay', function() {
|
||||
var msg;
|
||||
pp.pc.ondatachannel({
|
||||
channel: {
|
||||
bufferedAmount: 0,
|
||||
readyState: "open",
|
||||
send: function(data) {}
|
||||
}
|
||||
});
|
||||
spyOn(pp.client, 'send');
|
||||
spyOn(pp.relay, 'send');
|
||||
msg = new MessageEvent("message", {
|
||||
data: Uint8Array.from([1, 2, 3]).buffer
|
||||
});
|
||||
pp.onClientToRelayMessage(msg);
|
||||
pp.flush();
|
||||
expect(pp.client.send).not.toHaveBeenCalled();
|
||||
expect(pp.relay.send).toHaveBeenCalledWith(arrayMatching([1, 2, 3]));
|
||||
});
|
||||
|
||||
it('proxies data from relay to client', function() {
|
||||
var msg;
|
||||
spyOn(pp.client, 'send');
|
||||
spyOn(pp.relay, 'send');
|
||||
msg = new MessageEvent("message", {
|
||||
data: Uint8Array.from([4, 5, 6]).buffer
|
||||
});
|
||||
pp.onRelayToClientMessage(msg);
|
||||
pp.flush();
|
||||
expect(pp.client.send).toHaveBeenCalledWith(arrayMatching([4, 5, 6]));
|
||||
expect(pp.relay.send).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('sends nothing with nothing to flush', function() {
|
||||
spyOn(pp.client, 'send');
|
||||
spyOn(pp.relay, 'send');
|
||||
pp.flush();
|
||||
expect(pp.client.send).not.toHaveBeenCalled();
|
||||
expect(pp.relay.send).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
// TODO: rate limit tests
|
|
@ -1,103 +0,0 @@
|
|||
/* global expect, it, describe, spyOn, Snowflake, Config, UI */
|
||||
|
||||
/*
|
||||
jasmine tests for Snowflake
|
||||
*/
|
||||
|
||||
// Fake browser functionality:
|
||||
class PeerConnection {
|
||||
setRemoteDescription() {
|
||||
return true;
|
||||
}
|
||||
send() {}
|
||||
}
|
||||
|
||||
class SessionDescription {}
|
||||
SessionDescription.prototype.type = 'offer';
|
||||
|
||||
class WebSocket {
|
||||
constructor() {
|
||||
this.bufferedAmount = 0;
|
||||
}
|
||||
send() {}
|
||||
}
|
||||
WebSocket.prototype.OPEN = 1;
|
||||
WebSocket.prototype.CLOSED = 0;
|
||||
|
||||
var log = function() {};
|
||||
|
||||
var config = new Config();
|
||||
|
||||
var ui = new UI();
|
||||
|
||||
class FakeBroker {
|
||||
getClientOffer() {
|
||||
return new Promise(function() {
|
||||
return {};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
describe('Snowflake', function() {
|
||||
|
||||
it('constructs correctly', function() {
|
||||
var s;
|
||||
s = new Snowflake(config, ui, {
|
||||
fake: 'broker'
|
||||
});
|
||||
expect(s.rateLimit).not.toBeNull();
|
||||
expect(s.broker).toEqual({
|
||||
fake: 'broker'
|
||||
});
|
||||
expect(s.ui).not.toBeNull();
|
||||
expect(s.retries).toBe(0);
|
||||
});
|
||||
|
||||
it('sets relay address correctly', function() {
|
||||
var s;
|
||||
s = new Snowflake(config, ui, null);
|
||||
s.setRelayAddr('foo');
|
||||
expect(s.relayAddr).toEqual('foo');
|
||||
});
|
||||
|
||||
it('initalizes WebRTC connection', function() {
|
||||
var s;
|
||||
s = new Snowflake(config, ui, new FakeBroker());
|
||||
spyOn(s.broker, 'getClientOffer').and.callThrough();
|
||||
s.beginWebRTC();
|
||||
expect(s.retries).toBe(1);
|
||||
expect(s.broker.getClientOffer).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('receives SDP offer and sends answer', function() {
|
||||
var pair, s;
|
||||
s = new Snowflake(config, ui, new FakeBroker());
|
||||
pair = {
|
||||
receiveWebRTCOffer: function() {}
|
||||
};
|
||||
spyOn(pair, 'receiveWebRTCOffer').and.returnValue(true);
|
||||
spyOn(s, 'sendAnswer');
|
||||
s.receiveOffer(pair, '{"type":"offer","sdp":"foo"}');
|
||||
expect(s.sendAnswer).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('does not send answer when receiving invalid offer', function() {
|
||||
var pair, s;
|
||||
s = new Snowflake(config, ui, new FakeBroker());
|
||||
pair = {
|
||||
receiveWebRTCOffer: function() {}
|
||||
};
|
||||
spyOn(pair, 'receiveWebRTCOffer').and.returnValue(false);
|
||||
spyOn(s, 'sendAnswer');
|
||||
s.receiveOffer(pair, '{"type":"not a good offer","sdp":"foo"}');
|
||||
expect(s.sendAnswer).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('can make a proxypair', function() {
|
||||
var s;
|
||||
s = new Snowflake(config, ui, new FakeBroker());
|
||||
s.makeProxyPair();
|
||||
expect(s.proxyPairs.length).toBe(1);
|
||||
});
|
||||
|
||||
});
|
|
@ -1,68 +0,0 @@
|
|||
/* global expect, it, describe, spyOn, DebugUI */
|
||||
/* eslint no-redeclare: 0 */
|
||||
|
||||
/*
|
||||
jasmine tests for Snowflake UI
|
||||
*/
|
||||
|
||||
var document = {
|
||||
getElementById: function() {
|
||||
return {};
|
||||
},
|
||||
createTextNode: function(txt) {
|
||||
return txt;
|
||||
}
|
||||
};
|
||||
|
||||
describe('UI', function() {
|
||||
|
||||
it('activates debug mode when badge does not exist', function() {
|
||||
var u;
|
||||
spyOn(document, 'getElementById').and.callFake(function(id) {
|
||||
if ('badge' === id) {
|
||||
return null;
|
||||
}
|
||||
return {};
|
||||
});
|
||||
u = new DebugUI();
|
||||
expect(document.getElementById.calls.count()).toEqual(2);
|
||||
expect(u.$status).not.toBeNull();
|
||||
expect(u.$msglog).not.toBeNull();
|
||||
});
|
||||
|
||||
it('sets status message when in debug mode', function() {
|
||||
var u;
|
||||
u = new DebugUI();
|
||||
u.$status = {
|
||||
innerHTML: '',
|
||||
appendChild: function(txt) {
|
||||
return this.innerHTML = txt;
|
||||
}
|
||||
};
|
||||
u.setStatus('test');
|
||||
expect(u.$status.innerHTML).toEqual('Status: test');
|
||||
});
|
||||
|
||||
it('sets message log css correctly for debug mode', function() {
|
||||
var u;
|
||||
u = new DebugUI();
|
||||
u.setActive(true);
|
||||
expect(u.$msglog.className).toEqual('active');
|
||||
u.setActive(false);
|
||||
expect(u.$msglog.className).toEqual('');
|
||||
});
|
||||
|
||||
it('logs to the textarea correctly when debug mode', function() {
|
||||
var u;
|
||||
u = new DebugUI();
|
||||
u.$msglog = {
|
||||
value: '',
|
||||
scrollTop: 0,
|
||||
scrollHeight: 1337
|
||||
};
|
||||
u.log('test');
|
||||
expect(u.$msglog.value).toEqual('test\n');
|
||||
expect(u.$msglog.scrollTop).toEqual(1337);
|
||||
});
|
||||
|
||||
});
|
|
@ -1,252 +0,0 @@
|
|||
/* global expect, it, describe, Parse, Params */
|
||||
|
||||
/*
|
||||
jasmine tests for Snowflake utils
|
||||
*/
|
||||
|
||||
describe('Parse', function() {
|
||||
|
||||
describe('cookie', function() {
|
||||
|
||||
it('parses correctly', function() {
|
||||
expect(Parse.cookie('')).toEqual({});
|
||||
expect(Parse.cookie('a=b')).toEqual({
|
||||
a: 'b'
|
||||
});
|
||||
expect(Parse.cookie('a=b=c')).toEqual({
|
||||
a: 'b=c'
|
||||
});
|
||||
expect(Parse.cookie('a=b; c=d')).toEqual({
|
||||
a: 'b',
|
||||
c: 'd'
|
||||
});
|
||||
expect(Parse.cookie('a=b ; c=d')).toEqual({
|
||||
a: 'b',
|
||||
c: 'd'
|
||||
});
|
||||
expect(Parse.cookie('a= b')).toEqual({
|
||||
a: 'b'
|
||||
});
|
||||
expect(Parse.cookie('a=')).toEqual({
|
||||
a: ''
|
||||
});
|
||||
expect(Parse.cookie('key')).toBeNull();
|
||||
expect(Parse.cookie('key=%26%20')).toEqual({
|
||||
key: '& '
|
||||
});
|
||||
expect(Parse.cookie('a=\'\'')).toEqual({
|
||||
a: '\'\''
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('address', function() {
|
||||
|
||||
it('parses IPv4', function() {
|
||||
expect(Parse.address('')).toBeNull();
|
||||
expect(Parse.address('3.3.3.3:4444')).toEqual({
|
||||
host: '3.3.3.3',
|
||||
port: 4444
|
||||
});
|
||||
expect(Parse.address('3.3.3.3')).toBeNull();
|
||||
expect(Parse.address('3.3.3.3:0x1111')).toBeNull();
|
||||
expect(Parse.address('3.3.3.3:-4444')).toBeNull();
|
||||
expect(Parse.address('3.3.3.3:65536')).toBeNull();
|
||||
});
|
||||
|
||||
it('parses IPv6', function() {
|
||||
expect(Parse.address('[1:2::a:f]:4444')).toEqual({
|
||||
host: '1:2::a:f',
|
||||
port: 4444
|
||||
});
|
||||
expect(Parse.address('[1:2::a:f]')).toBeNull();
|
||||
expect(Parse.address('[1:2::a:f]:0x1111')).toBeNull();
|
||||
expect(Parse.address('[1:2::a:f]:-4444')).toBeNull();
|
||||
expect(Parse.address('[1:2::a:f]:65536')).toBeNull();
|
||||
expect(Parse.address('[1:2::ffff:1.2.3.4]:4444')).toEqual({
|
||||
host: '1:2::ffff:1.2.3.4',
|
||||
port: 4444
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('byte count', function() {
|
||||
|
||||
it('returns null for bad inputs', function() {
|
||||
expect(Parse.byteCount("")).toBeNull();
|
||||
expect(Parse.byteCount("x")).toBeNull();
|
||||
expect(Parse.byteCount("1x")).toBeNull();
|
||||
expect(Parse.byteCount("1.x")).toBeNull();
|
||||
expect(Parse.byteCount("1.2x")).toBeNull();
|
||||
expect(Parse.byteCount("toString")).toBeNull();
|
||||
expect(Parse.byteCount("1toString")).toBeNull();
|
||||
expect(Parse.byteCount("1.toString")).toBeNull();
|
||||
expect(Parse.byteCount("1.2toString")).toBeNull();
|
||||
expect(Parse.byteCount("k")).toBeNull();
|
||||
expect(Parse.byteCount("m")).toBeNull();
|
||||
expect(Parse.byteCount("g")).toBeNull();
|
||||
expect(Parse.byteCount("K")).toBeNull();
|
||||
expect(Parse.byteCount("M")).toBeNull();
|
||||
expect(Parse.byteCount("G")).toBeNull();
|
||||
expect(Parse.byteCount("-1")).toBeNull();
|
||||
expect(Parse.byteCount("-1k")).toBeNull();
|
||||
expect(Parse.byteCount("1.2.3")).toBeNull();
|
||||
expect(Parse.byteCount("1.2.3k")).toBeNull();
|
||||
});
|
||||
|
||||
it('handles numbers without a suffix', function() {
|
||||
expect(Parse.byteCount("10")).toEqual(10);
|
||||
expect(Parse.byteCount("10.")).toEqual(10);
|
||||
expect(Parse.byteCount("1.5")).toEqual(1.5);
|
||||
});
|
||||
|
||||
it('handles lowercase suffixes', function() {
|
||||
expect(Parse.byteCount("10k")).toEqual(10*1024);
|
||||
expect(Parse.byteCount("10m")).toEqual(10*1024*1024);
|
||||
expect(Parse.byteCount("10g")).toEqual(10*1024*1024*1024);
|
||||
expect(Parse.byteCount("10.k")).toEqual(10*1024);
|
||||
expect(Parse.byteCount("10.m")).toEqual(10*1024*1024);
|
||||
expect(Parse.byteCount("10.g")).toEqual(10*1024*1024*1024);
|
||||
expect(Parse.byteCount("1.5k")).toEqual(1.5*1024);
|
||||
expect(Parse.byteCount("1.5m")).toEqual(1.5*1024*1024);
|
||||
expect(Parse.byteCount("1.5G")).toEqual(1.5*1024*1024*1024);
|
||||
});
|
||||
|
||||
it('handles uppercase suffixes', function() {
|
||||
expect(Parse.byteCount("10K")).toEqual(10*1024);
|
||||
expect(Parse.byteCount("10M")).toEqual(10*1024*1024);
|
||||
expect(Parse.byteCount("10G")).toEqual(10*1024*1024*1024);
|
||||
expect(Parse.byteCount("10.K")).toEqual(10*1024);
|
||||
expect(Parse.byteCount("10.M")).toEqual(10*1024*1024);
|
||||
expect(Parse.byteCount("10.G")).toEqual(10*1024*1024*1024);
|
||||
expect(Parse.byteCount("1.5K")).toEqual(1.5*1024);
|
||||
expect(Parse.byteCount("1.5M")).toEqual(1.5*1024*1024);
|
||||
expect(Parse.byteCount("1.5G")).toEqual(1.5*1024*1024*1024);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ipFromSDP', function() {
|
||||
|
||||
var testCases = [
|
||||
{
|
||||
// https://tools.ietf.org/html/rfc4566#section-5
|
||||
sdp: "v=0\no=jdoe 2890844526 2890842807 IN IP4 10.47.16.5\ns=SDP Seminar\ni=A Seminar on the session description protocol\nu=http://www.example.com/seminars/sdp.pdf\ne=j.doe@example.com (Jane Doe)\nc=IN IP4 224.2.17.12/127\nt=2873397496 2873404696\na=recvonly\nm=audio 49170 RTP/AVP 0\nm=video 51372 RTP/AVP 99\na=rtpmap:99 h263-1998/90000",
|
||||
expected: '224.2.17.12'
|
||||
},
|
||||
{
|
||||
// Missing c= line
|
||||
sdp: "v=0\no=jdoe 2890844526 2890842807 IN IP4 10.47.16.5\ns=SDP Seminar\ni=A Seminar on the session description protocol\nu=http://www.example.com/seminars/sdp.pdf\ne=j.doe@example.com (Jane Doe)\nt=2873397496 2873404696\na=recvonly\nm=audio 49170 RTP/AVP 0\nm=video 51372 RTP/AVP 99\na=rtpmap:99 h263-1998/90000",
|
||||
expected: void 0
|
||||
},
|
||||
{
|
||||
// Single line, IP address only
|
||||
sdp: "c=IN IP4 224.2.1.1\n",
|
||||
expected: '224.2.1.1'
|
||||
},
|
||||
{
|
||||
// Same, with TTL
|
||||
sdp: "c=IN IP4 224.2.1.1/127\n",
|
||||
expected: '224.2.1.1'
|
||||
},
|
||||
{
|
||||
// Same, with TTL and multicast addresses
|
||||
sdp: "c=IN IP4 224.2.1.1/127/3\n",
|
||||
expected: '224.2.1.1'
|
||||
},
|
||||
{
|
||||
// IPv6, address only
|
||||
sdp: "c=IN IP6 FF15::101\n",
|
||||
expected: 'ff15::101'
|
||||
},
|
||||
{
|
||||
// Same, with multicast addresses
|
||||
sdp: "c=IN IP6 FF15::101/3\n",
|
||||
expected: 'ff15::101'
|
||||
},
|
||||
{
|
||||
// Multiple c= lines
|
||||
sdp: "c=IN IP4 1.2.3.4\nc=IN IP4 5.6.7.8",
|
||||
expected: '1.2.3.4'
|
||||
},
|
||||
{
|
||||
// Modified from SDP sent by snowflake-client.
|
||||
sdp: "v=0\no=- 7860378660295630295 2 IN IP4 127.0.0.1\ns=-\nt=0 0\na=group:BUNDLE data\na=msid-semantic: WMS\nm=application 54653 DTLS/SCTP 5000\nc=IN IP4 1.2.3.4\na=candidate:3581707038 1 udp 2122260223 192.168.0.1 54653 typ host generation 0 network-id 1 network-cost 50\na=candidate:2617212910 1 tcp 1518280447 192.168.0.1 59673 typ host tcptype passive generation 0 network-id 1 network-cost 50\na=candidate:2082671819 1 udp 1686052607 1.2.3.4 54653 typ srflx raddr 192.168.0.1 rport 54653 generation 0 network-id 1 network-cost 50\na=ice-ufrag:IBdf\na=ice-pwd:G3lTrrC9gmhQx481AowtkhYz\na=fingerprint:sha-256 53:F8:84:D9:3C:1F:A0:44:AA:D6:3C:65:80:D3:CB:6F:23:90:17:41:06:F9:9C:10:D8:48:4A:A8:B6:FA:14:A1\na=setup:actpass\na=mid:data\na=sctpmap:5000 webrtc-datachannel 1024",
|
||||
expected: '1.2.3.4'
|
||||
},
|
||||
{
|
||||
// Improper character within IPv4
|
||||
sdp: "c=IN IP4 224.2z.1.1",
|
||||
expected: void 0
|
||||
},
|
||||
{
|
||||
// Improper character within IPv6
|
||||
sdp: "c=IN IP6 ff15:g::101",
|
||||
expected: void 0
|
||||
},
|
||||
{
|
||||
// Bogus "IP7" addrtype
|
||||
sdp: "c=IN IP7 1.2.3.4\n",
|
||||
expected: void 0
|
||||
}
|
||||
];
|
||||
|
||||
it('parses SDP', function() {
|
||||
var i, len, ref, ref1, results, test;
|
||||
results = [];
|
||||
for (i = 0, len = testCases.length; i < len; i++) {
|
||||
test = testCases[i];
|
||||
// https://tools.ietf.org/html/rfc4566#section-5: "The sequence # CRLF
|
||||
// (0x0d0a) is used to end a record, although parsers SHOULD be tolerant
|
||||
// and also accept records terminated with a single newline character."
|
||||
// We represent the test cases with LF line endings for convenience, and
|
||||
// test them both that way and with CRLF line endings.
|
||||
expect((ref = Parse.ipFromSDP(test.sdp)) != null ? ref.toLowerCase() : void 0).toEqual(test.expected);
|
||||
results.push(expect((ref1 = Parse.ipFromSDP(test.sdp.replace(/\n/, "\r\n"))) != null ? ref1.toLowerCase() : void 0).toEqual(test.expected));
|
||||
}
|
||||
return results;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('Params', function() {
|
||||
|
||||
describe('bool', function() {
|
||||
|
||||
var getBool = function(query) {
|
||||
return Params.getBool(new URLSearchParams(query), 'param', false);
|
||||
};
|
||||
|
||||
it('parses correctly', function() {
|
||||
expect(getBool('param=true')).toBe(true);
|
||||
expect(getBool('param')).toBe(true);
|
||||
expect(getBool('param=')).toBe(true);
|
||||
expect(getBool('param=1')).toBe(true);
|
||||
expect(getBool('param=0')).toBe(false);
|
||||
expect(getBool('param=false')).toBe(false);
|
||||
expect(getBool('param=unexpected')).toBeNull();
|
||||
expect(getBool('pram=true')).toBe(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('byteCount', function() {
|
||||
|
||||
var DEFAULT = 77;
|
||||
var getByteCount = function(query) {
|
||||
return Params.getByteCount(new URLSearchParams(query), 'param', DEFAULT);
|
||||
};
|
||||
|
||||
it('supports default values', function() {
|
||||
expect(getByteCount('param=x')).toBeNull();
|
||||
expect(getByteCount('param=10')).toEqual(10);
|
||||
expect(getByteCount('foo=10k')).toEqual(DEFAULT);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
|
@ -1,41 +0,0 @@
|
|||
/* global expect, it, describe, WS */
|
||||
|
||||
/*
|
||||
jasmine tests for Snowflake websocket
|
||||
*/
|
||||
|
||||
describe('BuildUrl', function() {
|
||||
|
||||
it('should parse just protocol and host', function() {
|
||||
expect(WS.buildUrl('http', 'example.com')).toBe('http://example.com');
|
||||
});
|
||||
|
||||
it('should handle different ports', function() {
|
||||
expect(WS.buildUrl('http', 'example.com', 80)).toBe('http://example.com');
|
||||
expect(WS.buildUrl('http', 'example.com', 81)).toBe('http://example.com:81');
|
||||
expect(WS.buildUrl('http', 'example.com', 443)).toBe('http://example.com:443');
|
||||
expect(WS.buildUrl('http', 'example.com', 444)).toBe('http://example.com:444');
|
||||
});
|
||||
|
||||
it('should handle paths', function() {
|
||||
expect(WS.buildUrl('http', 'example.com', 80, '/')).toBe('http://example.com/');
|
||||
expect(WS.buildUrl('http', 'example.com', 80, '/test?k=%#v')).toBe('http://example.com/test%3Fk%3D%25%23v');
|
||||
expect(WS.buildUrl('http', 'example.com', 80, '/test')).toBe('http://example.com/test');
|
||||
});
|
||||
|
||||
it('should handle params', function() {
|
||||
expect(WS.buildUrl('http', 'example.com', 80, '/test', [['k', '%#v']])).toBe('http://example.com/test?k=%25%23v');
|
||||
expect(WS.buildUrl('http', 'example.com', 80, '/test', [['a', 'b'], ['c', 'd']])).toBe('http://example.com/test?a=b&c=d');
|
||||
});
|
||||
|
||||
it('should handle ips', function() {
|
||||
expect(WS.buildUrl('http', '1.2.3.4')).toBe('http://1.2.3.4');
|
||||
expect(WS.buildUrl('http', '1:2::3:4')).toBe('http://[1:2::3:4]');
|
||||
});
|
||||
|
||||
it('should handle bogus', function() {
|
||||
expect(WS.buildUrl('http', 'bog][us')).toBe('http://bog%5D%5Bus');
|
||||
expect(WS.buildUrl('http', 'bog:u]s')).toBe('http://bog%3Au%5Ds');
|
||||
});
|
||||
|
||||
});
|
|
@ -1,5 +0,0 @@
|
|||
<Files "embed.html">
|
||||
Header always unset X-Frame-Options
|
||||
</Files>
|
||||
|
||||
Redirect permanent /snowflake.html /
|
|
@ -1,80 +0,0 @@
|
|||
{
|
||||
"appDesc": {
|
||||
"message": "Snowflake is a WebRTC pluggable transport for Tor."
|
||||
},
|
||||
"popupEnabled": {
|
||||
"message": "Enabled"
|
||||
},
|
||||
"popupLearnMore": {
|
||||
"message": "Learn more"
|
||||
},
|
||||
"popupStatusOff": {
|
||||
"message": "Snowflake is off"
|
||||
},
|
||||
"popupStatusOn": {
|
||||
"message": "Number of users currently connected: $1"
|
||||
},
|
||||
"popupStatusReady": {
|
||||
"message": "Your Snowflake is ready to help users circumvent censorship"
|
||||
},
|
||||
"popupWebRTCOff": {
|
||||
"message": "WebRTC feature is not detected."
|
||||
},
|
||||
"popupBridgeUnreachable": {
|
||||
"message": "Could not connect to the bridge."
|
||||
},
|
||||
"popupDescOn": {
|
||||
"message": "Number of users your Snowflake has helped circumvent censorship in the last 24 hours: $1"
|
||||
},
|
||||
"badgeCookiesOff": {
|
||||
"message": "Cookies are not enabled."
|
||||
},
|
||||
"websiteIntro": {
|
||||
"message": "Snowflake is a system to defeat internet censorship. People who are censored can use Snowflake to access the internet. Their connection goes through Snowflake proxies, which are run by volunteers. For more detailed information about how Snowflake works see our <a href=\"https://trac.torproject.org/projects/tor/wiki/doc/Snowflake/\" data-msgid=\"__MSG_docWiki__\">documentation wiki</a>."
|
||||
},
|
||||
"docWiki": {
|
||||
"message": "documentation wiki"
|
||||
},
|
||||
"browser": {
|
||||
"message": "Browser"
|
||||
},
|
||||
"censoredUsers": {
|
||||
"message": "If your internet access is censored, you should download <a href=\"https://www.torproject.org/download/\">Tor Browser</a>."
|
||||
},
|
||||
"extension": {
|
||||
"message": "Extension"
|
||||
},
|
||||
"installExtension": {
|
||||
"message": "If your internet access is <strong>not</strong> censored, you should consider installing the Snowflake extension to help users in censored networks. There is no need to worry about which websites people are accessing through your proxy. Their visible browsing IP address will match their Tor exit node, not yours."
|
||||
},
|
||||
"installFirefox": {
|
||||
"message": "Install in Firefox"
|
||||
},
|
||||
"installChrome": {
|
||||
"message": "Install in Chrome"
|
||||
},
|
||||
"reportingBugs": {
|
||||
"message": "Reporting Bugs"
|
||||
},
|
||||
"fileBug": {
|
||||
"message": "If you encounter problems with Snowflake as a client or a proxy, please consider filing a bug. To do so, you will have to,"
|
||||
},
|
||||
"sharedAccount": {
|
||||
"message": "Either <a href=\"https://trac.torproject.org/projects/tor/register\">create an account</a> or <a href=\"https://trac.torproject.org/projects/tor/login\">log in</a> using the shared <b>cypherpunks</b> account with password <b>writecode</b>."
|
||||
},
|
||||
"bugTracker": {
|
||||
"message": "<a href=\"https://trac.torproject.org/projects/tor/newticket?component=Circumvention%2FSnowflake\">File a ticket</a> using our bug tracker."
|
||||
},
|
||||
"descriptive": {
|
||||
"message": "Please try to be as descriptive as possible with your ticket and if possible include log messages that will help us reproduce the bug. Consider adding keywords <em>snowflake-webextension</em> or <em>snowflake-client</em> to let us know how which part of the Snowflake system is experiencing problems."
|
||||
},
|
||||
"embed": {
|
||||
"message": "Embed"
|
||||
},
|
||||
"possible": {
|
||||
"message": "It is now possible to embed the Snowflake badge on any website:"
|
||||
},
|
||||
"looksLike": {
|
||||
"message": "Which looks like this:"
|
||||
}
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
<!-- 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/. -->
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12"><path fill="black" d="M9 6a1 1 0 0 0-.293-.707l-3-3a1 1 0 0 0-1.414 1.414L6.586 6 4.293 8.293a1 1 0 0 0 1.414 1.414l3-3A1 1 0 0 0 9 6z"/></svg>
|
Before Width: | Height: | Size: 438 B |
|
@ -1,4 +0,0 @@
|
|||
<!-- 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/. -->
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12"><path fill="white" d="M9 6a1 1 0 0 0-.293-.707l-3-3a1 1 0 0 0-1.414 1.414L6.586 6 4.293 8.293a1 1 0 0 0 1.414 1.414l3-3A1 1 0 0 0 9 6z"/></svg>
|
Before Width: | Height: | Size: 438 B |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 8 KiB |
Before Width: | Height: | Size: 7.8 KiB |
Before Width: | Height: | Size: 8 KiB |
Before Width: | Height: | Size: 7.8 KiB |
Before Width: | Height: | Size: 7.8 KiB |
Before Width: | Height: | Size: 3.6 KiB |
Before Width: | Height: | Size: 7 KiB |
Before Width: | Height: | Size: 4.2 KiB |
Before Width: | Height: | Size: 8.1 KiB |
Before Width: | Height: | Size: 3.6 KiB |
Before Width: | Height: | Size: 7.2 KiB |
Before Width: | Height: | Size: 4.2 KiB |
Before Width: | Height: | Size: 8.1 KiB |
Before Width: | Height: | Size: 3.6 KiB |
Before Width: | Height: | Size: 7.2 KiB |
Before Width: | Height: | Size: 4.2 KiB |
Before Width: | Height: | Size: 8.1 KiB |
334
proxy/static/bootstrap.css
vendored
|
@ -1,334 +0,0 @@
|
|||
/* This is a subset of bootstrap.css */
|
||||
.navbar-brand img {
|
||||
max-width: 4em; }
|
||||
|
||||
.navbar {
|
||||
display: none; }
|
||||
|
||||
.navbar {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 0.5rem 1rem; }
|
||||
.navbar > .container,
|
||||
.navbar > .container-fluid {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
justify-content: space-between; }
|
||||
|
||||
.navbar-brand {
|
||||
display: inline-block;
|
||||
padding-top: 0.3125rem;
|
||||
padding-bottom: 0.3125rem;
|
||||
margin-right: 1rem;
|
||||
font-size: 1.25rem;
|
||||
line-height: inherit;
|
||||
white-space: nowrap; }
|
||||
.navbar-brand:focus, .navbar-brand:hover {
|
||||
text-decoration: none; }
|
||||
|
||||
.navbar-dark .navbar-brand {
|
||||
color: #FFFFFF; }
|
||||
.navbar-dark .navbar-brand:focus, .navbar-dark .navbar-brand:hover {
|
||||
color: #FFFFFF; }
|
||||
.navbar-dark .navbar-nav .nav-link {
|
||||
color: #FFFFFF; }
|
||||
.navbar-dark .navbar-nav .nav-link:focus, .navbar-dark .navbar-nav .nav-link:hover {
|
||||
color: rgba(255, 255, 255, 0.75); }
|
||||
.navbar-dark .navbar-nav .nav-link.disabled {
|
||||
color: rgba(255, 255, 255, 0.25); }
|
||||
.navbar-dark .navbar-nav .show > .nav-link,
|
||||
.navbar-dark .navbar-nav .active > .nav-link,
|
||||
.navbar-dark .navbar-nav .nav-link.show,
|
||||
.navbar-dark .navbar-nav .nav-link.active {
|
||||
color: #FFFFFF; }
|
||||
.navbar-dark .navbar-toggler {
|
||||
color: #FFFFFF;
|
||||
border-color: rgba(255, 255, 255, 0.1); }
|
||||
.navbar-dark .navbar-toggler-icon {
|
||||
background-image: url("data:image/svg+xml;charset=utf8,%3Csvg viewBox='0 0 30 30' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath stroke='%23FFFFFF' stroke-width='2' stroke-linecap='round' stroke-miterlimit='10' d='M4 7h22M4 15h22M4 23h22'/%3E%3C/svg%3E"); }
|
||||
.navbar-dark .navbar-text {
|
||||
color: #FFFFFF; }
|
||||
.navbar-dark .navbar-text a {
|
||||
color: #FFFFFF; }
|
||||
.navbar-dark .navbar-text a:focus, .navbar-dark .navbar-text a:hover {
|
||||
color: #FFFFFF; }
|
||||
|
||||
.navbar {
|
||||
background-image: url("./images/onion-bg.svg");
|
||||
background-repeat: no-repeat;
|
||||
background-position: 10px 12px; }
|
||||
|
||||
.navbar-brand span {
|
||||
font-size: 0.6em;
|
||||
display: flex; }
|
||||
|
||||
.no-gutters {
|
||||
margin-right: 0;
|
||||
margin-left: 0; }
|
||||
.no-gutters > .col,
|
||||
.no-gutters > [class*="col-"] {
|
||||
padding-right: 0;
|
||||
padding-left: 0; }
|
||||
|
||||
.no-gutters {
|
||||
margin-bottom: 0 !important; }
|
||||
|
||||
.no-background {
|
||||
background-image: none !important; }
|
||||
|
||||
.bg-dark {
|
||||
background-color: #59316B !important; }
|
||||
|
||||
a.bg-dark:focus, a.bg-dark:hover {
|
||||
background-color: #3c2148 !important; }
|
||||
|
||||
.p-4 {
|
||||
padding: 1.5rem !important; }
|
||||
|
||||
.btn-group,
|
||||
.btn-group-vertical {
|
||||
position: relative;
|
||||
display: inline-flex;
|
||||
vertical-align: middle; }
|
||||
.btn-group > .btn,
|
||||
.btn-group-vertical > .btn {
|
||||
position: relative;
|
||||
flex: 0 1 auto; }
|
||||
.btn-group > .btn:hover,
|
||||
.btn-group-vertical > .btn:hover {
|
||||
z-index: 2; }
|
||||
.btn-group > .btn:focus, .btn-group > .btn:active, .btn-group > .btn.active,
|
||||
.btn-group-vertical > .btn:focus,
|
||||
.btn-group-vertical > .btn:active,
|
||||
.btn-group-vertical > .btn.active {
|
||||
z-index: 2; }
|
||||
.btn-group .btn + .btn,
|
||||
.btn-group .btn + .btn-group,
|
||||
.btn-group .btn-group + .btn,
|
||||
.btn-group .btn-group + .btn-group,
|
||||
.btn-group-vertical .btn + .btn,
|
||||
.btn-group-vertical .btn + .btn-group,
|
||||
.btn-group-vertical .btn-group + .btn,
|
||||
.btn-group-vertical .btn-group + .btn-group {
|
||||
margin-left: -1px; }
|
||||
|
||||
.btn-group > .btn:not(:first-child):not(:last-child):not(.dropdown-toggle) {
|
||||
border-radius: 0; }
|
||||
|
||||
.btn-group > .btn:first-child {
|
||||
margin-left: 0; }
|
||||
.btn-group > .btn:first-child:not(:last-child):not(.dropdown-toggle) {
|
||||
border-top-right-radius: 0;
|
||||
border-bottom-right-radius: 0; }
|
||||
|
||||
.btn-group > .btn:last-child:not(:first-child),
|
||||
.btn-group > .dropdown-toggle:not(:first-child) {
|
||||
border-top-left-radius: 0;
|
||||
border-bottom-left-radius: 0; }
|
||||
|
||||
.btn-group > .btn-group {
|
||||
float: left; }
|
||||
|
||||
.btn-group > .btn-group:not(:first-child):not(:last-child) > .btn {
|
||||
border-radius: 0; }
|
||||
|
||||
.btn-group > .btn-group:first-child:not(:last-child) > .btn:last-child,
|
||||
.btn-group > .btn-group:first-child:not(:last-child) > .dropdown-toggle {
|
||||
border-top-right-radius: 0;
|
||||
border-bottom-right-radius: 0; }
|
||||
|
||||
.btn-group > .btn-group:last-child:not(:first-child) > .btn:first-child {
|
||||
border-top-left-radius: 0;
|
||||
border-bottom-left-radius: 0; }
|
||||
|
||||
.dropup,
|
||||
.dropdown {
|
||||
position: relative; }
|
||||
|
||||
.dropdown-toggle::after {
|
||||
display: inline-block;
|
||||
width: 0;
|
||||
height: 0;
|
||||
margin-left: 0.255em;
|
||||
vertical-align: 0.255em;
|
||||
content: "";
|
||||
border-top: 0.3em solid;
|
||||
border-right: 0.3em solid transparent;
|
||||
border-bottom: 0;
|
||||
border-left: 0.3em solid transparent; }
|
||||
.dropdown-toggle:empty::after {
|
||||
margin-left: 0; }
|
||||
|
||||
.dropup .dropdown-toggle::after {
|
||||
display: inline-block;
|
||||
width: 0;
|
||||
height: 0;
|
||||
margin-left: 0.255em;
|
||||
vertical-align: 0.255em;
|
||||
content: "";
|
||||
border-top: 0;
|
||||
border-right: 0.3em solid transparent;
|
||||
border-bottom: 0.3em solid;
|
||||
border-left: 0.3em solid transparent; }
|
||||
.dropup .dropdown-toggle:empty::after {
|
||||
margin-left: 0; }
|
||||
|
||||
.dropdown-menu {
|
||||
position: absolute;
|
||||
top: 100%;
|
||||
left: 0;
|
||||
z-index: 1000;
|
||||
display: none;
|
||||
float: left;
|
||||
min-width: 10rem;
|
||||
padding: 0.5rem 0;
|
||||
margin: 0.125rem 0 0;
|
||||
font-size: 1rem;
|
||||
color: #212529;
|
||||
text-align: left;
|
||||
list-style: none;
|
||||
background-color: #FFFFFF;
|
||||
background-clip: padding-box;
|
||||
border: 1px solid rgba(0, 0, 0, 0.15);
|
||||
border-radius: 0.25rem; }
|
||||
|
||||
.dropup .dropdown-menu {
|
||||
margin-top: 0;
|
||||
margin-bottom: 0.125rem; }
|
||||
.dropup .dropdown-toggle::after {
|
||||
display: inline-block;
|
||||
width: 0;
|
||||
height: 0;
|
||||
margin-left: 0.255em;
|
||||
vertical-align: 0.255em;
|
||||
content: "";
|
||||
border-top: 0;
|
||||
border-right: 0.3em solid transparent;
|
||||
border-bottom: 0.3em solid;
|
||||
border-left: 0.3em solid transparent; }
|
||||
.dropup .dropdown-toggle:empty::after {
|
||||
margin-left: 0; }
|
||||
|
||||
.dropdown-menu.show {
|
||||
display: block; }
|
||||
|
||||
.dropdown-item {
|
||||
display: block;
|
||||
width: 100%;
|
||||
padding: 0.25rem 1.5rem;
|
||||
clear: both;
|
||||
font-weight: 400;
|
||||
color: #212529;
|
||||
text-align: inherit;
|
||||
white-space: nowrap;
|
||||
background: none;
|
||||
border: 0; }
|
||||
.dropdown-item:focus, .dropdown-item:hover {
|
||||
color: #16181b;
|
||||
text-decoration: none;
|
||||
background-color: #F8F9FA; }
|
||||
.dropdown-item.active, .dropdown-item:active {
|
||||
color: #FFFFFF;
|
||||
text-decoration: none;
|
||||
background-color: #7D4698; }
|
||||
.dropdown-item.disabled, .dropdown-item:disabled {
|
||||
color: #848E97;
|
||||
background-color: transparent; }
|
||||
|
||||
.btn {
|
||||
display: inline-block;
|
||||
font-weight: 400;
|
||||
text-align: center;
|
||||
white-space: nowrap;
|
||||
vertical-align: middle;
|
||||
user-select: none;
|
||||
border: 1px solid transparent;
|
||||
padding: 0.375rem 0.75rem;
|
||||
font-size: 1rem;
|
||||
line-height: 1.5;
|
||||
border-radius: 0.25rem;
|
||||
transition: background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out; }
|
||||
.btn:focus, .btn:hover {
|
||||
text-decoration: none; }
|
||||
.btn:focus, .btn.focus {
|
||||
outline: 0;
|
||||
box-shadow: 0 0 0 0.2rem rgba(125, 70, 152, 0.25); }
|
||||
.btn.disabled, .btn:disabled {
|
||||
opacity: .65; }
|
||||
.btn:not([disabled]):not(.disabled):active, .btn:not([disabled]):not(.disabled).active {
|
||||
background-image: none; }
|
||||
|
||||
a.btn.disabled,
|
||||
fieldset[disabled] a.btn {
|
||||
pointer-events: none; }
|
||||
|
||||
.btn-dark {
|
||||
color: #fff;
|
||||
background-color: #59316B;
|
||||
border-color: #59316B; }
|
||||
.btn-dark:hover {
|
||||
color: #fff;
|
||||
background-color: #432551;
|
||||
border-color: #3c2148; }
|
||||
.btn-dark:focus, .btn-dark.focus {
|
||||
box-shadow: 0 0 0 0.2rem rgba(89, 49, 107, 0.5); }
|
||||
.btn-dark.disabled, .btn-dark:disabled {
|
||||
background-color: #59316B;
|
||||
border-color: #59316B; }
|
||||
.btn-dark:not([disabled]):not(.disabled):active, .btn-dark:not([disabled]):not(.disabled).active, .show > .btn-dark.dropdown-toggle {
|
||||
color: #fff;
|
||||
background-color: #3c2148;
|
||||
border-color: #351d3f;
|
||||
box-shadow: 0 0 0 0.2rem rgba(89, 49, 107, 0.5); }
|
||||
|
||||
|
||||
.btn-block {
|
||||
display: block;
|
||||
width: 100%; }
|
||||
|
||||
.btn-block + .btn-block {
|
||||
margin-top: 0.5rem; }
|
||||
|
||||
input[type="submit"].btn-block,
|
||||
input[type="reset"].btn-block,
|
||||
input[type="button"].btn-block {
|
||||
width: 100%; }
|
||||
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
box-sizing: border-box; }
|
||||
|
||||
a,
|
||||
area,
|
||||
button,
|
||||
[role="button"],
|
||||
input:not([type="range"]),
|
||||
label,
|
||||
select,
|
||||
summary,
|
||||
textarea {
|
||||
touch-action: manipulation; }
|
||||
|
||||
a {
|
||||
color: #7D4698;
|
||||
text-decoration: none;
|
||||
background-color: transparent;
|
||||
-webkit-text-decoration-skip: objects; }
|
||||
a:hover {
|
||||
color: #522e64;
|
||||
text-decoration: underline; }
|
||||
|
||||
a:not([href]):not([tabindex]) {
|
||||
color: inherit;
|
||||
text-decoration: none; }
|
||||
a:not([href]):not([tabindex]):focus, a:not([href]):not([tabindex]):hover {
|
||||
color: inherit;
|
||||
text-decoration: none; }
|
||||
a:not([href]):not([tabindex]):focus {
|
||||
outline: 0; }
|
||||
|
Before Width: | Height: | Size: 5.2 KiB |
|
@ -1,150 +0,0 @@
|
|||
body {
|
||||
color: black;
|
||||
margin: 10px;
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
|
||||
width: 300px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
#active {
|
||||
margin: 20px 0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#statusimg {
|
||||
background-image: url("assets/status-off.svg");
|
||||
background-repeat: no-repeat;
|
||||
background-position: center center;
|
||||
min-height: 60px;
|
||||
}
|
||||
#statusimg.on {
|
||||
background-image: url("assets/status-on.svg");
|
||||
}
|
||||
#statusimg.on.running {
|
||||
background-image: url("assets/status-running.svg");
|
||||
}
|
||||
|
||||
.b {
|
||||
border-top: 1px solid gainsboro;
|
||||
padding: 10px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.b a {
|
||||
color: inherit;
|
||||
display: inline-block;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.error {
|
||||
color: firebrick;
|
||||
}
|
||||
|
||||
.learn:before {
|
||||
content : " ";
|
||||
display: block;
|
||||
position: absolute;
|
||||
top: 12px;
|
||||
background-image: url('assets/arrowhead-right-12.svg');
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
opacity : 0.6;
|
||||
z-index: 9999;
|
||||
right: 0px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
/* Snowflake Status */
|
||||
|
||||
.transfering {
|
||||
-webkit-animation:spin 8s linear infinite;
|
||||
-moz-animation:spin 8s linear infinite;
|
||||
animation:spin 8s linear infinite;
|
||||
fill: BlueViolet;
|
||||
}
|
||||
@-moz-keyframes spin { 100% { -moz-transform: rotate(360deg); } }
|
||||
@-webkit-keyframes spin { 100% { -webkit-transform: rotate(360deg); } }
|
||||
@keyframes spin { 100% { -webkit-transform: rotate(360deg); transform:rotate(360deg); } }
|
||||
|
||||
/* Toggle */
|
||||
|
||||
.switch {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
width: 30px;
|
||||
height: 17px;
|
||||
float: right;
|
||||
}
|
||||
|
||||
.switch input {
|
||||
opacity: 0;
|
||||
width: 0;
|
||||
height: 0;
|
||||
}
|
||||
|
||||
.slider {
|
||||
position: absolute;
|
||||
cursor: pointer;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: #ccc;
|
||||
-webkit-transition: .4s;
|
||||
transition: .4s;
|
||||
border-radius: 17px;
|
||||
}
|
||||
|
||||
.slider:before {
|
||||
position: absolute;
|
||||
content: "";
|
||||
height: 13px;
|
||||
width: 13px;
|
||||
left: 2px;
|
||||
bottom: 2px;
|
||||
background-color: white;
|
||||
-webkit-transition: .4s;
|
||||
transition: .4s;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
input:checked + .slider {
|
||||
background-color: BlueViolet;
|
||||
}
|
||||
|
||||
input:focus + .slider {
|
||||
box-shadow: 0 0 1px BlueViolet;
|
||||
}
|
||||
|
||||
input:checked + .slider:before {
|
||||
-webkit-transform: translateX(13px);
|
||||
-ms-transform: translateX(13px);
|
||||
transform: translateX(13px);
|
||||
}
|
||||
|
||||
/* Dark Mode */
|
||||
@media (prefers-color-scheme: dark) {
|
||||
body {
|
||||
/* https://design.firefox.com/photon/visuals/color.html#dark-theme */
|
||||
color: white;
|
||||
background-color: #38383d;
|
||||
}
|
||||
#statusimg {
|
||||
background-image: url("assets/status-off-dark.svg");
|
||||
}
|
||||
#statusimg.on {
|
||||
background-image: url("assets/status-on-dark.svg");
|
||||
}
|
||||
#statusimg.on.running {
|
||||
background-image: url("assets/status-running.svg");
|
||||
}
|
||||
input:checked + .slider {
|
||||
background-color: #cc80ff;
|
||||
}
|
||||
input:focus + .slider {
|
||||
box-shadow: 0 0 1px #cc80ff;
|
||||
}
|
||||
.learn:before {
|
||||
background-image: url('assets/arrowhead-right-dark-12.svg');
|
||||
}
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<!-- This should be essentially be a no-opt in the popup -->
|
||||
<meta http-equiv="refresh" content="86400" />
|
||||
<title>Snowflake</title>
|
||||
<link rel="icon" id="icon" href="assets/toolbar-off.ico" />
|
||||
<link rel="stylesheet" href="embed.css" />
|
||||
<script src="popup.js"></script>
|
||||
<script src="embed.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="active">
|
||||
<div id="statusimg"></div>
|
||||
<p id="statustext">__MSG_popupStatusOff__</p>
|
||||
<p id="statusdesc"></p>
|
||||
</div>
|
||||
<div class="b button">
|
||||
<label id="toggle" for="enabled">__MSG_popupEnabled__</label>
|
||||
<label class="switch">
|
||||
<input id="enabled" type="checkbox" />
|
||||
<span class="slider round"></span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="b learn">
|
||||
<a target="_blank" href="https://snowflake.torproject.org/">__MSG_popupLearnMore__</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Before Width: | Height: | Size: 44 KiB |
|
@ -1,94 +0,0 @@
|
|||
@font-face {
|
||||
font-family: Source Sans Pro;
|
||||
src: url("SourceSansPro-Regular.ttf");
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: "Source Sans Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
|
||||
font-size: 1.3rem;
|
||||
font-weight: 400;
|
||||
line-height: 1.5;
|
||||
color: #212529;
|
||||
}
|
||||
|
||||
header {
|
||||
margin: 0;
|
||||
background-color: #59316B;
|
||||
padding: 0 5.2rem;
|
||||
}
|
||||
|
||||
#content {
|
||||
max-width: 90rem;
|
||||
margin: 0 auto 2.6rem auto;
|
||||
padding: 2.6rem 5.2rem;
|
||||
background-color: #FFFFFF;
|
||||
}
|
||||
|
||||
@media only screen and (max-width: 600px) {
|
||||
#content {
|
||||
padding: 2.6rem 1.3rem;
|
||||
}
|
||||
}
|
||||
|
||||
section {
|
||||
margin: 1.3rem 0;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin: 0;
|
||||
font-size: 2.6rem;
|
||||
color: #7D4698;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
h2 {
|
||||
margin: 0;
|
||||
font-size: 2rem;
|
||||
color: #7D4698;
|
||||
}
|
||||
|
||||
.sidebyside {
|
||||
display: flex;
|
||||
flex-flow: row wrap;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.sidebyside section {
|
||||
flex: 1 1 15rem;
|
||||
padding: 0 1.3rem;
|
||||
}
|
||||
|
||||
.addon {
|
||||
margin-top: 2.6rem 0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.addon a {
|
||||
display: inline-block;
|
||||
padding: 0 1.3rem;
|
||||
}
|
||||
|
||||
.diagram, .screenshot {
|
||||
padding: 2.6rem 5.2rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.diagram img, .screenshot img {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
textarea {
|
||||
max-width: 100%;
|
||||
width: 600px;
|
||||
}
|
||||
|
||||
.dropdown:hover .dropdown-menu {
|
||||
display: block;
|
||||
height: 350px;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.pull-right {
|
||||
float: right !important;
|
||||
}
|
|
@ -1,116 +0,0 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>Snowflake</title>
|
||||
<link rel="icon" href="./assets/favicon.ico" />
|
||||
<link rel="stylesheet" href="./bootstrap.css" />
|
||||
<link rel="stylesheet" href="./index.css" />
|
||||
</head>
|
||||
<body class="no-gutters">
|
||||
<header id="header">
|
||||
|
||||
<nav class="navbar no-background navbar-dark bg-dark p-4">
|
||||
|
||||
<a class="navbar-brand" href="https://www.torproject.org/">
|
||||
<img src="./tor-logo@2x.png" alt="Tor" height="50" />
|
||||
</a>
|
||||
|
||||
<div class="btn-group dropdown pull-right">
|
||||
|
||||
<button id="language-switcher" type="button" class="btn btn-dark bg-dark dropdown-toggle btn-block" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
</button>
|
||||
<div id="supported-languages" class="dropdown-menu">
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
<div>
|
||||
<section id="content">
|
||||
<h1>SNOWFLAKE</h1>
|
||||
|
||||
<p class="diagram"><img src="https://trac.torproject.org/projects/tor/raw-attachment/wiki/doc/Snowflake/snowflake-schematic.png" alt="Diagram" /></p>
|
||||
|
||||
<p data-msgid="__MSG_websiteIntro__">Snowflake is a system to defeat internet censorship. People who are
|
||||
censored can use Snowflake to access the internet. Their connection goes
|
||||
through Snowflake proxies, which are run by volunteers. For more detailed
|
||||
information about how Snowflake works see our
|
||||
<a href="https://trac.torproject.org/projects/tor/wiki/doc/Snowflake/" data-msgid="__MSG_docWiki__">documentation wiki</a>.</p>
|
||||
|
||||
<div class="sidebyside">
|
||||
|
||||
<section id="browser" class="browser">
|
||||
<h2 data-msgid="__MSG_browser__">Browser</h2>
|
||||
|
||||
<p data-msgid="__MSG_censoredUsers__">If your internet access is censored, you should download
|
||||
<a href="https://www.torproject.org/download/">Tor Browser</a>.</p>
|
||||
|
||||
<p class="screenshot"><img src="./screenshot.png" alt="Tor Browser screenshot" /></p>
|
||||
</section>
|
||||
|
||||
<section id="extension" class="extension">
|
||||
<h2 data-msgid="__MSG_extension__">Extension</h2>
|
||||
|
||||
<p data-msgid="__MSG_installExtension__">If your internet access is <strong>not</strong> censored, you should
|
||||
consider installing the Snowflake extension to help users in censored
|
||||
networks. There is no need to worry about which websites people are
|
||||
accessing through your proxy. Their visible browsing IP address will
|
||||
match their Tor exit node, not yours.</p>
|
||||
|
||||
<p class="addon">
|
||||
<a href="https://addons.mozilla.org/en-US/firefox/addon/torproject-snowflake/">
|
||||
<img src="./firefox150.jpg" alt="Install in Firefox" height="100" /><br />
|
||||
<span data-msgid="MSG_installFirefox__">Install in Firefox</span>
|
||||
</a>
|
||||
<a href="https://chrome.google.com/webstore/detail/snowflake/mafpmfcccpbjnhfhjnllmmalhifmlcie">
|
||||
<img src="./chrome150.jpg" alt="Install in Chrome" height="100" /><br />
|
||||
<span data-msgid="__MSG_installChrome__">Install in Chrome</span>
|
||||
</a>
|
||||
</p>
|
||||
</section>
|
||||
|
||||
</div>
|
||||
|
||||
<section id="bugs">
|
||||
<h2 data-msgid="__MSG_reportingBugs__">Reporting Bugs</h2>
|
||||
|
||||
<p data-msgid="__MSG_fileBug__">If you encounter problems with Snowflake as a client or a proxy,
|
||||
please consider filing a bug. To do so, you will have to,</p>
|
||||
|
||||
<ol>
|
||||
<li data-msgid="__MSG_sharedAccount__">
|
||||
Either <a href="https://trac.torproject.org/projects/tor/register">create an
|
||||
account</a> or <a href="https://trac.torproject.org/projects/tor/login">log in</a>
|
||||
using the shared <b>cypherpunks</b> account with password <b>writecode</b>.</li>
|
||||
<li data-msgid="__MSG_bugTracker__">
|
||||
<a href="https://trac.torproject.org/projects/tor/newticket?component=Circumvention%2FSnowflake">File a ticket</a>
|
||||
using our bug tracker.</li>
|
||||
</ol>
|
||||
|
||||
<p data-msgid="__MSG_descriptive__">
|
||||
Please try to be as descriptive as possible with your ticket and if
|
||||
possible include log messages that will help us reproduce the bug.
|
||||
Consider adding keywords <em>snowflake-webextension</em> or <em>snowflake-client</em>
|
||||
to let us know how which part of the Snowflake system is experiencing
|
||||
problems.
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section id="embed">
|
||||
<h2 data-msgid="__MSG_embed__">Embed</h2>
|
||||
|
||||
<p data-msgid="__MSG_possible__">It is now possible to embed the Snowflake badge on any website:</p>
|
||||
|
||||
<textarea readonly><iframe src="https://snowflake.torproject.org/embed.html" width="320" height="240" frameborder="0" scrolling="no"></iframe></textarea>
|
||||
|
||||
<p data-msgid="__MSG_looksLike__">Which looks like this:</p>
|
||||
|
||||
<iframe src="https://snowflake.torproject.org/embed.html" width="320" height="240" frameborder="0" scrolling="no"></iframe>
|
||||
</section>
|
||||
|
||||
</section>
|
||||
</div>
|
||||
<script src="index.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,83 +0,0 @@
|
|||
/* global availableLangs */
|
||||
|
||||
class Messages {
|
||||
constructor(json) {
|
||||
this.json = json;
|
||||
}
|
||||
getMessage(m, ...rest) {
|
||||
if (Object.prototype.hasOwnProperty.call(this.json, m)) {
|
||||
let message = this.json[m].message;
|
||||
return message.replace(/\$(\d+)/g, (...args) => {
|
||||
return rest[Number(args[1]) - 1];
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var defaultLang = "en_US";
|
||||
|
||||
var getLang = function() {
|
||||
let lang = navigator.language || defaultLang;
|
||||
lang = lang.replace(/-/g, '_');
|
||||
|
||||
//prioritize override language
|
||||
var url_string = window.location.href; //window.location.href
|
||||
var url = new URL(url_string);
|
||||
var override_lang = url.searchParams.get("lang");
|
||||
if (override_lang != null) {
|
||||
lang = override_lang;
|
||||
}
|
||||
|
||||
if (Object.prototype.hasOwnProperty.call(availableLangs, lang)) {
|
||||
return lang;
|
||||
}
|
||||
lang = lang.split('_')[0];
|
||||
if (Object.prototype.hasOwnProperty.call(availableLangs, lang)) {
|
||||
return lang;
|
||||
}
|
||||
return defaultLang;
|
||||
}
|
||||
|
||||
var fill = function(n, func) {
|
||||
switch(n.nodeType) {
|
||||
case 1: // Node.ELEMENT_NODE
|
||||
{
|
||||
const m = /^__MSG_([^_]*)__$/.exec(n.dataset.msgid);
|
||||
if (m) {
|
||||
var val = func(m[1]);
|
||||
if (val != undefined) {
|
||||
n.innerHTML = val
|
||||
}
|
||||
}
|
||||
n.childNodes.forEach(c => fill(c, func));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fetch(`./_locales/${getLang()}/messages.json`)
|
||||
.then((res) => {
|
||||
if (!res.ok) { return; }
|
||||
return res.json();
|
||||
})
|
||||
.then((json) => {
|
||||
var language = document.getElementById('language-switcher');
|
||||
var lang = `${getLang()}`
|
||||
language.innerText = availableLangs[lang].name + ' (' + lang + ')';
|
||||
var messages = new Messages(json);
|
||||
fill(document.body, (m) => {
|
||||
return messages.getMessage(m);
|
||||
});
|
||||
});
|
||||
|
||||
// Populate language switcher list
|
||||
for (var lang in availableLangs) {
|
||||
var languageList = document.getElementById('supported-languages');
|
||||
var link = document.createElement('a');
|
||||
link.setAttribute('href', '?lang='+lang);
|
||||
link.setAttribute('class', "dropdown-item");
|
||||
link.innerText = availableLangs[lang].name + ' (' + lang + ')';
|
||||
languageList.lastChild.after(link);
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
/* exported Popup */
|
||||
|
||||
// Add or remove a class from elem.classList, depending on cond.
|
||||
function setClass(elem, className, cond) {
|
||||
if (cond) {
|
||||
elem.classList.add(className);
|
||||
} else {
|
||||
elem.classList.remove(className);
|
||||
}
|
||||
}
|
||||
|
||||
class Popup {
|
||||
constructor() {
|
||||
this.div = document.getElementById('active');
|
||||
this.statustext = document.getElementById('statustext');
|
||||
this.statusdesc = document.getElementById('statusdesc');
|
||||
this.img = document.getElementById('statusimg');
|
||||
}
|
||||
setEnabled(enabled) {
|
||||
setClass(this.img, 'on', enabled);
|
||||
}
|
||||
setActive(active) {
|
||||
setClass(this.img, 'running', active);
|
||||
}
|
||||
setStatusText(txt) {
|
||||
this.statustext.innerText = txt;
|
||||
}
|
||||
setStatusDesc(desc, error) {
|
||||
this.statusdesc.innerText = desc;
|
||||
setClass(this.statusdesc, 'error', error);
|
||||
}
|
||||
hideButton() {
|
||||
document.querySelector('.button').style.display = 'none';
|
||||
}
|
||||
setChecked(checked) {
|
||||
document.getElementById('enabled').checked = checked;
|
||||
}
|
||||
static fill(n, func) {
|
||||
switch(n.nodeType) {
|
||||
case 3: { // Node.TEXT_NODE
|
||||
const m = /^__MSG_([^_]*)__$/.exec(n.nodeValue);
|
||||
if (m) { n.nodeValue = func(m[1]); }
|
||||
break;
|
||||
}
|
||||
case 1: // Node.ELEMENT_NODE
|
||||
n.childNodes.forEach(c => Popup.fill(c, func));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
Before Width: | Height: | Size: 369 KiB |
Before Width: | Height: | Size: 9.8 KiB |
17
proxy/ui.js
|
@ -1,17 +0,0 @@
|
|||
/*
|
||||
All of Snowflake's DOM manipulation and inputs.
|
||||
*/
|
||||
|
||||
class UI {
|
||||
|
||||
setStatus() {}
|
||||
|
||||
setActive(connected) {
|
||||
return this.active = connected;
|
||||
}
|
||||
|
||||
log() {}
|
||||
|
||||
}
|
||||
|
||||
UI.prototype.active = false;
|
216
proxy/util.js
|
@ -1,216 +0,0 @@
|
|||
/* exported Util, Params, DummyRateLimit */
|
||||
|
||||
/*
|
||||
A JavaScript WebRTC snowflake proxy
|
||||
|
||||
Contains helpers for parsing query strings and other utilities.
|
||||
*/
|
||||
|
||||
class Util {
|
||||
|
||||
static genSnowflakeID() {
|
||||
return Math.random().toString(36).substring(2);
|
||||
}
|
||||
|
||||
static hasWebRTC() {
|
||||
return typeof PeerConnection === 'function';
|
||||
}
|
||||
|
||||
static hasCookies() {
|
||||
return navigator.cookieEnabled;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class Parse {
|
||||
|
||||
// Parse a cookie data string (usually document.cookie). The return type is an
|
||||
// object mapping cookies names to values. Returns null on error.
|
||||
// http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-8747038
|
||||
static cookie(cookies) {
|
||||
var i, j, len, name, result, string, strings, value;
|
||||
result = {};
|
||||
strings = [];
|
||||
if (cookies) {
|
||||
strings = cookies.split(';');
|
||||
}
|
||||
for (i = 0, len = strings.length; i < len; i++) {
|
||||
string = strings[i];
|
||||
j = string.indexOf('=');
|
||||
if (-1 === j) {
|
||||
return null;
|
||||
}
|
||||
name = decodeURIComponent(string.substr(0, j).trim());
|
||||
value = decodeURIComponent(string.substr(j + 1).trim());
|
||||
if (!(name in result)) {
|
||||
result[name] = value;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Parse an address in the form 'host:port'. Returns an Object with keys 'host'
|
||||
// (String) and 'port' (int). Returns null on error.
|
||||
static address(spec) {
|
||||
var host, m, port;
|
||||
m = null;
|
||||
if (!m) {
|
||||
// IPv6 syntax.
|
||||
m = spec.match(/^\[([\0-9a-fA-F:.]+)\]:([0-9]+)$/);
|
||||
}
|
||||
if (!m) {
|
||||
// IPv4 syntax.
|
||||
m = spec.match(/^([0-9.]+):([0-9]+)$/);
|
||||
}
|
||||
if (!m) {
|
||||
// TODO: Domain match
|
||||
return null;
|
||||
}
|
||||
host = m[1];
|
||||
port = parseInt(m[2], 10);
|
||||
if (isNaN(port) || port < 0 || port > 65535) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
host: host,
|
||||
port: port
|
||||
};
|
||||
}
|
||||
|
||||
// Parse a count of bytes. A suffix of 'k', 'm', or 'g' (or uppercase)
|
||||
// does what you would think. Returns null on error.
|
||||
static byteCount(spec) {
|
||||
let matches = spec.match(/^(\d+(?:\.\d*)?)(\w*)$/);
|
||||
if (matches === null) {
|
||||
return null;
|
||||
}
|
||||
let count = Number(matches[1]);
|
||||
if (isNaN(count)) {
|
||||
return null;
|
||||
}
|
||||
const UNITS = new Map([
|
||||
['', 1],
|
||||
['k', 1024],
|
||||
['m', 1024*1024],
|
||||
['g', 1024*1024*1024],
|
||||
]);
|
||||
let unit = matches[2].toLowerCase();
|
||||
if (!UNITS.has(unit)) {
|
||||
return null;
|
||||
}
|
||||
let multiplier = UNITS.get(unit);
|
||||
return count * multiplier;
|
||||
}
|
||||
|
||||
// Parse a connection-address out of the "c=" Connection Data field of a
|
||||
// session description. Return undefined if none is found.
|
||||
// https://tools.ietf.org/html/rfc4566#section-5.7
|
||||
static ipFromSDP(sdp) {
|
||||
var i, len, m, pattern, ref;
|
||||
ref = [/^c=IN IP4 ([\d.]+)(?:(?:\/\d+)?\/\d+)?(:? |$)/m, /^c=IN IP6 ([0-9A-Fa-f:.]+)(?:\/\d+)?(:? |$)/m];
|
||||
for (i = 0, len = ref.length; i < len; i++) {
|
||||
pattern = ref[i];
|
||||
m = pattern.exec(sdp);
|
||||
if (m != null) {
|
||||
return m[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class Params {
|
||||
|
||||
static getBool(query, param, defaultValue) {
|
||||
if (!query.has(param)) {
|
||||
return defaultValue;
|
||||
}
|
||||
var val;
|
||||
val = query.get(param);
|
||||
if ('true' === val || '1' === val || '' === val) {
|
||||
return true;
|
||||
}
|
||||
if ('false' === val || '0' === val) {
|
||||
return false;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Get an object value and parse it as a byte count. Example byte counts are
|
||||
// '100' and '1.3m'. Returns |defaultValue| if param is not a key. Return null
|
||||
// on a parsing error.
|
||||
static getByteCount(query, param, defaultValue) {
|
||||
if (!query.has(param)) {
|
||||
return defaultValue;
|
||||
}
|
||||
return Parse.byteCount(query.get(param));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class BucketRateLimit {
|
||||
|
||||
constructor(capacity, time) {
|
||||
this.capacity = capacity;
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
age() {
|
||||
var delta, now;
|
||||
now = new Date();
|
||||
delta = (now - this.lastUpdate) / 1000.0;
|
||||
this.lastUpdate = now;
|
||||
this.amount -= delta * this.capacity / this.time;
|
||||
if (this.amount < 0.0) {
|
||||
return this.amount = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
update(n) {
|
||||
this.age();
|
||||
this.amount += n;
|
||||
return this.amount <= this.capacity;
|
||||
}
|
||||
|
||||
// How many seconds in the future will the limit expire?
|
||||
when() {
|
||||
this.age();
|
||||
return (this.amount - this.capacity) / (this.capacity / this.time);
|
||||
}
|
||||
|
||||
isLimited() {
|
||||
this.age();
|
||||
return this.amount > this.capacity;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
BucketRateLimit.prototype.amount = 0.0;
|
||||
|
||||
BucketRateLimit.prototype.lastUpdate = new Date();
|
||||
|
||||
|
||||
// A rate limiter that never limits.
|
||||
class DummyRateLimit {
|
||||
|
||||
constructor(capacity, time) {
|
||||
this.capacity = capacity;
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
update() {
|
||||
return true;
|
||||
}
|
||||
|
||||
when() {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
isLimited() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
/* global chrome, Popup */
|
||||
|
||||
// Fill i18n in HTML
|
||||
window.onload = () => {
|
||||
Popup.fill(document.body, (m) => {
|
||||
return chrome.i18n.getMessage(m);
|
||||
});
|
||||
};
|
||||
|
||||
const port = chrome.runtime.connect({
|
||||
name: "popup"
|
||||
});
|
||||
|
||||
port.onMessage.addListener((m) => {
|
||||
const { active, enabled, total, missingFeature } = m;
|
||||
const popup = new Popup();
|
||||
|
||||
if (missingFeature) {
|
||||
popup.setEnabled(false);
|
||||
popup.setActive(false);
|
||||
popup.setStatusText(chrome.i18n.getMessage('popupStatusOff'));
|
||||
popup.setStatusDesc(chrome.i18n.getMessage(missingFeature), true);
|
||||
popup.hideButton();
|
||||
return;
|
||||
}
|
||||
|
||||
const clients = active ? 1 : 0;
|
||||
|
||||
if (enabled) {
|
||||
popup.setChecked(true);
|
||||
if (clients > 0) {
|
||||
popup.setStatusText(chrome.i18n.getMessage('popupStatusOn', String(clients)));
|
||||
} else {
|
||||
popup.setStatusText(chrome.i18n.getMessage('popupStatusReady'));
|
||||
}
|
||||
popup.setStatusDesc((total > 0) ? chrome.i18n.getMessage('popupDescOn', String(total)) : '');
|
||||
} else {
|
||||
popup.setChecked(false);
|
||||
popup.setStatusText(chrome.i18n.getMessage('popupStatusOff'));
|
||||
popup.setStatusDesc("");
|
||||
}
|
||||
popup.setEnabled(enabled);
|
||||
popup.setActive(active);
|
||||
});
|
||||
|
||||
document.addEventListener('change', (event) => {
|
||||
port.postMessage({ enabled: event.target.checked });
|
||||
})
|
|
@ -1,24 +0,0 @@
|
|||
{
|
||||
"manifest_version": 2,
|
||||
"name": "Snowflake",
|
||||
"version": "0.2.2",
|
||||
"description": "__MSG_appDesc__",
|
||||
"default_locale": "en_US",
|
||||
"background": {
|
||||
"scripts": [
|
||||
"snowflake.js"
|
||||
],
|
||||
"persistent": true
|
||||
},
|
||||
"browser_action": {
|
||||
"default_icon": {
|
||||
"48": "assets/toolbar-on-48.png",
|
||||
"96": "assets/toolbar-on-96.png"
|
||||
},
|
||||
"default_title": "Snowflake",
|
||||
"default_popup": "embed.html"
|
||||
},
|
||||
"permissions": [
|
||||
"storage"
|
||||
]
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
/*
|
||||
Only websocket-specific stuff.
|
||||
*/
|
||||
|
||||
class WS {
|
||||
|
||||
// Build an escaped URL string from unescaped components. Only scheme and host
|
||||
// are required. See RFC 3986, section 3.
|
||||
static buildUrl(scheme, host, port, path, params) {
|
||||
var parts;
|
||||
parts = [];
|
||||
parts.push(encodeURIComponent(scheme));
|
||||
parts.push('://');
|
||||
// If it contains a colon but no square brackets, treat it as IPv6.
|
||||
if (host.match(/:/) && !host.match(/[[\]]/)) {
|
||||
parts.push('[');
|
||||
parts.push(host);
|
||||
parts.push(']');
|
||||
} else {
|
||||
parts.push(encodeURIComponent(host));
|
||||
}
|
||||
if (void 0 !== port && this.DEFAULT_PORTS[scheme] !== port) {
|
||||
parts.push(':');
|
||||
parts.push(encodeURIComponent(port.toString()));
|
||||
}
|
||||
if (void 0 !== path && '' !== path) {
|
||||
if (!path.match(/^\//)) {
|
||||
path = '/' + path;
|
||||
}
|
||||
path = path.replace(/[^/]+/, function(m) {
|
||||
return encodeURIComponent(m);
|
||||
});
|
||||
parts.push(path);
|
||||
}
|
||||
if (void 0 !== params) {
|
||||
parts.push('?');
|
||||
parts.push(new URLSearchParams(params).toString());
|
||||
}
|
||||
return parts.join('');
|
||||
}
|
||||
|
||||
static makeWebsocket(addr, params) {
|
||||
var url, ws, wsProtocol;
|
||||
wsProtocol = this.WSS_ENABLED ? 'wss' : 'ws';
|
||||
url = this.buildUrl(wsProtocol, addr.host, addr.port, '/', params);
|
||||
ws = new WebSocket(url);
|
||||
/*
|
||||
'User agents can use this as a hint for how to handle incoming binary data:
|
||||
if the attribute is set to 'blob', it is safe to spool it to disk, and if it
|
||||
is set to 'arraybuffer', it is likely more efficient to keep the data in
|
||||
memory.'
|
||||
*/
|
||||
ws.binaryType = 'arraybuffer';
|
||||
return ws;
|
||||
}
|
||||
|
||||
static probeWebsocket(addr) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const ws = WS.makeWebsocket(addr);
|
||||
ws.onopen = () => {
|
||||
resolve();
|
||||
ws.close();
|
||||
};
|
||||
ws.onerror = () => {
|
||||
reject();
|
||||
ws.close();
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
WS.WSS_ENABLED = true;
|
||||
|
||||
WS.DEFAULT_PORTS = {
|
||||
http: 80,
|
||||
https: 443
|
||||
};
|