Skip to content
Snippets Groups Projects
Verified Commit 16cf26ff authored by Pier Angelo Vendrame's avatar Pier Angelo Vendrame 🎃
Browse files

fixup! Bug 3455: Add DomainIsolator, for isolating circuit by domain.

Actually added the new circuit button.
parent bcabee6b
Branches
No related tags found
1 merge request!632Bug 41741: Refactor the domain isolator and new circuit
......@@ -61,6 +61,11 @@
<toolbarbutton id="appMenu-new-identity"
class="subviewbutton"
key="new-identity-key"/>
<toolbarbutton id="appMenuNewCircuit"
class="subviewbutton"
key="new-circuit-key"
label="&torbutton.context_menu.new_circuit_sentence_case;"
oncommand="TorDomainIsolator.newCircuitForBrowser(gBrowser);"/>
<toolbarseparator/>
<toolbarbutton id="appMenu-bookmarks-button"
class="subviewbutton subviewbutton-nav"
......
......@@ -31,6 +31,11 @@
<menuseparator/>
<menuitem id="menu_newIdentity"
key="new-identity-key"/>
<menuitem id="menu_newCircuit"
accesskey="&torbutton.context_menu.new_circuit_key;"
key="new-circuit-key"
label="&torbutton.context_menu.new_circuit;"
oncommand="TorDomainIsolator.newCircuitForBrowser(gBrowser);"/>
<menuseparator/>
<menuitem id="menu_openLocation"
hidden="true"
......
......@@ -389,4 +389,5 @@
internal="true"/>
#endif
<key id="new-identity-key" modifiers="accel shift" key="U" oncommand="NewIdentityButton.onCommand(event)"/>
<key id="new-circuit-key" modifiers="accel shift" key="L" oncommand="TorDomainIsolator.newCircuitForBrowser(gBrowser)"/>
</keyset>
......@@ -80,6 +80,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
TabCrashHandler: "resource:///modules/ContentCrashHandlers.jsm",
TelemetryEnvironment: "resource://gre/modules/TelemetryEnvironment.jsm",
TorConnect: "resource:///modules/TorConnect.jsm",
TorDomainIsolator: "resource://gre/modules/TorDomainIsolator.jsm",
Translation: "resource:///modules/translation/TranslationParent.jsm",
UITour: "resource:///modules/UITour.jsm",
UpdateUtils: "resource://gre/modules/UpdateUtils.jsm",
......
......@@ -555,6 +555,11 @@
<toolbarbutton id="new-identity-button" class="toolbarbutton-1 chromeclass-toolbar-additional"/>
<toolbarbutton id="new-circuit-button" class="toolbarbutton-1 chromeclass-toolbar-additional"
label="&torbutton.context_menu.new_circuit;"
oncommand="TorDomainIsolator.newCircuitForBrowser(gBrowser);"
tooltiptext="&torbutton.context_menu.new_circuit;"/>
<toolbarbutton id="fullscreen-button" class="toolbarbutton-1 chromeclass-toolbar-additional"
observes="View:FullScreen"
type="checkbox"
......
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M10.5994 2.89744C9.52191 2.34851 8.2983 2.15477 7.10392 2.34398C6.64247 2.41708 6.19453 2.5459 5.76923 2.72578C5.82159 2.91042 5.84961 3.10529 5.84961 3.3067C5.84961 4.48031 4.89821 5.4317 3.72461 5.4317C2.551 5.4317 1.59961 4.48031 1.59961 3.3067C1.59961 2.1331 2.551 1.1817 3.72461 1.1817C4.23757 1.1817 4.70808 1.36346 5.07525 1.66608C5.65429 1.3987 6.27072 1.21038 6.90834 1.10937C8.36342 0.878863 9.85413 1.11489 11.1668 1.78364C12.4795 2.45239 13.5468 3.51953 14.2158 4.83212C14.8848 6.14471 15.121 7.63538 14.8907 9.0905C14.8368 9.43143 14.5167 9.66408 14.1757 9.61013C13.8348 9.55617 13.6022 9.23605 13.6561 8.89511C13.8451 7.70071 13.6512 6.47713 13.1021 5.39971C12.553 4.3223 11.6769 3.44636 10.5994 2.89744ZM4.64961 3.3067C4.64961 3.81756 4.23547 4.2317 3.72461 4.2317C3.21375 4.2317 2.79961 3.81756 2.79961 3.3067C2.79961 2.79584 3.21375 2.3817 3.72461 2.3817C4.23547 2.3817 4.64961 2.79584 4.64961 3.3067Z" fill="context-fill"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M1.82421 6.38991C2.16514 6.44387 2.39779 6.76399 2.34383 7.10492C2.15482 8.29933 2.34875 9.52291 2.89785 10.6003C3.44695 11.6777 4.32303 12.5537 5.40053 13.1026C6.47803 13.6515 7.70165 13.8453 8.89602 13.6561C9.35628 13.5831 9.8031 13.4548 10.2274 13.2757C10.1734 13.0884 10.1445 12.8906 10.1445 12.686C10.1445 11.5124 11.0959 10.561 12.2695 10.561C13.4431 10.561 14.3945 11.5124 14.3945 12.686C14.3945 13.8596 13.4431 14.811 12.2695 14.811C11.7602 14.811 11.2927 14.6318 10.9267 14.333C10.3471 14.6009 9.72997 14.7895 9.0916 14.8907C7.63652 15.1212 6.14581 14.8851 4.83311 14.2164C3.52042 13.5476 2.45311 12.4805 1.78415 11.1679C1.11519 9.85533 0.878921 8.36466 1.1092 6.90954C1.16315 6.56861 1.48327 6.33596 1.82421 6.38991ZM13.1945 12.686C13.1945 13.1968 12.7804 13.611 12.2695 13.611C11.7587 13.611 11.3445 13.1968 11.3445 12.686C11.3445 12.1751 11.7587 11.761 12.2695 11.761C12.7804 11.761 13.1945 12.1751 13.1945 12.686Z" fill="context-fill"/>
</svg>
......@@ -267,3 +267,5 @@
skin/classic/browser/syncedtabs/sidebar.css (../shared/syncedtabs/sidebar.css)
skin/classic/browser/new_identity.svg (../shared/icons/new_identity.svg)
skin/classic/browser/new_circuit.svg (../shared/icons/new_circuit.svg)
......@@ -267,6 +267,10 @@ toolbar {
list-style-image: url("chrome://browser/skin/new_identity.svg");
}
#new-circuit-button {
list-style-image: url("chrome://browser/skin/new_circuit.svg");
}
#privatebrowsing-button {
list-style-image: url("chrome://browser/skin/privateBrowsing.svg");
}
......
......@@ -116,34 +116,25 @@ class TorDomainIsolatorImpl {
this.#noncesForUserContextId.set(userContextId, nonce);
}
return {
username: `${firstPartyDomain}:${userContextId}`,
username: this.#makeUsername(firstPartyDomain, userContextId),
password:
this.#noncesForDomains.get(firstPartyDomain) +
this.#noncesForUserContextId.get(userContextId),
};
}
// Re-generate the nonce for a certain domain.
newCircuitForDomain(domain) {
if (!domain) {
domain = CATCHALL_DOMAIN;
}
this.#noncesForDomains.set(domain, this.#nonce());
logger.info(
`New domain isolation for ${domain}: ${this.#noncesForDomains.get(
domain
)}`
);
}
// Re-generate the nonce for a userContextId.
newCircuitForUserContextId(userContextId) {
this.#noncesForUserContextId.set(userContextId, this.#nonce());
logger.info(
`New container isolation for ${userContextId}: ${this.#noncesForUserContextId.get(
userContextId
)}`
);
/**
* Create a new nonce for the FP domain of the selected browser and reload the
* tab with a new circuit.
*
* @param browser Should be the gBrowser from the context of the caller
*/
newCircuitForBrowser(browser) {
const firstPartyDomain = getDomainForBrowser(browser.selectedBrowser);
this.#newCircuitForDomain(firstPartyDomain);
// TODO: How to properly handle the user context? Should we use
// (domain, userContextId) pairs, instead of concatenating nonces?
browser.reloadWithFlags(Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE);
}
/**
......@@ -207,7 +198,7 @@ class TorDomainIsolatorImpl {
logger.info(
"tor catchall circuit has been dirty for over 10 minutes. Rotating."
);
this.newCircuitForDomain(CATCHALL_DOMAIN);
this.#newCircuitForDomain(CATCHALL_DOMAIN);
this.#catchallDirtySince = Date.now();
}
}
......@@ -262,6 +253,16 @@ class TorDomainIsolatorImpl {
);
}
/**
* Combine the needed data into a username for the proxy.
*/
#makeUsername(domain, userContextId) {
if (!domain) {
domain = CATCHALL_DOMAIN;
}
return `${domain}:${userContextId}`;
}
/**
* Generate a new 128 bit random tag.
*
......@@ -274,6 +275,88 @@ class TorDomainIsolatorImpl {
byte.toString(16).padStart(2, "0")
).join("");
}
/**
* Re-generate the nonce for a certain domain.
*/
#newCircuitForDomain(domain) {
if (!domain) {
domain = CATCHALL_DOMAIN;
}
this.#noncesForDomains.set(domain, this.#nonce());
logger.info(
`New domain isolation for ${domain}: ${this.#noncesForDomains.get(
domain
)}`
);
}
/**
* Re-generate the nonce for a userContextId.
*
* Currently, this function is not hooked to anything.
*/
#newCircuitForUserContextId(userContextId) {
this.#noncesForUserContextId.set(userContextId, this.#nonce());
logger.info(
`New container isolation for ${userContextId}: ${this.#noncesForUserContextId.get(
userContextId
)}`
);
}
}
/**
* Get the first party domain for a certain browser.
*
* @param browser The browser to get the FP-domain for.
*
* Please notice that it should be gBrowser.selectedBrowser, because
* browser.documentURI is the actual shown page, and might be an error page.
* In this case, we rely on currentURI, which for gBrowser is an alias of
* gBrowser.selectedBrowser.currentURI.
* See browser/base/content/tabbrowser.js and tor-browser#31562.
*/
function getDomainForBrowser(browser) {
let fpd = browser.contentPrincipal.originAttributes.firstPartyDomain;
// Bug 31562: For neterror or certerror, get the original URL from
// browser.currentURI and use it to calculate the firstPartyDomain.
const knownErrors = [
"about:neterror",
"about:certerror",
"about:httpsonlyerror",
];
const { documentURI } = browser;
if (
documentURI &&
documentURI.schemeIs("about") &&
knownErrors.some(x => documentURI.spec.startsWith(x))
) {
const knownSchemes = ["http", "https"];
const currentURI = browser.currentURI;
if (currentURI && knownSchemes.some(x => currentURI.schemeIs(x))) {
try {
fpd = Services.eTLD.getBaseDomainFromHost(currentURI.host);
} catch (e) {
if (
e.result === Cr.NS_ERROR_HOST_IS_IP_ADDRESS ||
e.result === Cr.NS_ERROR_INSUFFICIENT_DOMAIN_LEVELS
) {
fpd = currentURI.host;
} else {
logger.error(
`Failed to get first party domain for host ${currentURI.host}`,
e
);
}
}
}
}
return fpd;
}
const TorDomainIsolator = new TorDomainIsolatorImpl();
// Reduce global vars pollution
TorDomainIsolator.getDomainForBrowser = getDomainForBrowser;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment