Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

tor frontend changes for 0.23.x #14143

Merged
merged 79 commits into from
Jun 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
a160ac4
Tor MVP
riastradh-brave Jan 8, 2018
573b628
0.23.1
May 3, 2018
2ffd60e
fixes to tor build scripts
diracdeltas May 3, 2018
3e49022
initialize Tor partition at startup
diracdeltas May 7, 2018
d4bf124
Link to Tor FAQ in newtab, update muon, disable safebrowsing
diracdeltas May 7, 2018
b934bc5
add basic tor webdriver tests
diracdeltas May 12, 2018
69a879c
Update Muon to 6.1.4 and use stable tor binaries
bsclifton May 16, 2018
1d854ef
0.23.5
May 16, 2018
00788aa
update package-lock to fix nsp issue
diracdeltas May 16, 2018
91a5d76
0.23.6
May 16, 2018
cfadfb8
fix tor wiki link
diracdeltas May 17, 2018
4c989bf
Open link in new private tab should use tor if enabled
diracdeltas May 17, 2018
afe8ad3
Styling fixes based on david's feedback
diracdeltas May 17, 2018
76d1d78
update to muon 6.1.5
diracdeltas May 17, 2018
77add80
updated hash
jumde May 17, 2018
fd8174b
Update to new extra-private icon
diracdeltas May 17, 2018
f684ab6
0.23.7
May 17, 2018
4af30aa
Updated Tor private tab styling and layout
rossmoody May 21, 2018
4e85674
add tor tab indicator
diracdeltas May 22, 2018
6925b98
Talk to the control socket using my old draft tor daemon manager. (#1…
riastradh-brave May 22, 2018
69f2d50
turn tor to default off
diracdeltas May 31, 2018
cf945d6
Update tor binaries to stable version
jumde May 31, 2018
8eecf40
0.23.8
Jun 8, 2018
9b5b9d7
Fixes: #14374 Show warning if torrent files are opened in tor private…
jumde Jun 11, 2018
82eddde
Bump to muon 6.1.6
diracdeltas Jun 13, 2018
2615479
block webrtc functions via content script in tor tabs
diracdeltas May 24, 2018
c7d5598
Open Tor FAQ in Tor private tab if Tor is enabled
diracdeltas Jun 14, 2018
65ef32a
Close control_auth_cookie as soon as we're done with it.
riastradh-brave Jun 14, 2018
737d5e9
Fix vestigial error message.
riastradh-brave Jun 14, 2018
c4f0c4e
Fix netflix notification from tor tabs appearing on normal tabs
diracdeltas Jun 14, 2018
df68653
Add tor loading progress UI
diracdeltas Jun 6, 2018
9fbeb47
Fix session store unittest by adding tor property
diracdeltas Jun 15, 2018
3e0a1a0
0.23.9
Jun 15, 2018
74452fd
use correct version of chromdriver in ci build for current muon versi…
petemill Jun 15, 2018
668dfbf
0.23.10
Jun 15, 2018
07ed002
re-running npm install to fix nsp security issue
diracdeltas Jun 18, 2018
5b93829
Update to c67
diracdeltas Jun 19, 2018
a0365bb
0.23.11
Jun 19, 2018
9120d88
Tor 0.3.3.7 hash
jumde Jun 19, 2018
559c51d
Update package-lock for 0.23.11
diracdeltas Jun 19, 2018
64bdfd5
add tor menu items, make tor switch per tab
diracdeltas Jun 19, 2018
d3ff082
Implement DDG changes for #14459
diracdeltas Jun 20, 2018
67ba785
More UI tweaks
diracdeltas Jun 20, 2018
497086b
address review comments related to tor window handling
diracdeltas Jun 20, 2018
6ee0b76
Update Muon to 7.1.1
bsclifton Jun 21, 2018
5f86e02
Tab icon for tor tabs
petemill Jun 21, 2018
9c05c1a
0.23.12
Jun 21, 2018
f10a161
Don't show Tor error immediately on circuit established error
diracdeltas Jun 21, 2018
3a3f0cd
defense in depth against Flash/ledger running on tor tabs (#14482)
diracdeltas Jun 21, 2018
86a4ec7
Move control port and control cookie out of the way before reading.
riastradh-brave Jun 21, 2018
87d6e0b
0.23.13
Jun 22, 2018
cc65734
Adapt package_tor.js to the mingw build of tor. (#14507)
riastradh-brave Jun 22, 2018
0faffb3
0.23.14
Jun 22, 2018
f680baf
Bypass https://nodesecurity.io/advisories/664 temporarily
bsclifton Jun 22, 2018
78b5c9b
Remove NSP bypass and fix NSP error
diracdeltas Jun 22, 2018
bd596e6
increase Tor reconnection timeout
diracdeltas Jun 22, 2018
98fd9a9
Reverse order in which we read tor control port and auth cookie.
riastradh-brave Jun 22, 2018
4b53452
Fix !&#@&*!$& typo.
riastradh-brave Jun 22, 2018
5648cb3
Paranoia: stop watching the fs when tor daemon is not running.
riastradh-brave Jun 22, 2018
db880d2
0.23.15
Jun 22, 2018
42da7b8
disable URLbar context menu while tor is initializing
diracdeltas Jun 22, 2018
291ffaf
fix tor-related webtorrent issues
diracdeltas Jun 22, 2018
05a41bd
clarify that duckduckgo is a global setting
diracdeltas Jun 23, 2018
37ac751
Explicitly disable safe browsing since it is enabled by default
darkdh Jun 23, 2018
d554ab7
Fix context menu search engine in private/tor tabs
diracdeltas Jun 23, 2018
5396f03
0.23.16
Jun 23, 2018
2abf2a2
Get the version number from tor.
riastradh-brave Jun 25, 2018
b084122
Update Muon to 7.1.2
bsclifton Jun 25, 2018
5bb04f4
Print the tor version number to console as a demo.
riastradh-brave Jun 25, 2018
2864078
Show Tor version in about:brave
bsclifton Jun 25, 2018
97d41d2
0.23.17
Jun 25, 2018
9f0a4a1
Connect to 127.0.0.1, not localhost, for tor control channel. Tweak …
riastradh-brave Jun 26, 2018
c54ef3d
Add beta label to Tor Private Tab title
petemill Jun 26, 2018
84dc7f5
0.23.18
Jun 26, 2018
37f1a87
Update to muon 7.1.3
diracdeltas Jun 26, 2018
a435361
Add button to restart tor without restarting brave
diracdeltas Jun 27, 2018
178c3fb
0.23.19
Jun 27, 2018
06624a0
Make polling for tor restart work. Call setupTor only once.
riastradh-brave Jun 27, 2018
2dbd90b
Merge pull request #14585 from brave/riastradh-tor-fixrepoll
bsclifton Jun 28, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,6 @@ app/extensions/brave/content/scripts/sync.js

# script used for signing for widevine
signature_generator.py

# binaries
app/extensions/bin
4 changes: 2 additions & 2 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
runtime = electron
target_arch = x64
brave_electron_version = 7.0.6
brave_electron_version = 7.1.3
chromedriver_version = 2.37
target = v7.0.6
target = v7.1.3
disturl=https://brave-laptop-binaries.s3.amazonaws.com/atom-shell/dist/
build_from_source = true
6 changes: 5 additions & 1 deletion app/browser/api/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const format = require('date-fns/format')
const Immutable = require('immutable')
const electron = require('electron')
const ipc = electron.ipcMain
const session = electron.session
const path = require('path')
const os = require('os')
const qr = require('qr-image')
Expand All @@ -32,6 +33,7 @@ const updateState = require('../../common/state/updateState')
// Constants
const settings = require('../../../js/constants/settings')
const messages = require('../../../js/constants/messages')
const appConfig = require('../../../js/constants/appConfig')
const ledgerStatuses = require('../../common/constants/ledgerStatuses')

// Utils
Expand Down Expand Up @@ -863,7 +865,9 @@ const shouldTrackTab = (state, tabId) => {
if (tabFromState == null) {
tabFromState = pageDataState.getLastClosedTab(state, tabId)
}
const isPrivate = !tabFromState.get('partition', '').startsWith('persist:') || tabFromState.get('incognito')
const partition = tabFromState.get('partition', '')
const ses = session.fromPartition(partition)
const isPrivate = (ses && ses.isOffTheRecord()) || tabFromState.get('incognito') || partition === appConfig.tor.partition
return !isPrivate && !tabFromState.isEmpty() && ledgerUtil.shouldTrackView(tabFromState)
}

Expand Down
10 changes: 9 additions & 1 deletion app/browser/contentSettings/hostContentSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,27 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */

const { makeImmutable } = require('../../common/state/immutableUtil')
const appConfig = require('../../../js/constants/appConfig')

let registeredCallbacks = []
let registeredSessions = {}
let registeredPrivateSessions = {}
const blockContentSetting = { setting: 'block', primaryPattern: '*' }

module.exports.setContentSettings = (contentSettings, incognito) => {
contentSettings = makeImmutable(contentSettings)

const partitions = incognito ? registeredPrivateSessions : registeredSessions
for (let partition in partitions) {
let newContentSettings = contentSettings
if (partition === appConfig.tor.partition) {
// Do not allow plugins to be enabled in Tor contexts
newContentSettings = contentSettings.set('plugins', makeImmutable([blockContentSetting]))
}

const ses = partitions[partition]

contentSettings.forEach((settings, contentType) => {
newContentSettings.forEach((settings, contentType) => {
ses.contentSettings.clearForOneType(contentType)
settings.forEach((setting) => {
module.exports.setContentSetting(ses, setting.get('primaryPattern'), setting.get('secondaryPattern'),
Expand Down
1 change: 1 addition & 0 deletions app/browser/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const createFileSubmenu = () => {
const submenu = [
CommonMenu.newTabMenuItem(),
CommonMenu.newPrivateTabMenuItem(),
CommonMenu.newTorTabMenuItem(),
CommonMenu.newPartitionedTabMenuItem(),
CommonMenu.newWindowMenuItem(),
CommonMenu.separatorMenuItem,
Expand Down
21 changes: 20 additions & 1 deletion app/browser/reducers/tabsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const tabState = require('../../common/state/tabState')
const windowState = require('../../common/state/windowState')
const siteSettings = require('../../../js/state/siteSettings')
const siteSettingsState = require('../../common/state/siteSettingsState')
const {frameOptsFromFrame} = require('../../../js/state/frameStateUtil')
const {frameOptsFromFrame, isTor} = require('../../../js/state/frameStateUtil')
const updateState = require('../../common/state/updateState')

// Constants
Expand Down Expand Up @@ -51,6 +51,10 @@ const getWebRTCPolicy = (state, tabId) => {
return webrtcConstants.default
}

if (isTor(tabValue)) {
return webrtcConstants.disableNonProxiedUdp
}

const allSiteSettings = siteSettingsState.getAllSiteSettings(state, tabValue.get('incognito') === true)
const tabSiteSettings =
siteSettings.getSiteSettingsForURL(allSiteSettings, tabValue.get('url'))
Expand Down Expand Up @@ -254,6 +258,21 @@ const tabsReducer = (state, action, immutableAction) => {
}
})
break
case appConstants.APP_RECREATE_TOR_TAB:
{
const tabId = action.get('tabId')
tabs.create({
url: 'about:newtab',
isPrivate: true,
windowId: tabState.getWindowId(state, tabId),
index: action.get('index'),
active: true,
isTor: action.get('torEnabled')
}, (tab) => {
appActions.tabCloseRequested(tabId)
})
break
}
case appConstants.APP_TAB_UPDATED:
state = tabState.maybeCreateTab(state, action)
// tabs.debugTabs(state)
Expand Down
31 changes: 31 additions & 0 deletions app/browser/reducers/torReducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

'use strict'

const filtering = require('../../filtering')
const appConstants = require('../../../js/constants/appConstants')

const torReducer = (state, action) => {
switch (action.actionType) {
case appConstants.APP_RESTART_TOR:
filtering.relaunchTor()
break
case appConstants.APP_SET_TOR_NEW_IDENTITY:
filtering.setTorNewIdentity(action.url, action.tabId)
break
case appConstants.APP_ON_TOR_INIT_ERROR:
state = state.setIn(['tor', 'initializationError'], action.message)
break
case appConstants.APP_ON_TOR_INIT_SUCCESS:
state = state.setIn(['tor', 'initializationError'], false).setIn(['tor', 'percentInitialized'], null)
break
case appConstants.APP_ON_TOR_INIT_PERCENTAGE:
state = state.setIn(['tor', 'percentInitialized'], action.percentage)
break
}
return state
}

module.exports = torReducer
38 changes: 36 additions & 2 deletions app/browser/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ const { shouldDebugTabEvents } = require('../cmdLine')
const tabState = require('../common/state/tabState')
const {app, extensions, session, ipcMain} = require('electron')
const {makeImmutable, makeJS} = require('../common/state/immutableUtil')
const {getTargetAboutUrl, getSourceAboutUrl, isSourceAboutUrl, newFrameUrl, isTargetAboutUrl, isIntermediateAboutPage, isTargetMagnetUrl, getSourceMagnetUrl} = require('../../js/lib/appUrlUtil')
const {getExtensionsPath, getTargetAboutUrl, getSourceAboutUrl, isSourceAboutUrl, newFrameUrl, isTargetAboutUrl, isIntermediateAboutPage, isTargetMagnetUrl, getSourceMagnetUrl} = require('../../js/lib/appUrlUtil')
const {isURL, getUrlFromInput, toPDFJSLocation, getDefaultFaviconUrl, isHttpOrHttps, getLocationIfPDF} = require('../../js/lib/urlutil')
const {isSessionPartition} = require('../../js/state/frameStateUtil')
const {isSessionPartition, isTor} = require('../../js/state/frameStateUtil')
const {getOrigin} = require('../../js/lib/urlutil')
const settingsStore = require('../../js/settings')
const settings = require('../../js/constants/settings')
const {getBaseUrl} = require('../../js/lib/appUrlUtil')
const siteSettings = require('../../js/state/siteSettings')
const messages = require('../../js/constants/messages')
const webrtcConstants = require('../../js/constants/webrtcConstants')
const debounce = require('../../js/lib/debounce')
const aboutHistoryState = require('../common/state/aboutHistoryState')
const aboutNewTabState = require('../common/state/aboutNewTabState')
Expand All @@ -38,6 +39,8 @@ const bookmarkOrderCache = require('../common/cache/bookmarkOrderCache')
const ledgerState = require('../common/state/ledgerState')
const {getWindow, notifyWindowWebContentsAdded} = require('./windows')
const activeTabHistory = require('./activeTabHistory')
const path = require('path')
const {getTorSocksProxy} = require('../channel')

let adBlockRegions
let currentPartitionNumber = 0
Expand Down Expand Up @@ -101,6 +104,8 @@ const getPartition = (createProperties) => {
let partition = session.defaultSession.partition
if (createProperties.partition) {
partition = createProperties.partition
} else if (createProperties.isTor) {
partition = appConfig.tor.partition
} else if (createProperties.isPrivate) {
partition = 'default'
} else if (createProperties.isPartitioned) {
Expand All @@ -114,6 +119,7 @@ const getPartition = (createProperties) => {

const needsPartitionAssigned = (createProperties) => {
return !createProperties.openerTabId ||
createProperties.isTor ||
createProperties.isPrivate ||
createProperties.isPartitioned ||
createProperties.partitionNumber ||
Expand Down Expand Up @@ -340,12 +346,14 @@ const updateAboutDetails = (tabId) => {
const trackedBlockersCount = appState.getIn(['trackingProtection', 'count'], 0)
const httpsUpgradedCount = appState.getIn(['httpsEverywhere', 'count'], 0)
const adblockCount = appState.getIn(['adblock', 'count'], 0)
const torEnabled = isTor(getTabValue(tabId))
sendAboutDetails(tabId, messages.NEWTAB_DATA_UPDATED, {
showEmptyPage,
showImages,
trackedBlockersCount,
adblockCount,
httpsUpgradedCount,
torEnabled,
newTabDetail: newTabDetail.toJS()
})
} else if (location === 'about:autofill') {
Expand Down Expand Up @@ -511,6 +519,13 @@ const api = {
index = newTabValue.get('index')
}

const ses = session.fromPartition(newTab.session.partition)
let isPrivate
if (ses) {
isPrivate = ses.isOffTheRecord()
}
const isTor = newTab.session.partition === appConfig.tor.partition

const frameOpts = {
location,
displayURL,
Expand All @@ -519,6 +534,8 @@ const api = {
active: !!newTabValue.get('active'),
guestInstanceId: newTab.guestInstanceId,
isPinned: !!newTabValue.get('pinned'),
isPrivate,
isTor,
openerTabId,
disposition,
index,
Expand Down Expand Up @@ -1048,6 +1065,17 @@ const api = {
if (isSessionPartition(createProperties.partition)) {
createProperties.parent_partition = ''
}
if (createProperties.isTor) {
// TODO(riastradh): Duplicate logic in app/filtering.js.
createProperties.isolated_storage = true
createProperties.parent_partition = ''
createProperties.tor_proxy = getTorSocksProxy()
if (process.platform === 'win32') {
createProperties.tor_path = path.join(getExtensionsPath('bin'), 'tor.exe')
} else {
createProperties.tor_path = path.join(getExtensionsPath('bin'), 'tor')
}
}
}

// Tabs are allowed to be initially discarded (unloaded) if they are regular tabs
Expand All @@ -1068,6 +1096,12 @@ const api = {
console.log('Creating tab with properties: ', createProperties)
}
extensions.createTab(createProperties, (tab) => {
if (tab) {
// Initialize WebRTC IP handling to the safest default. This will
// be set based on shield settings in reducers/tabReducer.js once
// navigation starts.
tab.setWebRTCIPHandlingPolicy(webrtcConstants.disableNonProxiedUdp)
}
cb && cb(tab)
})
}
Expand Down
2 changes: 2 additions & 0 deletions app/browser/webtorrent.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,7 @@ function getHeader (headers, headerName) {

module.exports = {
init,
isTorrentFile,
isMagnetURL,
resourceName: 'webtorrent'
}
3 changes: 2 additions & 1 deletion app/browser/windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,12 @@ function openFramesInWindow (win, frames, activeFrameKey) {
let frameIndex = -1
for (const frame of frames) {
frameIndex++
const tab = webContentsCache.getWebContents(frame.tabId)
if (frame.tabId != null && frame.guestInstanceId != null) {
if (shouldDebugTabEvents) {
console.log('notifyWindowWebContentsAdded: on window create with existing tab', win.id)
}
api.notifyWindowWebContentsAdded(win.id, frame)
const tab = webContentsCache.getWebContents(frame.tabId)
if (tab && !tab.isDestroyed()) {
tab.moveTo(frameIndex, win.id)
}
Expand All @@ -226,6 +226,7 @@ function openFramesInWindow (win, frames, activeFrameKey) {
url: frame.location || frame.src || frame.provisionalLocation || frame.url,
partitionNumber: frame.partitionNumber,
isPrivate: frame.isPrivate,
isTor: frame.isTor || (tab && tab.session && tab.session.partition === appConfig.tor.partition),
active: activeFrameKey ? frame.key === activeFrameKey : true,
discarded: frame.unloaded,
title: frame.title,
Expand Down
31 changes: 31 additions & 0 deletions app/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,34 @@ exports.getLinuxDesktopName = () => {
}
return desktopName
}

// getTorSocksProxy()
//
// Return the socks5:// `URL' for the Tor socks proxy we will
// configure the tor daemon to listen on and muon to connect to,
// depending on which channel we're using. This is provisional
// until we let the OS choose the port number as in
// <https://github.com/brave/browser-laptop/issues/12936>, or
// until we add support for local sockets for SOCKS proxies as in
// <https://github.com/brave/muon/issues/469>.
//
exports.getTorSocksProxy = () => {
let portno
switch (channel) {
case 'dev':
case '':
default:
portno = 9250
break
case 'beta':
portno = 9260
break
case 'nightly':
portno = 9270
break
case 'developer':
portno = 9280
break
}
return `socks5://127.0.0.1:${portno}`
}
15 changes: 14 additions & 1 deletion app/common/commonMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const messages = require('../../js/constants/messages')
const locale = require('../../js/l10n')
const settings = require('../../js/constants/settings')
const {tabs} = require('../../js/constants/config')
const getSetting = require('../../js/settings').getSetting
const {getSetting} = require('../../js/settings')
const communityURL = 'https://community.brave.com/'
const isDarwin = process.platform === 'darwin'
const electron = require('electron')
Expand Down Expand Up @@ -85,6 +85,19 @@ module.exports.newPrivateTabMenuItem = () => {
}
}

module.exports.newTorTabMenuItem = () => {
return {
label: locale.translation('newTorTab'),
click: function (item, focusedWindow) {
ensureAtLeastOneWindow({
url: 'about:newtab',
isPrivate: true,
isTor: true
})
}
}
}

module.exports.newPartitionedTabMenuItem = () => {
const newPartitionedMenuItem = (partitionNumber) => ({
label: `${locale.translation('newSessionTab')} ${partitionNumber}`,
Expand Down
12 changes: 10 additions & 2 deletions app/common/lib/suggestion.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ const sigmoid = (t) => {

const ONE_DAY = 1000 * 60 * 60 * 24

const searchSuggestionsEnabled = (state, tabId) => {
const frame = getFrameByTabId(state, tabId)
if (!frame || frame.get('isPrivate')) {
return false
}
return getSetting(settings.OFFER_SEARCH_SUGGESTIONS)
}

/*
* Calculate the sorting priority for a history item based on number of
* accesses and time since last access
Expand Down Expand Up @@ -564,7 +572,7 @@ const getSearchSuggestions = (state, tabId, urlLocationLower) => {
return new Promise((resolve, reject) => {
const mapListToElements = getMapListToElements(urlLocationLower)
let suggestionsList = Immutable.List()
if (getSetting(settings.OFFER_SEARCH_SUGGESTIONS)) {
if (searchSuggestionsEnabled(state, tabId)) {
const searchResults = state.get('searchResults')
const sortHandler = getSortForSearchSuggestions(urlLocationLower)
if (searchResults) {
Expand Down Expand Up @@ -630,7 +638,7 @@ const generateNewSearchXHRResults = debounce((state, windowId, tabId, input) =>
? frameSearchDetail.get('autocomplete')
: searchDetail.get('autocompleteURL')

const shouldDoSearchSuggestions = getSetting(settings.OFFER_SEARCH_SUGGESTIONS) &&
const shouldDoSearchSuggestions = searchSuggestionsEnabled(state, tabId) &&
autocompleteURL &&
!isUrl(input) &&
input.length !== 0
Expand Down
Loading