tor-commits
Threads by month
- ----- 2026 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- 1 participants
- 216155 discussions
[tor-browser/tor-browser-78.12.0esr-10.5-1] Bug 21724: Make Firefox and Tor Browser distinct macOS apps
by sysrqb@torproject.org 09 Jul '21
by sysrqb@torproject.org 09 Jul '21
09 Jul '21
commit 3b5db6aa16a27cf306cce1e4f6ff22fa84c802ad
Author: teor <teor2345(a)gmail.com>
Date: Mon Mar 13 23:06:23 2017 +1100
Bug 21724: Make Firefox and Tor Browser distinct macOS apps
When macOS opens a document or selects a default browser, it sometimes
uses the CFBundleSignature. Changing from the Firefox MOZB signature to
a different signature TORB allows macOS to distinguish between Firefox
and Tor Browser.
---
browser/app/Makefile.in | 2 +-
browser/app/macbuild/Contents/Info.plist.in | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/browser/app/Makefile.in b/browser/app/Makefile.in
index 1aec6541fc0f..6770319f1866 100644
--- a/browser/app/Makefile.in
+++ b/browser/app/Makefile.in
@@ -103,5 +103,5 @@ ifdef MOZ_UPDATER
mv -f '$(dist_dest)/Contents/MacOS/updater.app/Contents/MacOS/org.mozilla.updater' '$(dist_dest)/Contents/Library/LaunchServices'
ln -s ../../../../Library/LaunchServices/org.mozilla.updater '$(dist_dest)/Contents/MacOS/updater.app/Contents/MacOS/org.mozilla.updater'
endif
- printf APPLMOZB > '$(dist_dest)/Contents/PkgInfo'
+ printf APPLTORB > '$(dist_dest)/Contents/PkgInfo'
endif
diff --git a/browser/app/macbuild/Contents/Info.plist.in b/browser/app/macbuild/Contents/Info.plist.in
index f6791ea48125..95b3bc83905c 100644
--- a/browser/app/macbuild/Contents/Info.plist.in
+++ b/browser/app/macbuild/Contents/Info.plist.in
@@ -179,7 +179,7 @@
<key>CFBundleShortVersionString</key>
<string>%APP_VERSION%</string>
<key>CFBundleSignature</key>
- <string>MOZB</string>
+ <string>TORB</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
1
0
[tor-browser/tor-browser-78.12.0esr-10.5-1] Bug 19121: reinstate the update.xml hash check
by sysrqb@torproject.org 09 Jul '21
by sysrqb@torproject.org 09 Jul '21
09 Jul '21
commit fe1d214fc67e1174a7ae2b01539bc4817f6a32d6
Author: Kathy Brade <brade(a)pearlcrescent.com>
Date: Mon Apr 23 15:22:57 2018 -0400
Bug 19121: reinstate the update.xml hash check
Revert most changes from Mozilla Bug 1373267 "Remove hashFunction and
hashValue attributes from nsIUpdatePatch and code related to these
attributes." Changes to the tests were not reverted; the tests have
been changed significantly and we do not run automated updater tests
for Tor Browser at this time.
Also partial revert of commit f1241db6986e4b54473a1ed870f7584c75d51122.
Revert the nsUpdateService.js changes from Mozilla Bug 862173 "don't
verify mar file hash when using mar signing to verify the mar file
(lessens main thread I/O)."
Changes to the tests were not reverted; the tests have been changed
significantly and we do not run automated updater tests for
Tor Browser at this time.
We kept the addition to the AppConstants API in case other JS code
references it in the future.
---
toolkit/modules/AppConstants.jsm | 7 ++++
toolkit/mozapps/update/UpdateService.jsm | 63 ++++++++++++++++++++++++++++-
toolkit/mozapps/update/UpdateTelemetry.jsm | 1 +
toolkit/mozapps/update/nsIUpdateService.idl | 11 +++++
4 files changed, 81 insertions(+), 1 deletion(-)
diff --git a/toolkit/modules/AppConstants.jsm b/toolkit/modules/AppConstants.jsm
index cd8ca2659626..84516f0d4c66 100644
--- a/toolkit/modules/AppConstants.jsm
+++ b/toolkit/modules/AppConstants.jsm
@@ -212,6 +212,13 @@ this.AppConstants = Object.freeze({
false,
#endif
+ MOZ_VERIFY_MAR_SIGNATURE:
+#ifdef MOZ_VERIFY_MAR_SIGNATURE
+ true,
+#else
+ false,
+#endif
+
MOZ_MAINTENANCE_SERVICE:
#ifdef MOZ_MAINTENANCE_SERVICE
true,
diff --git a/toolkit/mozapps/update/UpdateService.jsm b/toolkit/mozapps/update/UpdateService.jsm
index 1dc86a073646..ead961ab5252 100644
--- a/toolkit/mozapps/update/UpdateService.jsm
+++ b/toolkit/mozapps/update/UpdateService.jsm
@@ -742,6 +742,20 @@ function LOG(string) {
}
}
+/**
+ * Convert a string containing binary values to hex.
+ */
+function binaryToHex(input) {
+ var result = "";
+ for (var i = 0; i < input.length; ++i) {
+ var hex = input.charCodeAt(i).toString(16);
+ if (hex.length == 1)
+ hex = "0" + hex;
+ result += hex;
+ }
+ return result;
+}
+
/**
* Gets the specified directory at the specified hierarchy under the
* update root directory and creates it if it doesn't exist.
@@ -1534,6 +1548,8 @@ function UpdatePatch(patch) {
}
break;
case "finalURL":
+ case "hashFunction":
+ case "hashValue":
case "state":
case "type":
case "URL":
@@ -1553,6 +1569,8 @@ UpdatePatch.prototype = {
// over writing nsIUpdatePatch attributes.
_attrNames: [
"errorCode",
+ "hashFunction",
+ "hashValue",
"finalURL",
"selected",
"size",
@@ -1566,6 +1584,8 @@ UpdatePatch.prototype = {
*/
serialize: function UpdatePatch_serialize(updates) {
var patch = updates.createElementNS(URI_UPDATE_NS, "patch");
+ patch.setAttribute("hashFunction", this.hashFunction);
+ patch.setAttribute("hashValue", this.hashValue);
patch.setAttribute("size", this.size);
patch.setAttribute("type", this.type);
patch.setAttribute("URL", this.URL);
@@ -4315,7 +4335,42 @@ Downloader.prototype = {
}
LOG("Downloader:_verifyDownload downloaded size == expected size.");
- return true;
+ let fileStream = Cc["@mozilla.org/network/file-input-stream;1"].
+ createInstance(Ci.nsIFileInputStream);
+ fileStream.init(destination, FileUtils.MODE_RDONLY, FileUtils.PERMS_FILE, 0);
+
+ let digest;
+ try {
+ let hash = Cc["@mozilla.org/security/hash;1"].
+ createInstance(Ci.nsICryptoHash);
+ var hashFunction = Ci.nsICryptoHash[this._patch.hashFunction.toUpperCase()];
+ if (hashFunction == undefined) {
+ throw Cr.NS_ERROR_UNEXPECTED;
+ }
+ hash.init(hashFunction);
+ hash.updateFromStream(fileStream, -1);
+ // NOTE: For now, we assume that the format of _patch.hashValue is hex
+ // encoded binary (such as what is typically output by programs like
+ // sha1sum). In the future, this may change to base64 depending on how
+ // we choose to compute these hashes.
+ digest = binaryToHex(hash.finish(false));
+ } catch (e) {
+ LOG("Downloader:_verifyDownload - failed to compute hash of the " +
+ "downloaded update archive");
+ digest = "";
+ }
+
+ fileStream.close();
+
+ if (digest == this._patch.hashValue.toLowerCase()) {
+ LOG("Downloader:_verifyDownload hashes match.");
+ return true;
+ }
+
+ LOG("Downloader:_verifyDownload hashes do not match. ");
+ AUSTLMY.pingDownloadCode(this.isCompleteUpdate,
+ AUSTLMY.DWNLD_ERR_VERIFY_NO_HASH_MATCH);
+ return false;
},
/**
@@ -4889,6 +4944,9 @@ Downloader.prototype = {
" is higher than patch size: " +
this._patch.size
);
+ // It's important that we use a different code than
+ // NS_ERROR_CORRUPTED_CONTENT so that tests can verify the difference
+ // between a hash error and a wrong download error.
AUSTLMY.pingDownloadCode(
this.isCompleteUpdate,
AUSTLMY.DWNLD_ERR_PATCH_SIZE_LARGER
@@ -4907,6 +4965,9 @@ Downloader.prototype = {
" is not equal to expected patch size: " +
this._patch.size
);
+ // It's important that we use a different code than
+ // NS_ERROR_CORRUPTED_CONTENT so that tests can verify the difference
+ // between a hash error and a wrong download error.
AUSTLMY.pingDownloadCode(
this.isCompleteUpdate,
AUSTLMY.DWNLD_ERR_PATCH_SIZE_NOT_EQUAL
diff --git a/toolkit/mozapps/update/UpdateTelemetry.jsm b/toolkit/mozapps/update/UpdateTelemetry.jsm
index 6f560b07cfe7..b6c71b2ef8d6 100644
--- a/toolkit/mozapps/update/UpdateTelemetry.jsm
+++ b/toolkit/mozapps/update/UpdateTelemetry.jsm
@@ -180,6 +180,7 @@ var AUSTLMY = {
DWNLD_ERR_VERIFY_NO_REQUEST: 13,
DWNLD_ERR_VERIFY_PATCH_SIZE_NOT_EQUAL: 14,
DWNLD_ERR_WRITE_FAILURE: 15,
+ DWNLD_ERR_VERIFY_NO_HASH_MATCH: 16,
// Temporary failure code to see if there are failures without an update phase
DWNLD_UNKNOWN_PHASE_ERR_WRITE_FAILURE: 40,
diff --git a/toolkit/mozapps/update/nsIUpdateService.idl b/toolkit/mozapps/update/nsIUpdateService.idl
index 5e4cc63c3547..47bb27b17d41 100644
--- a/toolkit/mozapps/update/nsIUpdateService.idl
+++ b/toolkit/mozapps/update/nsIUpdateService.idl
@@ -39,6 +39,17 @@ interface nsIUpdatePatch : nsISupports
*/
attribute AString finalURL;
+ /**
+ * The hash function to use when determining this file's integrity
+ */
+ attribute AString hashFunction;
+
+ /**
+ * The value of the hash function named above that should be computed if
+ * this file is not corrupt.
+ */
+ attribute AString hashValue;
+
/**
* The size of this file, in bytes.
*/
1
0
[tor-browser/tor-browser-78.12.0esr-10.5-1] Bug 16940: After update, load local change notes.
by sysrqb@torproject.org 09 Jul '21
by sysrqb@torproject.org 09 Jul '21
09 Jul '21
commit d514e4a9c1e68a283c0fe46e3f5744d492f027f3
Author: Kathy Brade <brade(a)pearlcrescent.com>
Date: Wed Nov 25 11:36:20 2015 -0500
Bug 16940: After update, load local change notes.
Add an about:tbupdate page that displays the first section from
TorBrowser/Docs/ChangeLog.txt and includes a link to the remote
post-update page (typically our blog entry for the release).
Always load about:tbupdate in a content process, but implement the
code that reads the file system (changelog) in the chrome process
for compatibility with future sandboxing efforts.
Also fix bug 29440. Now about:tbupdate is styled as a fairly simple
changelog page that is designed to be displayed via a link that is on
about:tor.
---
browser/actors/AboutTBUpdateChild.jsm | 53 ++++++++
browser/actors/moz.build | 5 +
.../base/content/abouttbupdate/aboutTBUpdate.css | 74 ++++++++++++
.../base/content/abouttbupdate/aboutTBUpdate.js | 10 ++
.../base/content/abouttbupdate/aboutTBUpdate.xhtml | 39 ++++++
browser/base/content/browser-siteIdentity.js | 2 +-
browser/base/content/browser.js | 4 +
browser/base/jar.mn | 5 +
browser/components/BrowserContentHandler.jsm | 55 ++++++---
browser/components/BrowserGlue.jsm | 25 ++++
browser/components/about/AboutRedirector.cpp | 6 +
browser/components/about/components.conf | 3 +
browser/components/moz.build | 5 +-
.../locales/en-US/chrome/browser/aboutTBUpdate.dtd | 8 ++
browser/locales/jar.mn | 3 +
browser/modules/AboutTBUpdate.jsm | 134 +++++++++++++++++++++
browser/modules/moz.build | 5 +
17 files changed, 420 insertions(+), 16 deletions(-)
diff --git a/browser/actors/AboutTBUpdateChild.jsm b/browser/actors/AboutTBUpdateChild.jsm
new file mode 100644
index 000000000000..91bb4dbba888
--- /dev/null
+++ b/browser/actors/AboutTBUpdateChild.jsm
@@ -0,0 +1,53 @@
+// Copyright (c) 2019, The Tor Project, Inc.
+// See LICENSE for licensing information.
+//
+// vim: set sw=2 sts=2 ts=8 et syntax=javascript:
+
+var EXPORTED_SYMBOLS = ["AboutTBUpdateChild"];
+
+const {ActorChild} = ChromeUtils.import("resource://gre/modules/ActorChild.jsm");
+
+class AboutTBUpdateChild extends ActorChild {
+ receiveMessage(aMessage) {
+ if (aMessage.name == "AboutTBUpdate:Update")
+ this.onUpdate(aMessage.data);
+ }
+
+ handleEvent(aEvent) {
+ switch (aEvent.type) {
+ case "AboutTBUpdateLoad":
+ this.onPageLoad();
+ break;
+ case "pagehide":
+ this.onPageHide(aEvent);
+ break;
+ }
+ }
+
+ // aData may contain the following string properties:
+ // version
+ // releaseDate
+ // moreInfoURL
+ // releaseNotes
+ onUpdate(aData) {
+ let doc = this.content.document;
+ doc.getElementById("version-content").textContent = aData.version;
+ if (aData.releaseDate) {
+ doc.body.setAttribute("havereleasedate", "true");
+ doc.getElementById("releasedate-content").textContent = aData.releaseDate;
+ }
+ if (aData.moreInfoURL)
+ doc.getElementById("infolink").setAttribute("href", aData.moreInfoURL);
+ doc.getElementById("releasenotes-content").textContent = aData.releaseNotes;
+ }
+
+ onPageLoad() {
+ this.mm.sendAsyncMessage("AboutTBUpdate:RequestUpdate");
+ }
+
+ onPageHide(aEvent) {
+ if (aEvent.target.defaultView.frameElement) {
+ return;
+ }
+ }
+}
diff --git a/browser/actors/moz.build b/browser/actors/moz.build
index 4b903146699e..e70f0f09fe3a 100644
--- a/browser/actors/moz.build
+++ b/browser/actors/moz.build
@@ -74,3 +74,8 @@ FINAL_TARGET_FILES.actors += [
'WebRTCChild.jsm',
'WebRTCParent.jsm',
]
+
+if CONFIG['TOR_BROWSER_UPDATE']:
+ FINAL_TARGET_FILES.actors += [
+ 'AboutTBUpdateChild.jsm',
+ ]
diff --git a/browser/base/content/abouttbupdate/aboutTBUpdate.css b/browser/base/content/abouttbupdate/aboutTBUpdate.css
new file mode 100644
index 000000000000..7c1a34b77f17
--- /dev/null
+++ b/browser/base/content/abouttbupdate/aboutTBUpdate.css
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2019, The Tor Project, Inc.
+ * See LICENSE for licensing information.
+ *
+ * vim: set sw=2 sts=2 ts=8 et syntax=css:
+ */
+
+:root {
+ --abouttor-text-color: white;
+ --abouttor-bg-toron-color: #420C5D;
+}
+
+body {
+ font-family: Helvetica, Arial, sans-serif;
+ color: var(--abouttor-text-color);
+ background-color: var(--abouttor-bg-toron-color);
+ background-attachment: fixed;
+ background-size: 100% 100%;
+}
+
+a {
+ color: var(--abouttor-text-color);
+}
+
+.two-column-grid {
+ display: inline-grid;
+ grid-template-columns: auto auto;
+ grid-column-gap: 50px;
+ margin: 10px 0px 0px 50px;
+}
+
+.two-column-grid div {
+ margin-top: 40px;
+ align-self: baseline; /* Align baseline of text across the row. */
+}
+
+.label-column {
+ font-size: 14px;
+ font-weight: 400;
+}
+
+/*
+ * Use a reduced top margin to bring the row that contains the
+ * "visit our website" link closer to the row that precedes it. This
+ * looks better because the "visit our website" row does not have a
+ * label in the left column.
+ */
+div.more-info-row {
+ margin-top: 5px;
+ font-size: 14px;
+}
+
+#version-content {
+ font-size: 50px;
+ font-weight: 300;
+}
+
+body:not([havereleasedate]) .release-date-cell {
+ display: none;
+}
+
+#releasedate-content {
+ font-size: 17px;
+}
+
+#releasenotes-label {
+ align-self: start; /* Anchor "Release Notes" label at the top. */
+}
+
+#releasenotes-content {
+ font-family: monospace;
+ font-size: 15px;
+ white-space: pre;
+}
diff --git a/browser/base/content/abouttbupdate/aboutTBUpdate.js b/browser/base/content/abouttbupdate/aboutTBUpdate.js
new file mode 100644
index 000000000000..da7553f0ae81
--- /dev/null
+++ b/browser/base/content/abouttbupdate/aboutTBUpdate.js
@@ -0,0 +1,10 @@
+// Copyright (c) 2019, The Tor Project, Inc.
+// See LICENSE for licensing information.
+//
+// vim: set sw=2 sts=2 ts=8 et syntax=javascript:
+
+
+addEventListener("load", () => {
+ let event = new CustomEvent("AboutTBUpdateLoad", { bubbles: true });
+ document.dispatchEvent(event);
+});
diff --git a/browser/base/content/abouttbupdate/aboutTBUpdate.xhtml b/browser/base/content/abouttbupdate/aboutTBUpdate.xhtml
new file mode 100644
index 000000000000..8489cfef5083
--- /dev/null
+++ b/browser/base/content/abouttbupdate/aboutTBUpdate.xhtml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!DOCTYPE html [
+ <!ENTITY % htmlDTD
+ PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "DTD/xhtml1-strict.dtd">
+ %htmlDTD;
+ <!ENTITY % globalDTD SYSTEM "chrome://global/locale/global.dtd">
+ %globalDTD;
+ <!ENTITY % tbUpdateDTD SYSTEM "chrome://browser/locale/aboutTBUpdate.dtd">
+ %tbUpdateDTD;
+]>
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+ <meta http-equiv="Content-Security-Policy" content="default-src chrome:; object-src 'none'" />
+ <title>&aboutTBUpdate.changelogTitle;</title>
+ <link rel="stylesheet" type="text/css"
+ href="chrome://browser/content/abouttbupdate/aboutTBUpdate.css"/>
+ <script src="chrome://browser/content/abouttbupdate/aboutTBUpdate.js"
+ type="text/javascript"/>
+</head>
+<body dir="&locale.dir;">
+<div class="two-column-grid">
+ <div class="label-column">&aboutTBUpdate.version;</div>
+ <div id="version-content"/>
+
+ <div class="label-column release-date-cell">&aboutTBUpdate.releaseDate;</div>
+ <div id="releasedate-content" class="release-date-cell"/>
+
+ <div class="more-info-row"/>
+ <div class="more-info-row">&aboutTBUpdate.linkPrefix;<a id="infolink">&aboutTBUpdate.linkLabel;</a>&aboutTBUpdate.linkSuffix;</div>
+
+ <div id="releasenotes-label"
+ class="label-column">&aboutTBUpdate.releaseNotes;</div>
+ <div id="releasenotes-content"></div>
+</div>
+</body>
+</html>
diff --git a/browser/base/content/browser-siteIdentity.js b/browser/base/content/browser-siteIdentity.js
index 29f95ae4129f..1d6f9555b33f 100644
--- a/browser/base/content/browser-siteIdentity.js
+++ b/browser/base/content/browser-siteIdentity.js
@@ -57,7 +57,7 @@ var gIdentityHandler = {
* RegExp used to decide if an about url should be shown as being part of
* the browser UI.
*/
- _secureInternalUIWhitelist: /^(?:accounts|addons|cache|certificate|config|crashes|downloads|license|logins|preferences|protections|rights|sessionrestore|support|welcomeback)(?:[?#]|$)/i,
+ _secureInternalUIWhitelist: (AppConstants.TOR_BROWSER_UPDATE ? /^(?:accounts|addons|cache|certificate|config|crashes|downloads|license|logins|preferences|protections|rights|sessionrestore|support|welcomeback|tor|tbupdate)(?:[?#]|$)/i : /^(?:accounts|addons|cache|certificate|config|crashes|downloads|license|logins|preferences|protections|rights|sessionrestore|support|welcomeback|tor)(?:[?#]|$)/i),
/**
* Whether the established HTTPS connection is considered "broken".
diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js
index 3c342dedd5d4..036d92e131da 100644
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -631,6 +631,10 @@ var gInitialPages = [
"about:newinstall",
];
+if (AppConstants.TOR_BROWSER_UPDATE) {
+ gInitialPages.push("about:tbupdate");
+}
+
function isInitialPage(url) {
if (!(url instanceof Ci.nsIURI)) {
try {
diff --git a/browser/base/jar.mn b/browser/base/jar.mn
index a2e1f9c259d2..df65349796b5 100644
--- a/browser/base/jar.mn
+++ b/browser/base/jar.mn
@@ -29,6 +29,11 @@ browser.jar:
content/browser/aboutTabCrashed.css (content/aboutTabCrashed.css)
content/browser/aboutTabCrashed.js (content/aboutTabCrashed.js)
content/browser/aboutTabCrashed.xhtml (content/aboutTabCrashed.xhtml)
+#ifdef TOR_BROWSER_UPDATE
+ content/browser/abouttbupdate/aboutTBUpdate.xhtml (content/abouttbupdate/aboutTBUpdate.xhtml)
+ content/browser/abouttbupdate/aboutTBUpdate.js (content/abouttbupdate/aboutTBUpdate.js)
+ content/browser/abouttbupdate/aboutTBUpdate.css (content/abouttbupdate/aboutTBUpdate.css)
+#endif
* content/browser/browser.css (content/browser.css)
content/browser/browser.js (content/browser.js)
* content/browser/browser.xhtml (content/browser.xhtml)
diff --git a/browser/components/BrowserContentHandler.jsm b/browser/components/BrowserContentHandler.jsm
index 9f5b6ab0218c..1cc1015414fc 100644
--- a/browser/components/BrowserContentHandler.jsm
+++ b/browser/components/BrowserContentHandler.jsm
@@ -650,6 +650,23 @@ nsBrowserContentHandler.prototype = {
}
}
+ // Retrieve the home page early so we can compare it against about:tor
+ // to decide whether or not we need an override page (second tab) after
+ // an update was applied.
+ var startPage = "";
+ try {
+ var choice = prefb.getIntPref("browser.startup.page");
+ if (choice == 1 || choice == 3) {
+ startPage = HomePage.get();
+ }
+ } catch (e) {
+ Cu.reportError(e);
+ }
+
+ if (startPage == "about:blank") {
+ startPage = "";
+ }
+
var override;
var overridePage = "";
var additionalPage = "";
@@ -701,6 +718,16 @@ nsBrowserContentHandler.prototype = {
// into account because that requires waiting for the session file
// to be read. If a crash occurs after updating, before restarting,
// we may open the startPage in addition to restoring the session.
+ //
+ // Tor Browser: Instead of opening the post-update "override page"
+ // directly, we ensure that about:tor will be opened in a special
+ // mode that notifies the user that their browser was updated.
+ // The about:tor page will provide a link to the override page
+ // where the user can learn more about the update, as well as a
+ // link to the Tor Browser changelog page (about:tbupdate). The
+ // override page URL comes from the openURL attribute within the
+ // updates.xml file or, if no showURL action is present, from the
+ // startup.homepage_override_url pref.
willRestoreSession = SessionStartup.isAutomaticRestoreEnabled();
overridePage = Services.urlFormatter.formatURLPref(
@@ -720,6 +747,20 @@ nsBrowserContentHandler.prototype = {
overridePage = overridePage.replace("%OLD_VERSION%", old_mstone);
overridePage = overridePage.replace("%OLD_TOR_BROWSER_VERSION%",
old_tbversion);
+#ifdef TOR_BROWSER_UPDATE
+ if (overridePage)
+ {
+ prefb.setCharPref("torbrowser.post_update.url", overridePage);
+ prefb.setBoolPref("torbrowser.post_update.shouldNotify", true);
+ // If the user's homepage is about:tor, we will inform them
+ // about the update on that page; otherwise, we arrange to
+ // open about:tor in a secondary tab.
+ if (startPage === "about:tor")
+ overridePage = "";
+ else
+ overridePage = "about:tor";
+ }
+#endif
break;
case OVERRIDE_NEW_BUILD_ID:
if (UpdateManager.activeUpdate) {
@@ -792,20 +833,6 @@ nsBrowserContentHandler.prototype = {
}
}
- var startPage = "";
- try {
- var choice = prefb.getIntPref("browser.startup.page");
- if (choice == 1 || choice == 3) {
- startPage = HomePage.get();
- }
- } catch (e) {
- Cu.reportError(e);
- }
-
- if (startPage == "about:blank") {
- startPage = "";
- }
-
let skipStartPage =
(override == OVERRIDE_NEW_PROFILE ||
override == OVERRIDE_ALTERNATE_PROFILE) &&
diff --git a/browser/components/BrowserGlue.jsm b/browser/components/BrowserGlue.jsm
index 0a3555f26432..3b7d8d6e0309 100644
--- a/browser/components/BrowserGlue.jsm
+++ b/browser/components/BrowserGlue.jsm
@@ -560,6 +560,22 @@ let LEGACY_ACTORS = {
},
};
+if (AppConstants.TOR_BROWSER_UPDATE) {
+ LEGACY_ACTORS["AboutTBUpdate"] = {
+ child: {
+ module: "resource:///actors/AboutTBUpdateChild.jsm",
+ events: {
+ "AboutTBUpdateLoad": {wantUntrusted: true},
+ "pagehide": {capture: true},
+ },
+ matches: ["about:tbupdate"],
+ messages: [
+ "AboutTBUpdate:Update",
+ ],
+ }
+ };
+}
+
(function earlyBlankFirstPaint() {
if (
AppConstants.platform == "macosx" ||
@@ -747,6 +763,11 @@ if (AppConstants.MOZ_CRASHREPORTER) {
});
}
+if (AppConstants.TOR_BROWSER_UPDATE) {
+ XPCOMUtils.defineLazyModuleGetter(this, "AboutTBUpdate",
+ "resource:///modules/AboutTBUpdate.jsm");
+}
+
XPCOMUtils.defineLazyGetter(this, "gBrandBundle", function() {
return Services.strings.createBundle(
"chrome://branding/locale/brand.properties"
@@ -2200,6 +2221,10 @@ BrowserGlue.prototype = {
AsanReporter.init();
}
+ if (AppConstants.TOR_BROWSER_UPDATE) {
+ AboutTBUpdate.init();
+ }
+
Sanitizer.onStartup();
this._scheduleStartupIdleTasks();
this._lateTasksIdleObserver = (idleService, topic, data) => {
diff --git a/browser/components/about/AboutRedirector.cpp b/browser/components/about/AboutRedirector.cpp
index 1471e10bf0db..933d519bd959 100644
--- a/browser/components/about/AboutRedirector.cpp
+++ b/browser/components/about/AboutRedirector.cpp
@@ -120,6 +120,12 @@ static const RedirEntry kRedirMap[] = {
nsIAboutModule::URI_CAN_LOAD_IN_PRIVILEGEDABOUT_PROCESS},
{"pioneer", "chrome://browser/content/pioneer.html",
nsIAboutModule::ALLOW_SCRIPT | nsIAboutModule::HIDE_FROM_ABOUTABOUT},
+#ifdef TOR_BROWSER_UPDATE
+ {"tbupdate", "chrome://browser/content/abouttbupdate/aboutTBUpdate.xhtml",
+ nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT |
+ nsIAboutModule::URI_MUST_LOAD_IN_CHILD | nsIAboutModule::ALLOW_SCRIPT |
+ nsIAboutModule::HIDE_FROM_ABOUTABOUT},
+#endif
};
static nsAutoCString GetAboutModuleName(nsIURI* aURI) {
diff --git a/browser/components/about/components.conf b/browser/components/about/components.conf
index bf0c6c096847..f31159d30e15 100644
--- a/browser/components/about/components.conf
+++ b/browser/components/about/components.conf
@@ -32,6 +32,9 @@ pages = [
'welcomeback',
]
+if defined('TOR_BROWSER_UPDATE'):
+ pages.append('tbupdate')
+
Classes = [
{
'cid': '{7e4bb6ad-2fc4-4dc6-89ef-23e8e5ccf980}',
diff --git a/browser/components/moz.build b/browser/components/moz.build
index c75c10b0c92d..cf3f566eba71 100644
--- a/browser/components/moz.build
+++ b/browser/components/moz.build
@@ -90,11 +90,14 @@ EXTRA_COMPONENTS += [
]
EXTRA_JS_MODULES += [
- 'BrowserContentHandler.jsm',
'BrowserGlue.jsm',
'distribution.js',
]
+EXTRA_PP_JS_MODULES += [
+ 'BrowserContentHandler.jsm',
+]
+
BROWSER_CHROME_MANIFESTS += [
'safebrowsing/content/test/browser.ini',
'tests/browser/browser.ini',
diff --git a/browser/locales/en-US/chrome/browser/aboutTBUpdate.dtd b/browser/locales/en-US/chrome/browser/aboutTBUpdate.dtd
new file mode 100644
index 000000000000..2d1e59b40eaf
--- /dev/null
+++ b/browser/locales/en-US/chrome/browser/aboutTBUpdate.dtd
@@ -0,0 +1,8 @@
+<!ENTITY aboutTBUpdate.changelogTitle "Tor Browser Changelog">
+<!ENTITY aboutTBUpdate.updated "Tor Browser has been updated.">
+<!ENTITY aboutTBUpdate.linkPrefix "For the most up-to-date information about this release, ">
+<!ENTITY aboutTBUpdate.linkLabel "visit our website">
+<!ENTITY aboutTBUpdate.linkSuffix ".">
+<!ENTITY aboutTBUpdate.version "Version">
+<!ENTITY aboutTBUpdate.releaseDate "Release Date">
+<!ENTITY aboutTBUpdate.releaseNotes "Release Notes">
diff --git a/browser/locales/jar.mn b/browser/locales/jar.mn
index ca892a187adf..31e2d3d870e6 100644
--- a/browser/locales/jar.mn
+++ b/browser/locales/jar.mn
@@ -20,6 +20,9 @@
locale/browser/accounts.properties (%chrome/browser/accounts.properties)
locale/browser/app-extension-fields.properties (%chrome/browser/app-extension-fields.properties)
+#ifdef TOR_BROWSER_UPDATE
+ locale/browser/aboutTBUpdate.dtd (%chrome/browser/aboutTBUpdate.dtd)
+#endif
locale/browser/browser.dtd (%chrome/browser/browser.dtd)
locale/browser/baseMenuOverlay.dtd (%chrome/browser/baseMenuOverlay.dtd)
locale/browser/browser.properties (%chrome/browser/browser.properties)
diff --git a/browser/modules/AboutTBUpdate.jsm b/browser/modules/AboutTBUpdate.jsm
new file mode 100644
index 000000000000..996e2e8394aa
--- /dev/null
+++ b/browser/modules/AboutTBUpdate.jsm
@@ -0,0 +1,134 @@
+// Copyright (c) 2019, The Tor Project, Inc.
+// See LICENSE for licensing information.
+//
+// vim: set sw=2 sts=2 ts=8 et syntax=javascript:
+
+"use strict";
+
+var Cc = Components.classes;
+var Ci = Components.interfaces;
+var Cu = Components.utils;
+
+this.EXPORTED_SYMBOLS = [ "AboutTBUpdate" ];
+
+Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/NetUtil.jsm");
+
+const kRequestUpdateMessageName = "AboutTBUpdate:RequestUpdate";
+const kSendUpdateMessageName = "AboutTBUpdate:Update";
+
+#expand const TOR_BROWSER_VERSION = __TOR_BROWSER_VERSION_QUOTED__;
+
+/**
+ * This code provides services to the about:tbupdate page. Whenever
+ * about:tbupdate needs to do something chrome-privileged, it sends a
+ * message that's handled here. It is modeled after Mozilla's about:home
+ * implementation.
+ */
+var AboutTBUpdate = {
+ init: function() {
+ Services.mm.addMessageListener(kRequestUpdateMessageName, this);
+ },
+
+ receiveMessage: function(aMessage) {
+ if (aMessage.name == kRequestUpdateMessageName)
+ this.sendAboutTBUpdateData(aMessage.target);
+ },
+
+ sendAboutTBUpdateData: function(aTarget) {
+ let data = this.releaseNoteInfo;
+ data.moreInfoURL = this.moreInfoURL;
+ if (aTarget && aTarget.messageManager) {
+ aTarget.messageManager.sendAsyncMessage(kSendUpdateMessageName, data);
+ } else {
+ Services.mm.broadcastAsyncMessage(kSendUpdateMessageName, data);
+ }
+ },
+
+ get moreInfoURL() {
+ try {
+ return Services.prefs.getCharPref("torbrowser.post_update.url");
+ } catch (e) {}
+
+ // Use the default URL as a fallback.
+ return Services.urlFormatter.formatURLPref("startup.homepage_override_url");
+ },
+
+ // Read the text from the beginning of the changelog file that is located
+ // at TorBrowser/Docs/ChangeLog.txt and return an object that contains
+ // the following properties:
+ // version e.g., Tor Browser 8.5
+ // releaseDate e.g., March 31 2019
+ // releaseNotes details of changes (lines 2 - end of ChangeLog.txt)
+ // We attempt to parse the first line of ChangeLog.txt to extract the
+ // version and releaseDate. If parsing fails, we return the entire first
+ // line in version and omit releaseDate.
+ //
+ // On Mac OS, when building with --enable-tor-browser-data-outside-app-dir
+ // to support Gatekeeper signing, the ChangeLog.txt file is located in
+ // TorBrowser.app/Contents/Resources/TorBrowser/Docs/.
+ get releaseNoteInfo() {
+ let info = {};
+
+ try {
+#ifdef TOR_BROWSER_DATA_OUTSIDE_APP_DIR
+ // "XREExeF".parent is the directory that contains firefox, i.e.,
+ // Browser/ or, on Mac OS, TorBrowser.app/Contents/MacOS/.
+ let f = Services.dirsvc.get("XREExeF", Ci.nsIFile).parent;
+#ifdef XP_MACOSX
+ f = f.parent;
+ f.append("Resources");
+#endif
+ f.append("TorBrowser");
+#else
+ // "DefProfRt" is .../TorBrowser/Data/Browser
+ let f = Cc["@mozilla.org/file/directory_service;1"]
+ .getService(Ci.nsIProperties).get("DefProfRt", Ci.nsIFile);
+ f = f.parent.parent; // Remove "Data/Browser"
+#endif
+ f.append("Docs");
+ f.append("ChangeLog.txt");
+
+ let fs = Cc["@mozilla.org/network/file-input-stream;1"]
+ .createInstance(Ci.nsIFileInputStream);
+ fs.init(f, -1, 0, 0);
+ let s = NetUtil.readInputStreamToString(fs, fs.available());
+ fs.close();
+
+ // Truncate at the first empty line.
+ s = s.replace(/[\r\n][\r\n][\s\S]*$/m, "");
+
+ // Split into first line (version plus releaseDate) and
+ // remainder (releaseNotes).
+ // This first match() uses multiline mode with two capture groups:
+ // first line: (.*$)
+ // remaining lines: ([\s\S]+)
+ // [\s\S] matches all characters including end of line. This trick
+ // is needed because when using JavaScript regex in multiline mode,
+ // . does not match an end of line character.
+ let matchArray = s.match(/(.*$)\s*([\s\S]+)/m);
+ if (matchArray && (matchArray.length == 3)) {
+ info.releaseNotes = matchArray[2];
+ let line1 = matchArray[1];
+ // Extract the version and releaseDate. The first line looks like:
+ // Tor Browser 8.5 -- May 1 2019
+ // The regex uses two capture groups:
+ // text that does not include a hyphen: (^[^-]*)
+ // remaining text: (.*$)
+ // In between we match optional whitespace, one or more hyphens, and
+ // optional whitespace by using: \s*-+\s*
+ matchArray = line1.match(/(^[^-]*)\s*-+\s*(.*$)/);
+ if (matchArray && (matchArray.length == 3)) {
+ info.version = matchArray[1];
+ info.releaseDate = matchArray[2];
+ } else {
+ info.version = line1; // Match failed: return entire line in version.
+ }
+ } else {
+ info.releaseNotes = s; // Only one line: use as releaseNotes.
+ }
+ } catch (e) {}
+
+ return info;
+ },
+};
diff --git a/browser/modules/moz.build b/browser/modules/moz.build
index 88f2a55d6f49..61fe5371e48f 100644
--- a/browser/modules/moz.build
+++ b/browser/modules/moz.build
@@ -160,6 +160,11 @@ EXTRA_JS_MODULES += [
'ZoomUI.jsm',
]
+if CONFIG['TOR_BROWSER_UPDATE']:
+ EXTRA_PP_JS_MODULES += [
+ 'AboutTBUpdate.jsm',
+ ]
+
if CONFIG['MOZ_ASAN_REPORTER']:
EXTRA_JS_MODULES += [
'AsanReporter.jsm',
1
0
[tor-browser/tor-browser-78.12.0esr-10.5-1] Bug 13379: Sign our MAR files.
by sysrqb@torproject.org 09 Jul '21
by sysrqb@torproject.org 09 Jul '21
09 Jul '21
commit a944f69f3f2e380d86e5db6e1ba3cf22717cecf4
Author: Kathy Brade <brade(a)pearlcrescent.com>
Date: Wed Dec 17 16:37:11 2014 -0500
Bug 13379: Sign our MAR files.
Configure with --enable-verify-mar (when updating, require a valid
signature on the MAR file before it is applied).
Use the Tor Browser version instead of the Firefox version inside the
MAR file info block (necessary to prevent downgrade attacks).
Use NSS on all platforms for checking MAR signatures (instead of using
OS-native APIs, which Mozilla does on Mac OS and Windows). So that the
NSS and NSPR libraries the updater depends on can be found at runtime,
we add the firefox directory to the shared library search path on macOS.
On Linux, rpath is used by Mozilla to solve that problem, but that
approach won't work on macOS because the updater executable is copied
during the update process to a location that is under TorBrowser-Data,
and the location of TorBrowser-Data varies.
Also includes the fix for bug 18900.
---
.mozconfig | 1 +
.mozconfig-asan | 1 +
.mozconfig-mac | 1 +
.mozconfig-mingw | 1 +
modules/libmar/tool/mar.c | 6 +--
modules/libmar/tool/moz.build | 12 ++++--
modules/libmar/verify/moz.build | 14 +++---
.../mozapps/update/updater/updater-common.build | 24 +++++++++--
toolkit/mozapps/update/updater/updater.cpp | 25 +++++++----
toolkit/xre/moz.build | 3 ++
toolkit/xre/nsUpdateDriver.cpp | 50 ++++++++++++++++++++++
11 files changed, 113 insertions(+), 25 deletions(-)
diff --git a/.mozconfig b/.mozconfig
index 18cd1f9b6487..c50c57d410de 100755
--- a/.mozconfig
+++ b/.mozconfig
@@ -37,3 +37,4 @@ ac_add_options MOZ_TELEMETRY_REPORTING=
ac_add_options --disable-tor-launcher
ac_add_options --with-tor-browser-version=dev-build
ac_add_options --disable-tor-browser-update
+ac_add_options --enable-verify-mar
diff --git a/.mozconfig-asan b/.mozconfig-asan
index 98ea6ac6f3fe..8bee813bfee8 100644
--- a/.mozconfig-asan
+++ b/.mozconfig-asan
@@ -30,6 +30,7 @@ ac_add_options --enable-official-branding
ac_add_options --enable-default-toolkit=cairo-gtk3
ac_add_options --enable-tor-browser-update
+ac_add_options --enable-verify-mar
ac_add_options --disable-strip
ac_add_options --disable-install-strip
diff --git a/.mozconfig-mac b/.mozconfig-mac
index 26e2b6b92fdb..5b4624ef1f67 100644
--- a/.mozconfig-mac
+++ b/.mozconfig-mac
@@ -43,6 +43,7 @@ ac_add_options --disable-debug
ac_add_options --enable-tor-browser-data-outside-app-dir
ac_add_options --enable-tor-browser-update
+ac_add_options --enable-verify-mar
ac_add_options --disable-crashreporter
ac_add_options --disable-webrtc
diff --git a/.mozconfig-mingw b/.mozconfig-mingw
index 3ec6ff18a3e9..ce6ace1dad67 100644
--- a/.mozconfig-mingw
+++ b/.mozconfig-mingw
@@ -15,6 +15,7 @@ ac_add_options --enable-strip
ac_add_options --enable-official-branding
ac_add_options --enable-tor-browser-update
+ac_add_options --enable-verify-mar
ac_add_options --disable-bits-download
# Let's make sure no preference is enabling either Adobe's or Google's CDM.
diff --git a/modules/libmar/tool/mar.c b/modules/libmar/tool/mar.c
index 0bf2cb4bd1d4..ea2b79924914 100644
--- a/modules/libmar/tool/mar.c
+++ b/modules/libmar/tool/mar.c
@@ -65,7 +65,7 @@ static void print_usage() {
"signed_input_archive.mar base_64_encoded_signature_file "
"changed_signed_output.mar\n");
printf("(i) is the index of the certificate to extract\n");
-# if defined(XP_MACOSX) || (defined(XP_WIN) && !defined(MAR_NSS))
+# if (defined(XP_MACOSX) || defined(XP_WIN)) && !defined(MAR_NSS)
printf("Verify a MAR file:\n");
printf(" mar [-C workingDir] -D DERFilePath -v signed_archive.mar\n");
printf(
@@ -149,7 +149,7 @@ int main(int argc, char** argv) {
memset((void*)certBuffers, 0, sizeof(certBuffers));
#endif
#if !defined(NO_SIGN_VERIFY) && \
- ((!defined(MAR_NSS) && defined(XP_WIN)) || defined(XP_MACOSX))
+ (!defined(MAR_NSS) && (defined(XP_WIN) || defined(XP_MACOSX)))
memset(DERFilePaths, 0, sizeof(DERFilePaths));
memset(fileSizes, 0, sizeof(fileSizes));
#endif
@@ -181,7 +181,7 @@ int main(int argc, char** argv) {
argc -= 2;
}
#if !defined(NO_SIGN_VERIFY)
-# if (!defined(MAR_NSS) && defined(XP_WIN)) || defined(XP_MACOSX)
+# if (!defined(MAR_NSS) && (defined(XP_WIN) || defined(XP_MACOSX)))
/* -D DERFilePath, also matches -D[index] DERFilePath
We allow an index for verifying to be symmetric
with the import and export command line arguments. */
diff --git a/modules/libmar/tool/moz.build b/modules/libmar/tool/moz.build
index 19653fb0b073..8953af0bb15c 100644
--- a/modules/libmar/tool/moz.build
+++ b/modules/libmar/tool/moz.build
@@ -35,15 +35,21 @@ if CONFIG['MOZ_BUILD_APP'] != 'tools/update-packaging':
'verifymar',
]
+ if CONFIG['TOR_BROWSER_UPDATE']:
+ DEFINES['MAR_NSS'] = True
+
if CONFIG['OS_ARCH'] == 'WINNT':
USE_STATIC_LIBS = True
OS_LIBS += [
'ws2_32',
- 'crypt32',
- 'advapi32',
]
- elif CONFIG['OS_ARCH'] == 'Darwin':
+ if not CONFIG['TOR_BROWSER_UPDATE']:
+ OS_LIBS += [
+ 'crypt32',
+ 'advapi32',
+ ]
+ elif CONFIG['OS_ARCH'] == 'Darwin' and not CONFIG['TOR_BROWSER_UPDATE']:
OS_LIBS += [
'-framework Security',
]
diff --git a/modules/libmar/verify/moz.build b/modules/libmar/verify/moz.build
index 9f7dc56f8f8a..e1c6ced31c37 100644
--- a/modules/libmar/verify/moz.build
+++ b/modules/libmar/verify/moz.build
@@ -16,15 +16,12 @@ FORCE_STATIC_LIB = True
if CONFIG['OS_ARCH'] == 'WINNT':
USE_STATIC_LIBS = True
elif CONFIG['OS_ARCH'] == 'Darwin':
- UNIFIED_SOURCES += [
- 'MacVerifyCrypto.cpp',
- ]
- OS_LIBS += [
- '-framework Security',
+ USE_LIBS += [
+ 'nspr',
+ 'nss',
+ 'signmar',
]
else:
- DEFINES['MAR_NSS'] = True
- LOCAL_INCLUDES += ['../sign']
USE_LIBS += [
'nspr',
'nss',
@@ -38,6 +35,9 @@ else:
'-Wl,-rpath=\\$$ORIGIN',
]
+DEFINES['MAR_NSS'] = True
+LOCAL_INCLUDES += ['../sign']
+
LOCAL_INCLUDES += [
'../src',
]
diff --git a/toolkit/mozapps/update/updater/updater-common.build b/toolkit/mozapps/update/updater/updater-common.build
index 5898e92d465d..9f8365df8ade 100644
--- a/toolkit/mozapps/update/updater/updater-common.build
+++ b/toolkit/mozapps/update/updater/updater-common.build
@@ -4,6 +4,10 @@
# 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/.
+DEFINES['MAR_NSS'] = True
+
+link_with_nss = DEFINES['MAR_NSS'] or (CONFIG['OS_ARCH'] == 'Linux' and CONFIG['MOZ_VERIFY_MAR_SIGNATURE'])
+
srcs = [
'archivereader.cpp',
'updater.cpp',
@@ -36,10 +40,14 @@ if CONFIG['OS_ARCH'] == 'WINNT':
'ws2_32',
'shell32',
'shlwapi',
- 'crypt32',
- 'advapi32',
]
+ if not link_with_nss:
+ OS_LIBS += [
+ 'crypt32',
+ 'advapi32',
+ ]
+
USE_LIBS += [
'bspatch',
'mar',
@@ -47,6 +55,13 @@ USE_LIBS += [
'xz-embedded',
]
+if link_with_nss:
+ USE_LIBS += [
+ 'nspr',
+ 'nss',
+ 'signmar',
+ ]
+
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gtk':
have_progressui = 1
srcs += [
@@ -61,9 +76,12 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
]
OS_LIBS += [
'-framework Cocoa',
- '-framework Security',
'-framework SystemConfiguration',
]
+ if not link_with_nss:
+ OS_LIBS += [
+ '-framework Security',
+ ]
UNIFIED_SOURCES += [
'/toolkit/xre/updaterfileutils_osx.mm',
]
diff --git a/toolkit/mozapps/update/updater/updater.cpp b/toolkit/mozapps/update/updater/updater.cpp
index 9a95c3b17761..aaec0b38dda0 100644
--- a/toolkit/mozapps/update/updater/updater.cpp
+++ b/toolkit/mozapps/update/updater/updater.cpp
@@ -106,9 +106,11 @@ struct UpdateServerThreadArgs {
# define USE_EXECV
#endif
-#if defined(MOZ_VERIFY_MAR_SIGNATURE) && !defined(XP_WIN) && !defined(XP_MACOSX)
-# include "nss.h"
-# include "prerror.h"
+#if defined(MOZ_VERIFY_MAR_SIGNATURE)
+# if defined(MAR_NSS) || (!defined(XP_WIN) && !defined(XP_MACOSX))
+# include "nss.h"
+# include "prerror.h"
+# endif
#endif
#include "crctable.h"
@@ -2738,8 +2740,13 @@ static void UpdateThreadFunc(void* param) {
if (ReadMARChannelIDs(updateSettingsPath, &MARStrings) != OK) {
rv = UPDATE_SETTINGS_FILE_CHANNEL;
} else {
+# ifdef TOR_BROWSER_UPDATE
+ const char* appVersion = TOR_BROWSER_VERSION_QUOTED;
+# else
+ const char* appVersion = MOZ_APP_VERSION;
+# endif
rv = gArchiveReader.VerifyProductInformation(MARStrings.MARChannelID,
- MOZ_APP_VERSION);
+ appVersion);
}
}
}
@@ -2940,11 +2947,10 @@ int NS_main(int argc, NS_tchar** argv) {
}
#endif
-#if defined(MOZ_VERIFY_MAR_SIGNATURE) && !defined(XP_WIN) && !defined(XP_MACOSX)
- // On Windows and Mac we rely on native APIs to do verifications so we don't
- // need to initialize NSS at all there.
- // Otherwise, minimize the amount of NSS we depend on by avoiding all the NSS
- // databases.
+#if defined(MOZ_VERIFY_MAR_SIGNATURE)
+# if defined(MAR_NSS) || (!defined(XP_WIN) && !defined(XP_MACOSX))
+ // If using NSS for signature verification, initialize NSS but minimize
+ // the portion we depend on by avoiding all of the NSS databases.
if (NSS_NoDB_Init(nullptr) != SECSuccess) {
PRErrorCode error = PR_GetError();
fprintf(stderr, "Could not initialize NSS: %s (%d)", PR_ErrorToName(error),
@@ -2952,6 +2958,7 @@ int NS_main(int argc, NS_tchar** argv) {
_exit(1);
}
#endif
+#endif
#ifdef XP_MACOSX
if (!isElevated) {
diff --git a/toolkit/xre/moz.build b/toolkit/xre/moz.build
index 7ba3be2fe241..6afab145c2b6 100644
--- a/toolkit/xre/moz.build
+++ b/toolkit/xre/moz.build
@@ -214,6 +214,9 @@ for var in ('APP_VERSION', 'APP_ID'):
if CONFIG['MOZ_BUILD_APP'] == 'browser':
DEFINES['MOZ_BUILD_APP_IS_BROWSER'] = True
+if CONFIG['TOR_BROWSER_UPDATE']:
+ DEFINES['MAR_NSS'] = True
+
LOCAL_INCLUDES += [
'../../other-licenses/nsis/Contrib/CityHash/cityhash',
'../components/find',
diff --git a/toolkit/xre/nsUpdateDriver.cpp b/toolkit/xre/nsUpdateDriver.cpp
index 55d1982504ed..1cbee302719f 100644
--- a/toolkit/xre/nsUpdateDriver.cpp
+++ b/toolkit/xre/nsUpdateDriver.cpp
@@ -360,6 +360,42 @@ static nsresult GetUpdateDirFromAppDir(nsIFile* aAppDir, nsIFile** aResult) {
# endif
#endif
+#if defined(TOR_BROWSER_UPDATE) && defined(MOZ_VERIFY_MAR_SIGNATURE) && \
+ defined(MAR_NSS) && defined(XP_MACOSX)
+/**
+ * Ideally we would save and restore the original library path value after
+ * the updater finishes its work (and before firefox is re-launched).
+ * Doing so would avoid potential problems like the following bug:
+ * https://bugzilla.mozilla.org/show_bug.cgi?id=1434033
+ */
+/**
+ * Appends the specified path to the library path.
+ * This is used so that the updater can find libnss3.dylib and other
+ * shared libs.
+ *
+ * @param pathToAppend A new library path to prepend to the dynamic linker's
+ * search path.
+ */
+# include "prprf.h"
+# define PATH_SEPARATOR ":"
+# define LD_LIBRARY_PATH_ENVVAR_NAME "DYLD_LIBRARY_PATH"
+static void AppendToLibPath(const char* pathToAppend) {
+ char* pathValue = getenv(LD_LIBRARY_PATH_ENVVAR_NAME);
+ if (nullptr == pathValue || '\0' == *pathValue) {
+ // Leak the string because that is required by PR_SetEnv.
+ char* s =
+ Smprintf("%s=%s", LD_LIBRARY_PATH_ENVVAR_NAME, pathToAppend).release();
+ PR_SetEnv(s);
+ } else {
+ // Leak the string because that is required by PR_SetEnv.
+ char* s = Smprintf("%s=%s" PATH_SEPARATOR "%s", LD_LIBRARY_PATH_ENVVAR_NAME,
+ pathToAppend, pathValue)
+ .release();
+ PR_SetEnv(s);
+ }
+}
+#endif
+
/**
* Applies, switches, or stages an update.
*
@@ -606,6 +642,20 @@ static void ApplyUpdate(nsIFile* greDir, nsIFile* updateDir, nsIFile* appDir,
PR_SetEnv("MOZ_SAFE_MODE_RESTART=1");
}
+#if defined(TOR_BROWSER_UPDATE) && defined(MOZ_VERIFY_MAR_SIGNATURE) && \
+ defined(MAR_NSS) && defined(XP_MACOSX)
+ // On macOS, append the app directory to the shared library search path
+ // so the system can locate the shared libraries that are needed by the
+ // updater, e.g., libnss3.dylib).
+ nsAutoCString appPath;
+ nsresult rv2 = appDir->GetNativePath(appPath);
+ if (NS_SUCCEEDED(rv2)) {
+ AppendToLibPath(appPath.get());
+ } else {
+ LOG(("ApplyUpdate -- appDir->GetNativePath() failed (0x%x)\n", rv2));
+ }
+#endif
+
LOG(("spawning updater process [%s]\n", updaterPath.get()));
#ifdef DEBUG
dump_argv("ApplyUpdate updater", argv, argc);
1
0
[Git][tpo/applications/fenix] Pushed new tag tor-browser-90.0.0b6-11.0-1-build1
by Matthew Finkel (@sysrqb) 08 Jul '21
by Matthew Finkel (@sysrqb) 08 Jul '21
08 Jul '21
Matthew Finkel pushed new tag tor-browser-90.0.0b6-11.0-1-build1 at The Tor Project / Applications / fenix
--
View it on GitLab: https://gitlab.torproject.org/tpo/applications/fenix/-/tree/tor-browser-90.…
You're receiving this email because of your account on gitlab.torproject.org.
1
0
[Git][tpo/applications/fenix][tor-browser-90.0.0b6-11.0-1] squash! Add Tor integration and UI
by Matthew Finkel (@sysrqb) 08 Jul '21
by Matthew Finkel (@sysrqb) 08 Jul '21
08 Jul '21
Matthew Finkel pushed to branch tor-browser-90.0.0b6-11.0-1 at The Tor Project / Applications / fenix
Commits:
16dc16f5 by Matthew Finkel at 2021-07-08T20:16:18+00:00
squash! Add Tor integration and UI
Bug 40179: Show Snowflake bridge option on Release
- - - - -
1 changed file:
- app/src/main/java/org/mozilla/fenix/settings/TorBridgeConfigFragment.kt
Changes:
=====================================
app/src/main/java/org/mozilla/fenix/settings/TorBridgeConfigFragment.kt
=====================================
@@ -40,13 +40,6 @@ class TorBridgeConfigFragment : PreferenceFragmentCompat() {
// `*` is Kotlin's "spread" operator, for expanding an Array as a vararg.
addToRadioGroup(*builtinBridgeRadioGroups.toTypedArray())
-
- // Snowflake is not available on Release at this time.
- if (Config.channel.isRelease) {
- radioSnowflake.apply {
- isVisible = false
- }
- }
}
override fun onResume() {
View it on GitLab: https://gitlab.torproject.org/tpo/applications/fenix/-/commit/16dc16f51280f…
--
View it on GitLab: https://gitlab.torproject.org/tpo/applications/fenix/-/commit/16dc16f51280f…
You're receiving this email because of your account on gitlab.torproject.org.
1
0
[snowflake/main] Fix race is broker test reported by `go test -race`
by arlo@torproject.org 08 Jul '21
by arlo@torproject.org 08 Jul '21
08 Jul '21
commit dfb68d7cfc4b69c5e1f5628f3db002c3595fa1f0
Author: Arlo Breault <arlolra(a)gmail.com>
Date: Thu Jul 8 15:31:56 2021 -0400
Fix race is broker test reported by `go test -race`
---
broker/snowflake-broker_test.go | 27 +++++++++++++++------------
1 file changed, 15 insertions(+), 12 deletions(-)
diff --git a/broker/snowflake-broker_test.go b/broker/snowflake-broker_test.go
index 77e62cf..9e1c9f1 100644
--- a/broker/snowflake-broker_test.go
+++ b/broker/snowflake-broker_test.go
@@ -173,10 +173,10 @@ func TestBroker(t *testing.T) {
So(err, ShouldBeNil)
Convey("with a client offer if available.", func() {
- go func(ctx *BrokerContext) {
+ go func(i *IPC) {
proxyPolls(i, w, r)
done <- true
- }(ctx)
+ }(i)
// Pass a fake client offer to this proxy
p := <-ctx.proxyPolls
So(p.id, ShouldEqual, "ymbcCMto7KHNGYlp")
@@ -187,10 +187,10 @@ func TestBroker(t *testing.T) {
})
Convey("return empty 200 OK when no client offer is available.", func() {
- go func(ctx *BrokerContext) {
+ go func(i *IPC) {
proxyPolls(i, w, r)
done <- true
- }(ctx)
+ }(i)
p := <-ctx.proxyPolls
So(p.id, ShouldEqual, "ymbcCMto7KHNGYlp")
// nil means timeout
@@ -202,6 +202,7 @@ func TestBroker(t *testing.T) {
})
Convey("Responds to proxy answers...", func() {
+ done := make(chan bool)
s := ctx.AddSnowflake("test", "", NATUnrestricted, 0)
w := httptest.NewRecorder()
data := bytes.NewReader([]byte(`{"Version":"1.0","Sid":"test","Answer":"test"}`))
@@ -209,10 +210,12 @@ func TestBroker(t *testing.T) {
Convey("by passing to the client if valid.", func() {
r, err := http.NewRequest("POST", "snowflake.broker/answer", data)
So(err, ShouldBeNil)
- go func(ctx *BrokerContext) {
+ go func(i *IPC) {
proxyAnswers(i, w, r)
- }(ctx)
+ done <- true
+ }(i)
answer := <-s.answerChannel
+ <-done
So(w.Code, ShouldEqual, http.StatusOK)
So(answer, ShouldResemble, "test")
})
@@ -265,10 +268,10 @@ func TestBroker(t *testing.T) {
rp, err := http.NewRequest("POST", "snowflake.broker/proxy", datap)
So(err, ShouldBeNil)
- go func(ctx *BrokerContext) {
+ go func(i *IPC) {
proxyPolls(i, wp, rp)
proxy_done <- true
- }(ctx)
+ }(i)
// Client offer
wc := httptest.NewRecorder()
@@ -289,10 +292,10 @@ func TestBroker(t *testing.T) {
datap = bytes.NewReader([]byte(`{"Version":"1.0","Sid":"ymbcCMto7KHNGYlp","Answer":"test"}`))
rp, err = http.NewRequest("POST", "snowflake.broker/answer", datap)
So(err, ShouldBeNil)
- go func(ctx *BrokerContext) {
+ go func(i *IPC) {
proxyAnswers(i, wp, rp)
proxy_done <- true
- }(ctx)
+ }(i)
<-proxy_done
<-client_done
@@ -682,10 +685,10 @@ func TestMetrics(t *testing.T) {
r, err := http.NewRequest("POST", "snowflake.broker/proxy", data)
r.RemoteAddr = "129.97.208.23:8888" //CA geoip
So(err, ShouldBeNil)
- go func(ctx *BrokerContext) {
+ go func(i *IPC) {
proxyPolls(i, w, r)
done <- true
- }(ctx)
+ }(i)
p := <-ctx.proxyPolls //manually unblock poll
p.offerChannel <- nil
<-done
1
0
commit 0ced1cc32497f3b47a614ef4a526af7925447252
Author: Arlo Breault <abreault(a)wikimedia.org>
Date: Thu May 20 08:31:30 2021 -0400
Move http handlers to a separate file
---
broker/broker.go | 196 ----------------------------------------------------
broker/http.go | 205 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 205 insertions(+), 196 deletions(-)
diff --git a/broker/broker.go b/broker/broker.go
index 58f3955..437a4d1 100644
--- a/broker/broker.go
+++ b/broker/broker.go
@@ -8,10 +8,8 @@ package main
import (
"container/heap"
"crypto/tls"
- "errors"
"flag"
"io"
- "io/ioutil"
"log"
"net/http"
"os"
@@ -21,17 +19,12 @@ import (
"syscall"
"time"
- "git.torproject.org/pluggable-transports/snowflake.git/common/messages"
"git.torproject.org/pluggable-transports/snowflake.git/common/safelog"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"golang.org/x/crypto/acme/autocert"
)
-const (
- readLimit = 100000 // Maximum number of bytes to be read from an HTTP request
-)
-
type BrokerContext struct {
snowflakes *SnowflakeHeap
restrictedSnowflakes *SnowflakeHeap
@@ -69,38 +62,6 @@ func NewBrokerContext(metricsLogger *log.Logger) *BrokerContext {
}
}
-// Implements the http.Handler interface
-type SnowflakeHandler struct {
- *IPC
- handle func(*IPC, http.ResponseWriter, *http.Request)
-}
-
-// Implements the http.Handler interface
-type MetricsHandler struct {
- logFilename string
- handle func(string, http.ResponseWriter, *http.Request)
-}
-
-func (sh SnowflakeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
- w.Header().Set("Access-Control-Allow-Origin", "*")
- w.Header().Set("Access-Control-Allow-Headers", "Origin, X-Session-ID")
- // Return early if it's CORS preflight.
- if "OPTIONS" == r.Method {
- return
- }
- sh.handle(sh.IPC, w, r)
-}
-
-func (mh MetricsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
- w.Header().Set("Access-Control-Allow-Origin", "*")
- w.Header().Set("Access-Control-Allow-Headers", "Origin, X-Session-ID")
- // Return early if it's CORS preflight.
- if "OPTIONS" == r.Method {
- return
- }
- mh.handle(mh.logFilename, w, r)
-}
-
// Proxies may poll for client offers concurrently.
type ProxyPoll struct {
id string
@@ -178,169 +139,12 @@ func (ctx *BrokerContext) AddSnowflake(id string, proxyType string, natType stri
return snowflake
}
-/*
-For snowflake proxies to request a client from the Broker.
-*/
-func proxyPolls(i *IPC, w http.ResponseWriter, r *http.Request) {
- body, err := ioutil.ReadAll(http.MaxBytesReader(w, r.Body, readLimit))
- if err != nil {
- log.Println("Invalid data.")
- w.WriteHeader(http.StatusBadRequest)
- return
- }
-
- arg := messages.Arg{
- Body: body,
- RemoteAddr: r.RemoteAddr,
- NatType: "",
- }
-
- var response []byte
- err = i.ProxyPolls(arg, &response)
- switch {
- case err == nil:
- case errors.Is(err, messages.ErrBadRequest):
- w.WriteHeader(http.StatusBadRequest)
- return
- case errors.Is(err, messages.ErrInternal):
- fallthrough
- default:
- log.Println(err)
- w.WriteHeader(http.StatusInternalServerError)
- return
- }
-
- if _, err := w.Write(response); err != nil {
- log.Printf("proxyPolls unable to write offer with error: %v", err)
- }
-}
-
// Client offer contains an SDP and the NAT type of the client
type ClientOffer struct {
natType string
sdp []byte
}
-/*
-Expects a WebRTC SDP offer in the Request to give to an assigned
-snowflake proxy, which responds with the SDP answer to be sent in
-the HTTP response back to the client.
-*/
-func clientOffers(i *IPC, w http.ResponseWriter, r *http.Request) {
- body, err := ioutil.ReadAll(http.MaxBytesReader(w, r.Body, readLimit))
- if err != nil {
- log.Printf("Error reading client request: %s", err.Error())
- w.WriteHeader(http.StatusBadRequest)
- return
- }
-
- arg := messages.Arg{
- Body: body,
- RemoteAddr: "",
- NatType: r.Header.Get("Snowflake-NAT-Type"),
- }
-
- var response []byte
- err = i.ClientOffers(arg, &response)
- switch {
- case err == nil:
- case errors.Is(err, messages.ErrUnavailable):
- w.WriteHeader(http.StatusServiceUnavailable)
- return
- case errors.Is(err, messages.ErrTimeout):
- w.WriteHeader(http.StatusGatewayTimeout)
- return
- default:
- log.Println(err)
- w.WriteHeader(http.StatusInternalServerError)
- return
- }
-
- if _, err := w.Write(response); err != nil {
- log.Printf("clientOffers unable to write answer with error: %v", err)
- }
-}
-
-/*
-Expects snowflake proxes which have previously successfully received
-an offer from proxyHandler to respond with an answer in an HTTP POST,
-which the broker will pass back to the original client.
-*/
-func proxyAnswers(i *IPC, w http.ResponseWriter, r *http.Request) {
- body, err := ioutil.ReadAll(http.MaxBytesReader(w, r.Body, readLimit))
- if err != nil {
- log.Println("Invalid data.")
- w.WriteHeader(http.StatusBadRequest)
- return
- }
-
- arg := messages.Arg{
- Body: body,
- RemoteAddr: "",
- NatType: "",
- }
-
- var response []byte
- err = i.ProxyAnswers(arg, &response)
- switch {
- case err == nil:
- case errors.Is(err, messages.ErrBadRequest):
- w.WriteHeader(http.StatusBadRequest)
- return
- case errors.Is(err, messages.ErrInternal):
- fallthrough
- default:
- log.Println(err)
- w.WriteHeader(http.StatusInternalServerError)
- return
- }
-
- if _, err := w.Write(response); err != nil {
- log.Printf("proxyAnswers unable to write answer response with error: %v", err)
- }
-}
-
-func debugHandler(i *IPC, w http.ResponseWriter, r *http.Request) {
- var response string
-
- err := i.Debug(new(interface{}), &response)
- if err != nil {
- log.Println(err)
- w.WriteHeader(http.StatusInternalServerError)
- return
- }
-
- if _, err := w.Write([]byte(response)); err != nil {
- log.Printf("writing proxy information returned error: %v ", err)
- }
-}
-
-func robotsTxtHandler(w http.ResponseWriter, r *http.Request) {
- w.Header().Set("Content-Type", "text/plain; charset=utf-8")
- if _, err := w.Write([]byte("User-agent: *\nDisallow: /\n")); err != nil {
- log.Printf("robotsTxtHandler unable to write, with this error: %v", err)
- }
-}
-
-func metricsHandler(metricsFilename string, w http.ResponseWriter, r *http.Request) {
- w.Header().Set("Content-Type", "text/plain; charset=utf-8")
-
- if metricsFilename == "" {
- http.NotFound(w, r)
- return
- }
- metricsFile, err := os.OpenFile(metricsFilename, os.O_RDONLY, 0644)
- if err != nil {
- log.Println("Error opening metrics file for reading")
- http.NotFound(w, r)
- return
- }
-
- if _, err := io.Copy(w, metricsFile); err != nil {
- log.Printf("copying metricsFile returned error: %v", err)
- }
-}
-
func main() {
var acmeEmail string
var acmeHostnamesCommas string
diff --git a/broker/http.go b/broker/http.go
new file mode 100644
index 0000000..6555d7a
--- /dev/null
+++ b/broker/http.go
@@ -0,0 +1,205 @@
+package main
+
+import (
+ "errors"
+ "io"
+ "io/ioutil"
+ "log"
+ "net/http"
+ "os"
+
+ "git.torproject.org/pluggable-transports/snowflake.git/common/messages"
+)
+
+const (
+ readLimit = 100000 // Maximum number of bytes to be read from an HTTP request
+)
+
+// Implements the http.Handler interface
+type SnowflakeHandler struct {
+ *IPC
+ handle func(*IPC, http.ResponseWriter, *http.Request)
+}
+
+func (sh SnowflakeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Access-Control-Allow-Origin", "*")
+ w.Header().Set("Access-Control-Allow-Headers", "Origin, X-Session-ID")
+ // Return early if it's CORS preflight.
+ if "OPTIONS" == r.Method {
+ return
+ }
+ sh.handle(sh.IPC, w, r)
+}
+
+// Implements the http.Handler interface
+type MetricsHandler struct {
+ logFilename string
+ handle func(string, http.ResponseWriter, *http.Request)
+}
+
+func (mh MetricsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Access-Control-Allow-Origin", "*")
+ w.Header().Set("Access-Control-Allow-Headers", "Origin, X-Session-ID")
+ // Return early if it's CORS preflight.
+ if "OPTIONS" == r.Method {
+ return
+ }
+ mh.handle(mh.logFilename, w, r)
+}
+
+func robotsTxtHandler(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "text/plain; charset=utf-8")
+ if _, err := w.Write([]byte("User-agent: *\nDisallow: /\n")); err != nil {
+ log.Printf("robotsTxtHandler unable to write, with this error: %v", err)
+ }
+}
+
+func metricsHandler(metricsFilename string, w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "text/plain; charset=utf-8")
+
+ if metricsFilename == "" {
+ http.NotFound(w, r)
+ return
+ }
+ metricsFile, err := os.OpenFile(metricsFilename, os.O_RDONLY, 0644)
+ if err != nil {
+ log.Println("Error opening metrics file for reading")
+ http.NotFound(w, r)
+ return
+ }
+
+ if _, err := io.Copy(w, metricsFile); err != nil {
+ log.Printf("copying metricsFile returned error: %v", err)
+ }
+}
+
+func debugHandler(i *IPC, w http.ResponseWriter, r *http.Request) {
+ var response string
+
+ err := i.Debug(new(interface{}), &response)
+ if err != nil {
+ log.Println(err)
+ w.WriteHeader(http.StatusInternalServerError)
+ return
+ }
+
+ if _, err := w.Write([]byte(response)); err != nil {
+ log.Printf("writing proxy information returned error: %v ", err)
+ }
+}
+
+/*
+For snowflake proxies to request a client from the Broker.
+*/
+func proxyPolls(i *IPC, w http.ResponseWriter, r *http.Request) {
+ body, err := ioutil.ReadAll(http.MaxBytesReader(w, r.Body, readLimit))
+ if err != nil {
+ log.Println("Invalid data.")
+ w.WriteHeader(http.StatusBadRequest)
+ return
+ }
+
+ arg := messages.Arg{
+ Body: body,
+ RemoteAddr: r.RemoteAddr,
+ NatType: "",
+ }
+
+ var response []byte
+ err = i.ProxyPolls(arg, &response)
+ switch {
+ case err == nil:
+ case errors.Is(err, messages.ErrBadRequest):
+ w.WriteHeader(http.StatusBadRequest)
+ return
+ case errors.Is(err, messages.ErrInternal):
+ fallthrough
+ default:
+ log.Println(err)
+ w.WriteHeader(http.StatusInternalServerError)
+ return
+ }
+
+ if _, err := w.Write(response); err != nil {
+ log.Printf("proxyPolls unable to write offer with error: %v", err)
+ }
+}
+
+/*
+Expects a WebRTC SDP offer in the Request to give to an assigned
+snowflake proxy, which responds with the SDP answer to be sent in
+the HTTP response back to the client.
+*/
+func clientOffers(i *IPC, w http.ResponseWriter, r *http.Request) {
+ body, err := ioutil.ReadAll(http.MaxBytesReader(w, r.Body, readLimit))
+ if err != nil {
+ log.Printf("Error reading client request: %s", err.Error())
+ w.WriteHeader(http.StatusBadRequest)
+ return
+ }
+
+ arg := messages.Arg{
+ Body: body,
+ RemoteAddr: "",
+ NatType: r.Header.Get("Snowflake-NAT-Type"),
+ }
+
+ var response []byte
+ err = i.ClientOffers(arg, &response)
+ switch {
+ case err == nil:
+ case errors.Is(err, messages.ErrUnavailable):
+ w.WriteHeader(http.StatusServiceUnavailable)
+ return
+ case errors.Is(err, messages.ErrTimeout):
+ w.WriteHeader(http.StatusGatewayTimeout)
+ return
+ default:
+ log.Println(err)
+ w.WriteHeader(http.StatusInternalServerError)
+ return
+ }
+
+ if _, err := w.Write(response); err != nil {
+ log.Printf("clientOffers unable to write answer with error: %v", err)
+ }
+}
+
+/*
+Expects snowflake proxes which have previously successfully received
+an offer from proxyHandler to respond with an answer in an HTTP POST,
+which the broker will pass back to the original client.
+*/
+func proxyAnswers(i *IPC, w http.ResponseWriter, r *http.Request) {
+ body, err := ioutil.ReadAll(http.MaxBytesReader(w, r.Body, readLimit))
+ if err != nil {
+ log.Println("Invalid data.")
+ w.WriteHeader(http.StatusBadRequest)
+ return
+ }
+
+ arg := messages.Arg{
+ Body: body,
+ RemoteAddr: "",
+ NatType: "",
+ }
+
+ var response []byte
+ err = i.ProxyAnswers(arg, &response)
+ switch {
+ case err == nil:
+ case errors.Is(err, messages.ErrBadRequest):
+ w.WriteHeader(http.StatusBadRequest)
+ return
+ case errors.Is(err, messages.ErrInternal):
+ fallthrough
+ default:
+ log.Println(err)
+ w.WriteHeader(http.StatusInternalServerError)
+ return
+ }
+
+ if _, err := w.Write(response); err != nil {
+ log.Printf("proxyAnswers unable to write answer response with error: %v", err)
+ }
+}
1
0
commit 87ad06a5e2f1b0d72c64dd0ca17543f524ac1d63
Author: Arlo Breault <arlolra(a)gmail.com>
Date: Thu Jun 3 17:04:58 2021 -0400
Get rid of legacy version
Move the logic for the legacy version into the http handlers and use a
shim when doing ipc.
---
broker/http.go | 51 ++++++++++++++++++++++++++++++++++++++------------
broker/ipc.go | 44 ++++++++++++-------------------------------
common/messages/ipc.go | 7 ++-----
3 files changed, 53 insertions(+), 49 deletions(-)
diff --git a/broker/http.go b/broker/http.go
index 6555d7a..2c45b2b 100644
--- a/broker/http.go
+++ b/broker/http.go
@@ -102,7 +102,6 @@ func proxyPolls(i *IPC, w http.ResponseWriter, r *http.Request) {
arg := messages.Arg{
Body: body,
RemoteAddr: r.RemoteAddr,
- NatType: "",
}
var response []byte
@@ -138,28 +137,57 @@ func clientOffers(i *IPC, w http.ResponseWriter, r *http.Request) {
return
}
+ // Handle the legacy version
+ isLegacy := false
+ if len(body) > 0 && body[0] == '{' {
+ isLegacy = true
+ req := messages.ClientPollRequest{
+ Offer: string(body),
+ NAT: r.Header.Get("Snowflake-NAT-Type"),
+ }
+ body, err = req.EncodePollRequest()
+ if err != nil {
+ log.Printf("Error shimming the legacy request: %s", err.Error())
+ w.WriteHeader(http.StatusInternalServerError)
+ return
+ }
+ }
+
arg := messages.Arg{
Body: body,
RemoteAddr: "",
- NatType: r.Header.Get("Snowflake-NAT-Type"),
}
var response []byte
err = i.ClientOffers(arg, &response)
- switch {
- case err == nil:
- case errors.Is(err, messages.ErrUnavailable):
- w.WriteHeader(http.StatusServiceUnavailable)
- return
- case errors.Is(err, messages.ErrTimeout):
- w.WriteHeader(http.StatusGatewayTimeout)
- return
- default:
+ if err != nil {
+ // Assert err == messages.ErrInternal
log.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
+ if isLegacy {
+ resp, err := messages.DecodeClientPollResponse(response)
+ if err != nil {
+ log.Println(err)
+ w.WriteHeader(http.StatusInternalServerError)
+ return
+ }
+ switch resp.Error {
+ case "":
+ response = []byte(resp.Answer)
+ case "no snowflake proxies currently available":
+ w.WriteHeader(http.StatusServiceUnavailable)
+ return
+ case "timed out waiting for answer!":
+ w.WriteHeader(http.StatusGatewayTimeout)
+ return
+ default:
+ panic("unknown error")
+ }
+ }
+
if _, err := w.Write(response); err != nil {
log.Printf("clientOffers unable to write answer with error: %v", err)
}
@@ -181,7 +209,6 @@ func proxyAnswers(i *IPC, w http.ResponseWriter, r *http.Request) {
arg := messages.Arg{
Body: body,
RemoteAddr: "",
- NatType: "",
}
var response []byte
diff --git a/broker/ipc.go b/broker/ipc.go
index 79ccf0f..a05f560 100644
--- a/broker/ipc.go
+++ b/broker/ipc.go
@@ -21,14 +21,10 @@ const (
NATUnrestricted = "unrestricted"
)
-// We support two client message formats. The legacy format is for backwards
-// combatability and relies heavily on HTTP headers and status codes to convey
-// information.
type clientVersion int
const (
- v0 clientVersion = iota //legacy version
- v1
+ v1 clientVersion = iota
)
type IPC struct {
@@ -141,32 +137,22 @@ func (i *IPC) ClientOffers(arg messages.Arg, response *[]byte) error {
startTime := time.Now()
body := arg.Body
- if len(body) > 0 && body[0] == '{' {
- version = v0
+ parts := bytes.SplitN(body, []byte("\n"), 2)
+ if len(parts) < 2 {
+ // no version number found
+ err := fmt.Errorf("unsupported message version")
+ return sendClientResponse(&messages.ClientPollResponse{Error: err.Error()}, response)
+ }
+ body = parts[1]
+ if string(parts[0]) == "1.0" {
+ version = v1
} else {
- parts := bytes.SplitN(body, []byte("\n"), 2)
- if len(parts) < 2 {
- // no version number found
- err := fmt.Errorf("unsupported message version")
- return sendClientResponse(&messages.ClientPollResponse{Error: err.Error()}, response)
- }
- body = parts[1]
- if string(parts[0]) == "1.0" {
- version = v1
-
- } else {
- err := fmt.Errorf("unsupported message version")
- return sendClientResponse(&messages.ClientPollResponse{Error: err.Error()}, response)
- }
+ err := fmt.Errorf("unsupported message version")
+ return sendClientResponse(&messages.ClientPollResponse{Error: err.Error()}, response)
}
var offer *ClientOffer
switch version {
- case v0:
- offer = &ClientOffer{
- natType: arg.NatType,
- sdp: body,
- }
case v1:
req, err := messages.DecodeClientPollRequest(body)
if err != nil {
@@ -203,8 +189,6 @@ func (i *IPC) ClientOffers(arg messages.Arg, response *[]byte) error {
}
i.ctx.metrics.lock.Unlock()
switch version {
- case v0:
- return messages.ErrUnavailable
case v1:
resp := &messages.ClientPollResponse{Error: "no snowflake proxies currently available"}
return sendClientResponse(resp, response)
@@ -230,8 +214,6 @@ func (i *IPC) ClientOffers(arg messages.Arg, response *[]byte) error {
i.ctx.metrics.promMetrics.ClientPollTotal.With(prometheus.Labels{"nat": offer.natType, "status": "matched"}).Inc()
i.ctx.metrics.lock.Unlock()
switch version {
- case v0:
- *response = []byte(answer)
case v1:
resp := &messages.ClientPollResponse{Answer: answer}
err = sendClientResponse(resp, response)
@@ -243,8 +225,6 @@ func (i *IPC) ClientOffers(arg messages.Arg, response *[]byte) error {
case <-time.After(time.Second * ClientTimeout):
log.Println("Client: Timed out.")
switch version {
- case v0:
- err = messages.ErrTimeout
case v1:
resp := &messages.ClientPollResponse{
Error: "timed out waiting for answer!"}
diff --git a/common/messages/ipc.go b/common/messages/ipc.go
index 3f89200..ee29a57 100644
--- a/common/messages/ipc.go
+++ b/common/messages/ipc.go
@@ -7,12 +7,9 @@ import (
type Arg struct {
Body []byte
RemoteAddr string
- NatType string
}
var (
- ErrBadRequest = errors.New("bad request")
- ErrInternal = errors.New("internal error")
- ErrUnavailable = errors.New("service unavailable")
- ErrTimeout = errors.New("timeout")
+ ErrBadRequest = errors.New("bad request")
+ ErrInternal = errors.New("internal error")
)
1
0
08 Jul '21
commit 015958fbe66bd91a003c6fc92a11bd5d13b887c3
Author: Arlo Breault <arlolra(a)gmail.com>
Date: Thu May 20 07:49:27 2021 -0400
Intermediary refactor teasing apart http / ipc
Introduces an IPC struct and moves the logic out of the http handlers
and into methods on that.
---
broker/broker.go | 338 +++++++++-------------------------------
broker/ipc.go | 293 ++++++++++++++++++++++++++++++++++
broker/snowflake-broker_test.go | 111 ++++++-------
common/messages/ipc.go | 18 +++
4 files changed, 445 insertions(+), 315 deletions(-)
diff --git a/broker/broker.go b/broker/broker.go
index fc4727d..58f3955 100644
--- a/broker/broker.go
+++ b/broker/broker.go
@@ -6,15 +6,13 @@ SessionDescriptions in order to negotiate a WebRTC connection.
package main
import (
- "bytes"
"container/heap"
"crypto/tls"
+ "errors"
"flag"
- "fmt"
"io"
"io/ioutil"
"log"
- "net"
"net/http"
"os"
"os/signal"
@@ -31,23 +29,7 @@ import (
)
const (
- ClientTimeout = 10
- ProxyTimeout = 10
- readLimit = 100000 //Maximum number of bytes to be read from an HTTP request
-
- NATUnknown = "unknown"
- NATRestricted = "restricted"
- NATUnrestricted = "unrestricted"
-)
-
-// We support two client message formats. The legacy format is for backwards
-// combatability and relies heavily on HTTP headers and status codes to convey
-// information.
-type clientVersion int
-
-const (
- v0 clientVersion = iota //legacy version
- v1
+ readLimit = 100000 // Maximum number of bytes to be read from an HTTP request
)
type BrokerContext struct {
@@ -89,8 +71,8 @@ func NewBrokerContext(metricsLogger *log.Logger) *BrokerContext {
// Implements the http.Handler interface
type SnowflakeHandler struct {
- *BrokerContext
- handle func(*BrokerContext, http.ResponseWriter, *http.Request)
+ *IPC
+ handle func(*IPC, http.ResponseWriter, *http.Request)
}
// Implements the http.Handler interface
@@ -106,7 +88,7 @@ func (sh SnowflakeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if "OPTIONS" == r.Method {
return
}
- sh.handle(sh.BrokerContext, w, r)
+ sh.handle(sh.IPC, w, r)
}
func (mh MetricsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@@ -199,7 +181,7 @@ func (ctx *BrokerContext) AddSnowflake(id string, proxyType string, natType stri
/*
For snowflake proxies to request a client from the Broker.
*/
-func proxyPolls(ctx *BrokerContext, w http.ResponseWriter, r *http.Request) {
+func proxyPolls(i *IPC, w http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(http.MaxBytesReader(w, r.Body, readLimit))
if err != nil {
log.Println("Invalid data.")
@@ -207,47 +189,28 @@ func proxyPolls(ctx *BrokerContext, w http.ResponseWriter, r *http.Request) {
return
}
- sid, proxyType, natType, clients, err := messages.DecodePollRequest(body)
- if err != nil {
- w.WriteHeader(http.StatusBadRequest)
- return
- }
-
- // Log geoip stats
- remoteIP, _, err := net.SplitHostPort(r.RemoteAddr)
- if err != nil {
- log.Println("Error processing proxy IP: ", err.Error())
- } else {
- ctx.metrics.lock.Lock()
- ctx.metrics.UpdateCountryStats(remoteIP, proxyType, natType)
- ctx.metrics.lock.Unlock()
+ arg := messages.Arg{
+ Body: body,
+ RemoteAddr: r.RemoteAddr,
+ NatType: "",
}
- // Wait for a client to avail an offer to the snowflake, or timeout if nil.
- offer := ctx.RequestOffer(sid, proxyType, natType, clients)
- var b []byte
- if nil == offer {
- ctx.metrics.lock.Lock()
- ctx.metrics.proxyIdleCount++
- ctx.metrics.promMetrics.ProxyPollTotal.With(prometheus.Labels{"nat": natType, "status": "idle"}).Inc()
- ctx.metrics.lock.Unlock()
-
- b, err = messages.EncodePollResponse("", false, "")
- if err != nil {
- w.WriteHeader(http.StatusInternalServerError)
- return
- }
-
- w.Write(b)
+ var response []byte
+ err = i.ProxyPolls(arg, &response)
+ switch {
+ case err == nil:
+ case errors.Is(err, messages.ErrBadRequest):
+ w.WriteHeader(http.StatusBadRequest)
return
- }
- ctx.metrics.promMetrics.ProxyPollTotal.With(prometheus.Labels{"nat": natType, "status": "matched"}).Inc()
- b, err = messages.EncodePollResponse(string(offer.sdp), true, offer.natType)
- if err != nil {
+ case errors.Is(err, messages.ErrInternal):
+ fallthrough
+ default:
+ log.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
- if _, err := w.Write(b); err != nil {
+
+ if _, err := w.Write(response); err != nil {
log.Printf("proxyPolls unable to write offer with error: %v", err)
}
}
@@ -258,162 +221,44 @@ type ClientOffer struct {
sdp []byte
}
-// Sends an encoded response to the client and an
-// HTTP server error if the response encoding fails
-func sendClientResponse(resp *messages.ClientPollResponse, w http.ResponseWriter) {
- data, err := resp.EncodePollResponse()
- if err != nil {
- log.Printf("error encoding answer")
- w.WriteHeader(http.StatusInternalServerError)
- } else {
- if _, err := w.Write([]byte(data)); err != nil {
- log.Printf("unable to write answer with error: %v", err)
- }
- }
-}
-
/*
Expects a WebRTC SDP offer in the Request to give to an assigned
snowflake proxy, which responds with the SDP answer to be sent in
the HTTP response back to the client.
*/
-func clientOffers(ctx *BrokerContext, w http.ResponseWriter, r *http.Request) {
- var err error
- var version clientVersion
-
- startTime := time.Now()
+func clientOffers(i *IPC, w http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(http.MaxBytesReader(w, r.Body, readLimit))
if err != nil {
log.Printf("Error reading client request: %s", err.Error())
- w.WriteHeader(http.StatusInternalServerError)
+ w.WriteHeader(http.StatusBadRequest)
return
}
- if len(body) > 0 && body[0] == '{' {
- version = v0
- } else {
- parts := bytes.SplitN(body, []byte("\n"), 2)
- if len(parts) < 2 {
- // no version number found
- err := fmt.Errorf("unsupported message version")
- sendClientResponse(&messages.ClientPollResponse{Error: err.Error()}, w)
- return
- }
- body = parts[1]
- if string(parts[0]) == "1.0" {
- version = v1
- } else {
- err := fmt.Errorf("unsupported message version")
- sendClientResponse(&messages.ClientPollResponse{Error: err.Error()}, w)
- return
- }
+ arg := messages.Arg{
+ Body: body,
+ RemoteAddr: "",
+ NatType: r.Header.Get("Snowflake-NAT-Type"),
}
- var offer *ClientOffer
- switch version {
- case v0:
- offer = &ClientOffer{
- natType: r.Header.Get("Snowflake-NAT-Type"),
- sdp: body,
- }
- case v1:
- req, err := messages.DecodeClientPollRequest(body)
- if err != nil {
- sendClientResponse(&messages.ClientPollResponse{Error: err.Error()}, w)
- return
- }
- offer = &ClientOffer{
- natType: req.NAT,
- sdp: []byte(req.Offer),
- }
+ var response []byte
+ err = i.ClientOffers(arg, &response)
+ switch {
+ case err == nil:
+ case errors.Is(err, messages.ErrUnavailable):
+ w.WriteHeader(http.StatusServiceUnavailable)
+ return
+ case errors.Is(err, messages.ErrTimeout):
+ w.WriteHeader(http.StatusGatewayTimeout)
+ return
default:
- panic("unknown version")
- }
-
- // Only hand out known restricted snowflakes to unrestricted clients
- var snowflakeHeap *SnowflakeHeap
- if offer.natType == NATUnrestricted {
- snowflakeHeap = ctx.restrictedSnowflakes
- } else {
- snowflakeHeap = ctx.snowflakes
- }
-
- // Immediately fail if there are no snowflakes available.
- ctx.snowflakeLock.Lock()
- numSnowflakes := snowflakeHeap.Len()
- ctx.snowflakeLock.Unlock()
- if numSnowflakes <= 0 {
- ctx.metrics.lock.Lock()
- ctx.metrics.clientDeniedCount++
- ctx.metrics.promMetrics.ClientPollTotal.With(prometheus.Labels{"nat": offer.natType, "status": "denied"}).Inc()
- if offer.natType == NATUnrestricted {
- ctx.metrics.clientUnrestrictedDeniedCount++
- } else {
- ctx.metrics.clientRestrictedDeniedCount++
- }
- ctx.metrics.lock.Unlock()
- switch version {
- case v0:
- w.WriteHeader(http.StatusServiceUnavailable)
- case v1:
- resp := &messages.ClientPollResponse{Error: "no snowflake proxies currently available"}
- sendClientResponse(resp, w)
- default:
- panic("unknown version")
- }
+ log.Println(err)
+ w.WriteHeader(http.StatusInternalServerError)
return
}
- // Otherwise, find the most available snowflake proxy, and pass the offer to it.
- // Delete must be deferred in order to correctly process answer request later.
- ctx.snowflakeLock.Lock()
- snowflake := heap.Pop(snowflakeHeap).(*Snowflake)
- ctx.snowflakeLock.Unlock()
- snowflake.offerChannel <- offer
-
- // Wait for the answer to be returned on the channel or timeout.
- select {
- case answer := <-snowflake.answerChannel:
- ctx.metrics.lock.Lock()
- ctx.metrics.clientProxyMatchCount++
- ctx.metrics.promMetrics.ClientPollTotal.With(prometheus.Labels{"nat": offer.natType, "status": "matched"}).Inc()
- ctx.metrics.lock.Unlock()
- switch version {
- case v0:
- if _, err := w.Write([]byte(answer)); err != nil {
- log.Printf("unable to write answer with error: %v", err)
- }
- case v1:
- resp := &messages.ClientPollResponse{Answer: answer}
- sendClientResponse(resp, w)
- default:
- panic("unknown version")
- }
- // Initial tracking of elapsed time.
- ctx.metrics.clientRoundtripEstimate = time.Since(startTime) /
- time.Millisecond
- case <-time.After(time.Second * ClientTimeout):
- log.Println("Client: Timed out.")
- switch version {
- case v0:
- w.WriteHeader(http.StatusGatewayTimeout)
- if _, err := w.Write(
- []byte("timed out waiting for answer!")); err != nil {
- log.Printf("unable to write timeout error, failed with error: %v",
- err)
- }
- case v1:
- resp := &messages.ClientPollResponse{
- Error: "timed out waiting for answer!"}
- sendClientResponse(resp, w)
- default:
- panic("unknown version")
- }
- }
- ctx.snowflakeLock.Lock()
- ctx.metrics.promMetrics.AvailableProxies.With(prometheus.Labels{"nat": snowflake.natType, "type": snowflake.proxyType}).Dec()
- delete(ctx.idToSnowflake, snowflake.id)
- ctx.snowflakeLock.Unlock()
+ if _, err := w.Write(response); err != nil {
+ log.Printf("clientOffers unable to write answer with error: %v", err)
+ }
}
/*
@@ -421,82 +266,51 @@ Expects snowflake proxes which have previously successfully received
an offer from proxyHandler to respond with an answer in an HTTP POST,
which the broker will pass back to the original client.
*/
-func proxyAnswers(ctx *BrokerContext, w http.ResponseWriter, r *http.Request) {
-
+func proxyAnswers(i *IPC, w http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(http.MaxBytesReader(w, r.Body, readLimit))
- if nil != err || nil == body || len(body) <= 0 {
+ if err != nil {
log.Println("Invalid data.")
w.WriteHeader(http.StatusBadRequest)
return
}
- answer, id, err := messages.DecodeAnswerRequest(body)
- if err != nil || answer == "" {
- w.WriteHeader(http.StatusBadRequest)
- return
+ arg := messages.Arg{
+ Body: body,
+ RemoteAddr: "",
+ NatType: "",
}
- var success = true
- ctx.snowflakeLock.Lock()
- snowflake, ok := ctx.idToSnowflake[id]
- ctx.snowflakeLock.Unlock()
- if !ok || nil == snowflake {
- // The snowflake took too long to respond with an answer, so its client
- // disappeared / the snowflake is no longer recognized by the Broker.
- success = false
- }
- b, err := messages.EncodeAnswerResponse(success)
- if err != nil {
- log.Printf("Error encoding answer: %s", err.Error())
+ var response []byte
+ err = i.ProxyAnswers(arg, &response)
+ switch {
+ case err == nil:
+ case errors.Is(err, messages.ErrBadRequest):
+ w.WriteHeader(http.StatusBadRequest)
+ return
+ case errors.Is(err, messages.ErrInternal):
+ fallthrough
+ default:
+ log.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
- w.Write(b)
- if success {
- snowflake.answerChannel <- answer
+ if _, err := w.Write(response); err != nil {
+ log.Printf("proxyAnswers unable to write answer response with error: %v", err)
}
-
}
-func debugHandler(ctx *BrokerContext, w http.ResponseWriter, r *http.Request) {
-
- var webexts, browsers, standalones, unknowns int
- var natRestricted, natUnrestricted, natUnknown int
- ctx.snowflakeLock.Lock()
- s := fmt.Sprintf("current snowflakes available: %d\n", len(ctx.idToSnowflake))
- for _, snowflake := range ctx.idToSnowflake {
- if snowflake.proxyType == "badge" {
- browsers++
- } else if snowflake.proxyType == "webext" {
- webexts++
- } else if snowflake.proxyType == "standalone" {
- standalones++
- } else {
- unknowns++
- }
-
- switch snowflake.natType {
- case NATRestricted:
- natRestricted++
- case NATUnrestricted:
- natUnrestricted++
- default:
- natUnknown++
- }
+func debugHandler(i *IPC, w http.ResponseWriter, r *http.Request) {
+ var response string
+ err := i.Debug(new(interface{}), &response)
+ if err != nil {
+ log.Println(err)
+ w.WriteHeader(http.StatusInternalServerError)
+ return
}
- ctx.snowflakeLock.Unlock()
- s += fmt.Sprintf("\tstandalone proxies: %d", standalones)
- s += fmt.Sprintf("\n\tbrowser proxies: %d", browsers)
- s += fmt.Sprintf("\n\twebext proxies: %d", webexts)
- s += fmt.Sprintf("\n\tunknown proxies: %d", unknowns)
-
- s += fmt.Sprintf("\nNAT Types available:")
- s += fmt.Sprintf("\n\trestricted: %d", natRestricted)
- s += fmt.Sprintf("\n\tunrestricted: %d", natUnrestricted)
- s += fmt.Sprintf("\n\tunknown: %d", natUnknown)
- if _, err := w.Write([]byte(s)); err != nil {
+
+ if _, err := w.Write([]byte(response)); err != nil {
log.Printf("writing proxy information returned error: %v ", err)
}
}
@@ -589,12 +403,14 @@ func main() {
go ctx.Broker()
+ i := &IPC{ctx}
+
http.HandleFunc("/robots.txt", robotsTxtHandler)
- http.Handle("/proxy", SnowflakeHandler{ctx, proxyPolls})
- http.Handle("/client", SnowflakeHandler{ctx, clientOffers})
- http.Handle("/answer", SnowflakeHandler{ctx, proxyAnswers})
- http.Handle("/debug", SnowflakeHandler{ctx, debugHandler})
+ http.Handle("/proxy", SnowflakeHandler{i, proxyPolls})
+ http.Handle("/client", SnowflakeHandler{i, clientOffers})
+ http.Handle("/answer", SnowflakeHandler{i, proxyAnswers})
+ http.Handle("/debug", SnowflakeHandler{i, debugHandler})
http.Handle("/metrics", MetricsHandler{metricsFilename, metricsHandler})
http.Handle("/prometheus", promhttp.HandlerFor(ctx.metrics.promMetrics.registry, promhttp.HandlerOpts{}))
diff --git a/broker/ipc.go b/broker/ipc.go
new file mode 100644
index 0000000..79ccf0f
--- /dev/null
+++ b/broker/ipc.go
@@ -0,0 +1,293 @@
+package main
+
+import (
+ "bytes"
+ "container/heap"
+ "fmt"
+ "log"
+ "net"
+ "time"
+
+ "git.torproject.org/pluggable-transports/snowflake.git/common/messages"
+ "github.com/prometheus/client_golang/prometheus"
+)
+
+const (
+ ClientTimeout = 10
+ ProxyTimeout = 10
+
+ NATUnknown = "unknown"
+ NATRestricted = "restricted"
+ NATUnrestricted = "unrestricted"
+)
+
+// We support two client message formats. The legacy format is for backwards
+// combatability and relies heavily on HTTP headers and status codes to convey
+// information.
+type clientVersion int
+
+const (
+ v0 clientVersion = iota //legacy version
+ v1
+)
+
+type IPC struct {
+ ctx *BrokerContext
+}
+
+func (i *IPC) Debug(_ interface{}, response *string) error {
+ var webexts, browsers, standalones, unknowns int
+ var natRestricted, natUnrestricted, natUnknown int
+
+ i.ctx.snowflakeLock.Lock()
+ s := fmt.Sprintf("current snowflakes available: %d\n", len(i.ctx.idToSnowflake))
+ for _, snowflake := range i.ctx.idToSnowflake {
+ if snowflake.proxyType == "badge" {
+ browsers++
+ } else if snowflake.proxyType == "webext" {
+ webexts++
+ } else if snowflake.proxyType == "standalone" {
+ standalones++
+ } else {
+ unknowns++
+ }
+
+ switch snowflake.natType {
+ case NATRestricted:
+ natRestricted++
+ case NATUnrestricted:
+ natUnrestricted++
+ default:
+ natUnknown++
+ }
+
+ }
+ i.ctx.snowflakeLock.Unlock()
+
+ s += fmt.Sprintf("\tstandalone proxies: %d", standalones)
+ s += fmt.Sprintf("\n\tbrowser proxies: %d", browsers)
+ s += fmt.Sprintf("\n\twebext proxies: %d", webexts)
+ s += fmt.Sprintf("\n\tunknown proxies: %d", unknowns)
+
+ s += fmt.Sprintf("\nNAT Types available:")
+ s += fmt.Sprintf("\n\trestricted: %d", natRestricted)
+ s += fmt.Sprintf("\n\tunrestricted: %d", natUnrestricted)
+ s += fmt.Sprintf("\n\tunknown: %d", natUnknown)
+
+ *response = s
+ return nil
+}
+
+func (i *IPC) ProxyPolls(arg messages.Arg, response *[]byte) error {
+ sid, proxyType, natType, clients, err := messages.DecodePollRequest(arg.Body)
+ if err != nil {
+ return messages.ErrBadRequest
+ }
+
+ // Log geoip stats
+ remoteIP, _, err := net.SplitHostPort(arg.RemoteAddr)
+ if err != nil {
+ log.Println("Error processing proxy IP: ", err.Error())
+ } else {
+ i.ctx.metrics.lock.Lock()
+ i.ctx.metrics.UpdateCountryStats(remoteIP, proxyType, natType)
+ i.ctx.metrics.lock.Unlock()
+ }
+
+ var b []byte
+
+ // Wait for a client to avail an offer to the snowflake, or timeout if nil.
+ offer := i.ctx.RequestOffer(sid, proxyType, natType, clients)
+
+ if offer == nil {
+ i.ctx.metrics.lock.Lock()
+ i.ctx.metrics.proxyIdleCount++
+ i.ctx.metrics.promMetrics.ProxyPollTotal.With(prometheus.Labels{"nat": natType, "status": "idle"}).Inc()
+ i.ctx.metrics.lock.Unlock()
+
+ b, err = messages.EncodePollResponse("", false, "")
+ if err != nil {
+ return messages.ErrInternal
+ }
+
+ *response = b
+ return nil
+ }
+
+ i.ctx.metrics.promMetrics.ProxyPollTotal.With(prometheus.Labels{"nat": natType, "status": "matched"}).Inc()
+ b, err = messages.EncodePollResponse(string(offer.sdp), true, offer.natType)
+ if err != nil {
+ return messages.ErrInternal
+ }
+ *response = b
+
+ return nil
+}
+
+func sendClientResponse(resp *messages.ClientPollResponse, response *[]byte) error {
+ data, err := resp.EncodePollResponse()
+ if err != nil {
+ log.Printf("error encoding answer")
+ return messages.ErrInternal
+ } else {
+ *response = []byte(data)
+ return nil
+ }
+}
+
+func (i *IPC) ClientOffers(arg messages.Arg, response *[]byte) error {
+ var version clientVersion
+
+ startTime := time.Now()
+ body := arg.Body
+
+ if len(body) > 0 && body[0] == '{' {
+ version = v0
+ } else {
+ parts := bytes.SplitN(body, []byte("\n"), 2)
+ if len(parts) < 2 {
+ // no version number found
+ err := fmt.Errorf("unsupported message version")
+ return sendClientResponse(&messages.ClientPollResponse{Error: err.Error()}, response)
+ }
+ body = parts[1]
+ if string(parts[0]) == "1.0" {
+ version = v1
+
+ } else {
+ err := fmt.Errorf("unsupported message version")
+ return sendClientResponse(&messages.ClientPollResponse{Error: err.Error()}, response)
+ }
+ }
+
+ var offer *ClientOffer
+ switch version {
+ case v0:
+ offer = &ClientOffer{
+ natType: arg.NatType,
+ sdp: body,
+ }
+ case v1:
+ req, err := messages.DecodeClientPollRequest(body)
+ if err != nil {
+ return sendClientResponse(&messages.ClientPollResponse{Error: err.Error()}, response)
+ }
+ offer = &ClientOffer{
+ natType: req.NAT,
+ sdp: []byte(req.Offer),
+ }
+ default:
+ panic("unknown version")
+ }
+
+ // Only hand out known restricted snowflakes to unrestricted clients
+ var snowflakeHeap *SnowflakeHeap
+ if offer.natType == NATUnrestricted {
+ snowflakeHeap = i.ctx.restrictedSnowflakes
+ } else {
+ snowflakeHeap = i.ctx.snowflakes
+ }
+
+ // Immediately fail if there are no snowflakes available.
+ i.ctx.snowflakeLock.Lock()
+ numSnowflakes := snowflakeHeap.Len()
+ i.ctx.snowflakeLock.Unlock()
+ if numSnowflakes <= 0 {
+ i.ctx.metrics.lock.Lock()
+ i.ctx.metrics.clientDeniedCount++
+ i.ctx.metrics.promMetrics.ClientPollTotal.With(prometheus.Labels{"nat": offer.natType, "status": "denied"}).Inc()
+ if offer.natType == NATUnrestricted {
+ i.ctx.metrics.clientUnrestrictedDeniedCount++
+ } else {
+ i.ctx.metrics.clientRestrictedDeniedCount++
+ }
+ i.ctx.metrics.lock.Unlock()
+ switch version {
+ case v0:
+ return messages.ErrUnavailable
+ case v1:
+ resp := &messages.ClientPollResponse{Error: "no snowflake proxies currently available"}
+ return sendClientResponse(resp, response)
+ default:
+ panic("unknown version")
+ }
+ }
+
+ // Otherwise, find the most available snowflake proxy, and pass the offer to it.
+ // Delete must be deferred in order to correctly process answer request later.
+ i.ctx.snowflakeLock.Lock()
+ snowflake := heap.Pop(snowflakeHeap).(*Snowflake)
+ i.ctx.snowflakeLock.Unlock()
+ snowflake.offerChannel <- offer
+
+ var err error
+
+ // Wait for the answer to be returned on the channel or timeout.
+ select {
+ case answer := <-snowflake.answerChannel:
+ i.ctx.metrics.lock.Lock()
+ i.ctx.metrics.clientProxyMatchCount++
+ i.ctx.metrics.promMetrics.ClientPollTotal.With(prometheus.Labels{"nat": offer.natType, "status": "matched"}).Inc()
+ i.ctx.metrics.lock.Unlock()
+ switch version {
+ case v0:
+ *response = []byte(answer)
+ case v1:
+ resp := &messages.ClientPollResponse{Answer: answer}
+ err = sendClientResponse(resp, response)
+ default:
+ panic("unknown version")
+ }
+ // Initial tracking of elapsed time.
+ i.ctx.metrics.clientRoundtripEstimate = time.Since(startTime) / time.Millisecond
+ case <-time.After(time.Second * ClientTimeout):
+ log.Println("Client: Timed out.")
+ switch version {
+ case v0:
+ err = messages.ErrTimeout
+ case v1:
+ resp := &messages.ClientPollResponse{
+ Error: "timed out waiting for answer!"}
+ err = sendClientResponse(resp, response)
+ default:
+ panic("unknown version")
+ }
+ }
+
+ i.ctx.snowflakeLock.Lock()
+ i.ctx.metrics.promMetrics.AvailableProxies.With(prometheus.Labels{"nat": snowflake.natType, "type": snowflake.proxyType}).Dec()
+ delete(i.ctx.idToSnowflake, snowflake.id)
+ i.ctx.snowflakeLock.Unlock()
+
+ return err
+}
+
+func (i *IPC) ProxyAnswers(arg messages.Arg, response *[]byte) error {
+ answer, id, err := messages.DecodeAnswerRequest(arg.Body)
+ if err != nil || answer == "" {
+ return messages.ErrBadRequest
+ }
+
+ var success = true
+ i.ctx.snowflakeLock.Lock()
+ snowflake, ok := i.ctx.idToSnowflake[id]
+ i.ctx.snowflakeLock.Unlock()
+ if !ok || snowflake == nil {
+ // The snowflake took too long to respond with an answer, so its client
+ // disappeared / the snowflake is no longer recognized by the Broker.
+ success = false
+ }
+
+ b, err := messages.EncodeAnswerResponse(success)
+ if err != nil {
+ log.Printf("Error encoding answer: %s", err.Error())
+ return messages.ErrInternal
+ }
+ *response = b
+
+ if success {
+ snowflake.answerChannel <- answer
+ }
+
+ return nil
+}
diff --git a/broker/snowflake-broker_test.go b/broker/snowflake-broker_test.go
index 825bc6f..77e62cf 100644
--- a/broker/snowflake-broker_test.go
+++ b/broker/snowflake-broker_test.go
@@ -28,6 +28,7 @@ func TestBroker(t *testing.T) {
Convey("Context", t, func() {
ctx := NewBrokerContext(NullLogger())
+ i := &IPC{ctx}
Convey("Adds Snowflake", func() {
So(ctx.snowflakes.Len(), ShouldEqual, 0)
@@ -76,7 +77,7 @@ func TestBroker(t *testing.T) {
So(err, ShouldBeNil)
Convey("with error when no snowflakes are available.", func() {
- clientOffers(ctx, w, r)
+ clientOffers(i, w, r)
So(w.Code, ShouldEqual, http.StatusOK)
So(w.Body.String(), ShouldEqual, `{"error":"no snowflake proxies currently available"}`)
})
@@ -86,7 +87,7 @@ func TestBroker(t *testing.T) {
// Prepare a fake proxy to respond with.
snowflake := ctx.AddSnowflake("fake", "", NATUnrestricted, 0)
go func() {
- clientOffers(ctx, w, r)
+ clientOffers(i, w, r)
done <- true
}()
offer := <-snowflake.offerChannel
@@ -104,7 +105,7 @@ func TestBroker(t *testing.T) {
done := make(chan bool)
snowflake := ctx.AddSnowflake("fake", "", NATUnrestricted, 0)
go func() {
- clientOffers(ctx, w, r)
+ clientOffers(i, w, r)
// Takes a few seconds here...
done <- true
}()
@@ -124,7 +125,7 @@ func TestBroker(t *testing.T) {
r.Header.Set("Snowflake-NAT-TYPE", "restricted")
Convey("with 503 when no snowflakes are available.", func() {
- clientOffers(ctx, w, r)
+ clientOffers(i, w, r)
So(w.Code, ShouldEqual, http.StatusServiceUnavailable)
So(w.Body.String(), ShouldEqual, "")
})
@@ -134,7 +135,7 @@ func TestBroker(t *testing.T) {
// Prepare a fake proxy to respond with.
snowflake := ctx.AddSnowflake("fake", "", NATUnrestricted, 0)
go func() {
- clientOffers(ctx, w, r)
+ clientOffers(i, w, r)
done <- true
}()
offer := <-snowflake.offerChannel
@@ -152,7 +153,7 @@ func TestBroker(t *testing.T) {
done := make(chan bool)
snowflake := ctx.AddSnowflake("fake", "", NATUnrestricted, 0)
go func() {
- clientOffers(ctx, w, r)
+ clientOffers(i, w, r)
// Takes a few seconds here...
done <- true
}()
@@ -173,7 +174,7 @@ func TestBroker(t *testing.T) {
Convey("with a client offer if available.", func() {
go func(ctx *BrokerContext) {
- proxyPolls(ctx, w, r)
+ proxyPolls(i, w, r)
done <- true
}(ctx)
// Pass a fake client offer to this proxy
@@ -187,7 +188,7 @@ func TestBroker(t *testing.T) {
Convey("return empty 200 OK when no client offer is available.", func() {
go func(ctx *BrokerContext) {
- proxyPolls(ctx, w, r)
+ proxyPolls(i, w, r)
done <- true
}(ctx)
p := <-ctx.proxyPolls
@@ -209,7 +210,7 @@ func TestBroker(t *testing.T) {
r, err := http.NewRequest("POST", "snowflake.broker/answer", data)
So(err, ShouldBeNil)
go func(ctx *BrokerContext) {
- proxyAnswers(ctx, w, r)
+ proxyAnswers(i, w, r)
}(ctx)
answer := <-s.answerChannel
So(w.Code, ShouldEqual, http.StatusOK)
@@ -220,7 +221,7 @@ func TestBroker(t *testing.T) {
data = bytes.NewReader([]byte(`{"Version":"1.0","Sid":"invalid","Answer":"test"}`))
r, err := http.NewRequest("POST", "snowflake.broker/answer", data)
So(err, ShouldBeNil)
- proxyAnswers(ctx, w, r)
+ proxyAnswers(i, w, r)
So(w.Code, ShouldEqual, http.StatusOK)
b, err := ioutil.ReadAll(w.Body)
So(err, ShouldBeNil)
@@ -232,7 +233,7 @@ func TestBroker(t *testing.T) {
data := bytes.NewReader(nil)
r, err := http.NewRequest("POST", "snowflake.broker/answer", data)
So(err, ShouldBeNil)
- proxyAnswers(ctx, w, r)
+ proxyAnswers(i, w, r)
So(w.Code, ShouldEqual, http.StatusBadRequest)
})
@@ -240,7 +241,7 @@ func TestBroker(t *testing.T) {
data := bytes.NewReader(make([]byte, 100001))
r, err := http.NewRequest("POST", "snowflake.broker/answer", data)
So(err, ShouldBeNil)
- proxyAnswers(ctx, w, r)
+ proxyAnswers(i, w, r)
So(w.Code, ShouldEqual, http.StatusBadRequest)
})
@@ -250,6 +251,7 @@ func TestBroker(t *testing.T) {
Convey("End-To-End", t, func() {
ctx := NewBrokerContext(NullLogger())
+ i := &IPC{ctx}
Convey("Check for client/proxy data race", func() {
proxy_done := make(chan bool)
@@ -264,7 +266,7 @@ func TestBroker(t *testing.T) {
So(err, ShouldBeNil)
go func(ctx *BrokerContext) {
- proxyPolls(ctx, wp, rp)
+ proxyPolls(i, wp, rp)
proxy_done <- true
}(ctx)
@@ -275,7 +277,7 @@ func TestBroker(t *testing.T) {
So(err, ShouldBeNil)
go func() {
- clientOffers(ctx, wc, rc)
+ clientOffers(i, wc, rc)
client_done <- true
}()
@@ -288,7 +290,7 @@ func TestBroker(t *testing.T) {
rp, err = http.NewRequest("POST", "snowflake.broker/answer", datap)
So(err, ShouldBeNil)
go func(ctx *BrokerContext) {
- proxyAnswers(ctx, wp, rp)
+ proxyAnswers(i, wp, rp)
proxy_done <- true
}(ctx)
@@ -307,7 +309,7 @@ func TestBroker(t *testing.T) {
rP, err := http.NewRequest("POST", "snowflake.broker/proxy", dataP)
So(err, ShouldBeNil)
go func() {
- proxyPolls(ctx, wP, rP)
+ proxyPolls(i, wP, rP)
polled <- true
}()
@@ -328,7 +330,7 @@ func TestBroker(t *testing.T) {
rC, err := http.NewRequest("POST", "snowflake.broker/client", dataC)
So(err, ShouldBeNil)
go func() {
- clientOffers(ctx, wC, rC)
+ clientOffers(i, wC, rC)
done <- true
}()
@@ -341,7 +343,7 @@ func TestBroker(t *testing.T) {
dataA := bytes.NewReader([]byte(`{"Version":"1.0","Sid":"ymbcCMto7KHNGYlp","Answer":"test"}`))
rA, err := http.NewRequest("POST", "snowflake.broker/answer", dataA)
So(err, ShouldBeNil)
- proxyAnswers(ctx, wA, rA)
+ proxyAnswers(i, wA, rA)
So(wA.Code, ShouldEqual, http.StatusOK)
<-done
@@ -503,6 +505,7 @@ func TestMetrics(t *testing.T) {
done := make(chan bool)
buf := new(bytes.Buffer)
ctx := NewBrokerContext(log.New(buf, "", 0))
+ i := &IPC{ctx}
err := ctx.metrics.LoadGeoipDatabases("test_geoip", "test_geoip6")
So(err, ShouldEqual, nil)
@@ -514,10 +517,10 @@ func TestMetrics(t *testing.T) {
r, err := http.NewRequest("POST", "snowflake.broker/proxy", data)
r.RemoteAddr = "129.97.208.23:8888" //CA geoip
So(err, ShouldBeNil)
- go func(ctx *BrokerContext) {
- proxyPolls(ctx, w, r)
+ go func(i *IPC) {
+ proxyPolls(i, w, r)
done <- true
- }(ctx)
+ }(i)
p := <-ctx.proxyPolls //manually unblock poll
p.offerChannel <- nil
<-done
@@ -527,10 +530,10 @@ func TestMetrics(t *testing.T) {
r, err = http.NewRequest("POST", "snowflake.broker/proxy", data)
r.RemoteAddr = "129.97.208.23:8888" //CA geoip
So(err, ShouldBeNil)
- go func(ctx *BrokerContext) {
- proxyPolls(ctx, w, r)
+ go func(i *IPC) {
+ proxyPolls(i, w, r)
done <- true
- }(ctx)
+ }(i)
p = <-ctx.proxyPolls //manually unblock poll
p.offerChannel <- nil
<-done
@@ -540,10 +543,10 @@ func TestMetrics(t *testing.T) {
r, err = http.NewRequest("POST", "snowflake.broker/proxy", data)
r.RemoteAddr = "129.97.208.23:8888" //CA geoip
So(err, ShouldBeNil)
- go func(ctx *BrokerContext) {
- proxyPolls(ctx, w, r)
+ go func(i *IPC) {
+ proxyPolls(i, w, r)
done <- true
- }(ctx)
+ }(i)
p = <-ctx.proxyPolls //manually unblock poll
p.offerChannel <- nil
<-done
@@ -553,10 +556,10 @@ func TestMetrics(t *testing.T) {
r, err = http.NewRequest("POST", "snowflake.broker/proxy", data)
r.RemoteAddr = "129.97.208.23:8888" //CA geoip
So(err, ShouldBeNil)
- go func(ctx *BrokerContext) {
- proxyPolls(ctx, w, r)
+ go func(i *IPC) {
+ proxyPolls(i, w, r)
done <- true
- }(ctx)
+ }(i)
p = <-ctx.proxyPolls //manually unblock poll
p.offerChannel <- nil
<-done
@@ -573,7 +576,7 @@ func TestMetrics(t *testing.T) {
r, err := http.NewRequest("POST", "snowflake.broker/client", data)
So(err, ShouldBeNil)
- clientOffers(ctx, w, r)
+ clientOffers(i, w, r)
ctx.metrics.printMetrics()
So(buf.String(), ShouldContainSubstring, "client-denied-count 8\nclient-restricted-denied-count 8\nclient-unrestricted-denied-count 0\nclient-snowflake-match-count 0")
@@ -595,7 +598,7 @@ func TestMetrics(t *testing.T) {
// Prepare a fake proxy to respond with.
snowflake := ctx.AddSnowflake("fake", "", NATUnrestricted, 0)
go func() {
- clientOffers(ctx, w, r)
+ clientOffers(i, w, r)
done <- true
}()
offer := <-snowflake.offerChannel
@@ -614,49 +617,49 @@ func TestMetrics(t *testing.T) {
r, err := http.NewRequest("POST", "snowflake.broker/client", data)
So(err, ShouldBeNil)
- clientOffers(ctx, w, r)
+ clientOffers(i, w, r)
w = httptest.NewRecorder()
data = bytes.NewReader(
[]byte("1.0\n{\"offer\": \"fake\", \"nat\": \"restricted\"}"))
r, err = http.NewRequest("POST", "snowflake.broker/client", data)
So(err, ShouldBeNil)
- clientOffers(ctx, w, r)
+ clientOffers(i, w, r)
w = httptest.NewRecorder()
data = bytes.NewReader(
[]byte("1.0\n{\"offer\": \"fake\", \"nat\": \"restricted\"}"))
r, err = http.NewRequest("POST", "snowflake.broker/client", data)
So(err, ShouldBeNil)
- clientOffers(ctx, w, r)
+ clientOffers(i, w, r)
w = httptest.NewRecorder()
data = bytes.NewReader(
[]byte("1.0\n{\"offer\": \"fake\", \"nat\": \"restricted\"}"))
r, err = http.NewRequest("POST", "snowflake.broker/client", data)
So(err, ShouldBeNil)
- clientOffers(ctx, w, r)
+ clientOffers(i, w, r)
w = httptest.NewRecorder()
data = bytes.NewReader(
[]byte("1.0\n{\"offer\": \"fake\", \"nat\": \"restricted\"}"))
r, err = http.NewRequest("POST", "snowflake.broker/client", data)
So(err, ShouldBeNil)
- clientOffers(ctx, w, r)
+ clientOffers(i, w, r)
w = httptest.NewRecorder()
data = bytes.NewReader(
[]byte("1.0\n{\"offer\": \"fake\", \"nat\": \"restricted\"}"))
r, err = http.NewRequest("POST", "snowflake.broker/client", data)
So(err, ShouldBeNil)
- clientOffers(ctx, w, r)
+ clientOffers(i, w, r)
w = httptest.NewRecorder()
data = bytes.NewReader(
[]byte("1.0\n{\"offer\": \"fake\", \"nat\": \"restricted\"}"))
r, err = http.NewRequest("POST", "snowflake.broker/client", data)
So(err, ShouldBeNil)
- clientOffers(ctx, w, r)
+ clientOffers(i, w, r)
w = httptest.NewRecorder()
data = bytes.NewReader(
[]byte("1.0\n{\"offer\": \"fake\", \"nat\": \"restricted\"}"))
r, err = http.NewRequest("POST", "snowflake.broker/client", data)
So(err, ShouldBeNil)
- clientOffers(ctx, w, r)
+ clientOffers(i, w, r)
ctx.metrics.printMetrics()
So(buf.String(), ShouldContainSubstring, "client-denied-count 8\nclient-restricted-denied-count 8\nclient-unrestricted-denied-count 0\n")
@@ -666,7 +669,7 @@ func TestMetrics(t *testing.T) {
[]byte("1.0\n{\"offer\": \"fake\", \"nat\": \"restricted\"}"))
r, err = http.NewRequest("POST", "snowflake.broker/client", data)
So(err, ShouldBeNil)
- clientOffers(ctx, w, r)
+ clientOffers(i, w, r)
buf.Reset()
ctx.metrics.printMetrics()
So(buf.String(), ShouldContainSubstring, "client-denied-count 16\nclient-restricted-denied-count 16\nclient-unrestricted-denied-count 0\n")
@@ -680,7 +683,7 @@ func TestMetrics(t *testing.T) {
r.RemoteAddr = "129.97.208.23:8888" //CA geoip
So(err, ShouldBeNil)
go func(ctx *BrokerContext) {
- proxyPolls(ctx, w, r)
+ proxyPolls(i, w, r)
done <- true
}(ctx)
p := <-ctx.proxyPolls //manually unblock poll
@@ -693,10 +696,10 @@ func TestMetrics(t *testing.T) {
log.Printf("unable to get NewRequest with error: %v", err)
}
r.RemoteAddr = "129.97.208.23:8888" //CA geoip
- go func(ctx *BrokerContext) {
- proxyPolls(ctx, w, r)
+ go func(i *IPC) {
+ proxyPolls(i, w, r)
done <- true
- }(ctx)
+ }(i)
p = <-ctx.proxyPolls //manually unblock poll
p.offerChannel <- nil
<-done
@@ -711,10 +714,10 @@ func TestMetrics(t *testing.T) {
r, err := http.NewRequest("POST", "snowflake.broker/proxy", data)
r.RemoteAddr = "129.97.208.23:8888" //CA geoip
So(err, ShouldBeNil)
- go func(ctx *BrokerContext) {
- proxyPolls(ctx, w, r)
+ go func(i *IPC) {
+ proxyPolls(i, w, r)
done <- true
- }(ctx)
+ }(i)
p := <-ctx.proxyPolls //manually unblock poll
p.offerChannel <- nil
<-done
@@ -728,10 +731,10 @@ func TestMetrics(t *testing.T) {
log.Printf("unable to get NewRequest with error: %v", err)
}
r.RemoteAddr = "129.97.208.24:8888" //CA geoip
- go func(ctx *BrokerContext) {
- proxyPolls(ctx, w, r)
+ go func(i *IPC) {
+ proxyPolls(i, w, r)
done <- true
- }(ctx)
+ }(i)
p = <-ctx.proxyPolls //manually unblock poll
p.offerChannel <- nil
<-done
@@ -747,7 +750,7 @@ func TestMetrics(t *testing.T) {
r, err := http.NewRequest("POST", "snowflake.broker/client", data)
So(err, ShouldBeNil)
- clientOffers(ctx, w, r)
+ clientOffers(i, w, r)
ctx.metrics.printMetrics()
So(buf.String(), ShouldContainSubstring, "client-denied-count 8\nclient-restricted-denied-count 8\nclient-unrestricted-denied-count 0\nclient-snowflake-match-count 0")
@@ -760,7 +763,7 @@ func TestMetrics(t *testing.T) {
r, err = http.NewRequest("POST", "snowflake.broker/client", data)
So(err, ShouldBeNil)
- clientOffers(ctx, w, r)
+ clientOffers(i, w, r)
ctx.metrics.printMetrics()
So(buf.String(), ShouldContainSubstring, "client-denied-count 8\nclient-restricted-denied-count 0\nclient-unrestricted-denied-count 8\nclient-snowflake-match-count 0")
@@ -773,7 +776,7 @@ func TestMetrics(t *testing.T) {
r, err = http.NewRequest("POST", "snowflake.broker/client", data)
So(err, ShouldBeNil)
- clientOffers(ctx, w, r)
+ clientOffers(i, w, r)
ctx.metrics.printMetrics()
So(buf.String(), ShouldContainSubstring, "client-denied-count 8\nclient-restricted-denied-count 8\nclient-unrestricted-denied-count 0\nclient-snowflake-match-count 0")
diff --git a/common/messages/ipc.go b/common/messages/ipc.go
new file mode 100644
index 0000000..3f89200
--- /dev/null
+++ b/common/messages/ipc.go
@@ -0,0 +1,18 @@
+package messages
+
+import (
+ "errors"
+)
+
+type Arg struct {
+ Body []byte
+ RemoteAddr string
+ NatType string
+}
+
+var (
+ ErrBadRequest = errors.New("bad request")
+ ErrInternal = errors.New("internal error")
+ ErrUnavailable = errors.New("service unavailable")
+ ErrTimeout = errors.New("timeout")
+)
1
0