Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Tor Browser
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
The Tor Project
Applications
Tor Browser
Commits
fee7b513
Verified
Commit
fee7b513
authored
Jul 25, 2023
by
Pier Angelo Vendrame
Browse files
Options
Downloads
Patches
Plain Diff
fixup! Bug 40933: Add tor-launcher functionality
Use actual private members for TorProcess.
parent
c19ca457
Branches
Branches containing commit
No related tags found
1 merge request
!734
Bug 42030: Rebased 13.0 alpha onto Firefox 115.2.0esr
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
toolkit/components/tor-launcher/TorProcess.sys.mjs
+77
-77
77 additions, 77 deletions
toolkit/components/tor-launcher/TorProcess.sys.mjs
with
77 additions
and
77 deletions
toolkit/components/tor-launcher/TorProcess.sys.mjs
+
77
−
77
View file @
fee7b513
...
...
@@ -30,53 +30,53 @@ const logger = new ConsoleAPI({
});
export
class
TorProcess
{
_
exeFile
=
null
;
_
dataDir
=
null
;
_
args
=
[];
_
subprocess
=
null
;
_
status
=
TorProcessStatus
.
Unknown
;
_
torProcessStartTime
=
null
;
// JS Date.now()
_
didConnectToTorControlPort
=
false
;
// Have we ever made a connection?
#
exeFile
=
null
;
#
dataDir
=
null
;
#
args
=
[];
#
subprocess
=
null
;
#
status
=
TorProcessStatus
.
Unknown
;
#
torProcessStartTime
=
null
;
// JS Date.now()
#
didConnectToTorControlPort
=
false
;
// Have we ever made a connection?
onExit
=
null
;
onRestart
=
null
;
onExit
=
()
=>
{}
;
onRestart
=
()
=>
{}
;
get
status
()
{
return
this
.
_
status
;
return
this
.
#
status
;
}
get
isRunning
()
{
return
(
this
.
_
status
===
TorProcessStatus
.
Starting
||
this
.
_
status
===
TorProcessStatus
.
Running
this
.
#
status
===
TorProcessStatus
.
Starting
||
this
.
#
status
===
TorProcessStatus
.
Running
);
}
async
start
()
{
if
(
this
.
_
subprocess
)
{
if
(
this
.
#
subprocess
)
{
return
;
}
this
.
_
status
=
TorProcessStatus
.
Unknown
;
this
.
#
status
=
TorProcessStatus
.
Unknown
;
try
{
this
.
_
makeArgs
();
this
.
_
addControlPortArg
();
this
.
_
addSocksPortArg
();
this
.
#
makeArgs
();
this
.
#
addControlPortArg
();
this
.
#
addSocksPortArg
();
const
pid
=
Services
.
appinfo
.
processID
;
if
(
pid
!==
0
)
{
this
.
_
args
.
push
(
"
__OwningControllerProcess
"
);
this
.
_
args
.
push
(
""
+
pid
);
this
.
#
args
.
push
(
"
__OwningControllerProcess
"
);
this
.
#
args
.
push
(
""
+
pid
);
}
if
(
TorLauncherUtil
.
shouldShowNetworkSettings
)
{
this
.
_
args
.
push
(
"
DisableNetwork
"
);
this
.
_
args
.
push
(
"
1
"
);
this
.
#
args
.
push
(
"
DisableNetwork
"
);
this
.
#
args
.
push
(
"
1
"
);
}
this
.
_
status
=
TorProcessStatus
.
Starting
;
this
.
_
didConnectToTorControlPort
=
false
;
this
.
#
status
=
TorProcessStatus
.
Starting
;
this
.
#
didConnectToTorControlPort
=
false
;
// useful for simulating slow tor daemon launch
const
kPrefTorDaemonLaunchDelay
=
"
extensions.torlauncher.launch_delay
"
;
...
...
@@ -88,21 +88,21 @@ export class TorProcess {
await
new
Promise
(
resolve
=>
setTimeout
(()
=>
resolve
(),
launchDelay
));
}
logger
.
debug
(
`Starting
${
this
.
_
exeFile
.
path
}
`
,
this
.
_
args
);
logger
.
debug
(
`Starting
${
this
.
#
exeFile
.
path
}
`
,
this
.
#
args
);
const
options
=
{
command
:
this
.
_
exeFile
.
path
,
arguments
:
this
.
_
args
,
command
:
this
.
#
exeFile
.
path
,
arguments
:
this
.
#
args
,
stderr
:
"
stdout
"
,
workdir
:
TorLauncherUtil
.
getTorFile
(
"
pt-startup-dir
"
,
false
).
path
,
};
this
.
_
subprocess
=
await
Subprocess
.
call
(
options
);
this
.
_
dumpStdout
();
this
.
_
watchProcess
();
this
.
_
status
=
TorProcessStatus
.
Running
;
this
.
_
torProcessStartTime
=
Date
.
now
();
this
.
#
subprocess
=
await
Subprocess
.
call
(
options
);
this
.
#
dumpStdout
();
this
.
#
watchProcess
();
this
.
#
status
=
TorProcessStatus
.
Running
;
this
.
#
torProcessStartTime
=
Date
.
now
();
}
catch
(
e
)
{
this
.
_
status
=
TorProcessStatus
.
Exited
;
this
.
_
subprocess
=
null
;
this
.
#
status
=
TorProcessStatus
.
Exited
;
this
.
#
subprocess
=
null
;
logger
.
error
(
"
startTor error:
"
,
e
);
throw
e
;
}
...
...
@@ -123,36 +123,36 @@ export class TorProcess {
// Still, before closing the owning connection, this class should forget about
// the process, so that future notifications will be ignored.
forget
()
{
this
.
_
subprocess
=
null
;
this
.
_
status
=
TorProcessStatus
.
Exited
;
this
.
#
subprocess
=
null
;
this
.
#
status
=
TorProcessStatus
.
Exited
;
}
// The owner of the process can use this function to tell us that they
// successfully connected to the control port. This information will be used
// only to decide which text to show in the confirmation dialog if tor exits.
connectionWorked
()
{
this
.
_
didConnectToTorControlPort
=
true
;
this
.
#
didConnectToTorControlPort
=
true
;
}
async
_
dumpStdout
()
{
async
#
dumpStdout
()
{
let
string
;
while
(
this
.
_
subprocess
&&
(
string
=
await
this
.
_
subprocess
.
stdout
.
readString
())
this
.
#
subprocess
&&
(
string
=
await
this
.
#
subprocess
.
stdout
.
readString
())
)
{
dump
(
string
);
}
}
async
_
watchProcess
()
{
const
watched
=
this
.
_
subprocess
;
async
#
watchProcess
()
{
const
watched
=
this
.
#
subprocess
;
if
(
!
watched
)
{
return
;
}
try
{
const
{
exitCode
}
=
await
watched
.
wait
();
if
(
watched
!==
this
.
_
subprocess
)
{
if
(
watched
!==
this
.
#
subprocess
)
{
logger
.
debug
(
`A Tor process exited with code
${
exitCode
}
.`
);
}
else
if
(
exitCode
)
{
logger
.
warn
(
`The watched Tor process exited with code
${
exitCode
}
.`
);
...
...
@@ -163,18 +163,18 @@ export class TorProcess {
logger
.
error
(
"
Failed to watch the tor process
"
,
e
);
}
if
(
watched
===
this
.
_
subprocess
)
{
this
.
_
processExitedUnexpectedly
();
if
(
watched
===
this
.
#
subprocess
)
{
this
.
#
processExitedUnexpectedly
();
}
}
_
processExitedUnexpectedly
()
{
this
.
_
subprocess
=
null
;
this
.
_
status
=
TorProcessStatus
.
Exited
;
#
processExitedUnexpectedly
()
{
this
.
#
subprocess
=
null
;
this
.
#
status
=
TorProcessStatus
.
Exited
;
// TODO: Move this logic somewhere else?
let
s
;
if
(
!
this
.
_
didConnectToTorControlPort
)
{
if
(
!
this
.
#
didConnectToTorControlPort
)
{
// tor might be misconfigured, becauser we could never connect to it
const
key
=
"
tor_exited_during_startup
"
;
s
=
TorLauncherUtil
.
getLocalizedString
(
key
);
...
...
@@ -213,24 +213,24 @@ export class TorProcess {
}
}
_
makeArgs
()
{
#
makeArgs
()
{
// Ideally, we would cd to the Firefox application directory before
// starting tor (but we don't know how to do that). Instead, we
// rely on the TBB launcher to start Firefox from the right place.
// Get the Tor data directory first so it is created before we try to
// construct paths to files that will be inside it.
this
.
_
exeFile
=
TorLauncherUtil
.
getTorFile
(
"
tor
"
,
false
);
this
.
#
exeFile
=
TorLauncherUtil
.
getTorFile
(
"
tor
"
,
false
);
const
torrcFile
=
TorLauncherUtil
.
getTorFile
(
"
torrc
"
,
true
);
this
.
_
dataDir
=
TorLauncherUtil
.
getTorFile
(
"
tordatadir
"
,
true
);
this
.
#
dataDir
=
TorLauncherUtil
.
getTorFile
(
"
tordatadir
"
,
true
);
const
onionAuthDir
=
TorLauncherUtil
.
getTorFile
(
"
toronionauthdir
"
,
true
);
const
hashedPassword
=
lazy
.
TorProtocolService
.
torGetPassword
(
true
);
let
detailsKey
;
if
(
!
this
.
_
exeFile
)
{
if
(
!
this
.
#
exeFile
)
{
detailsKey
=
"
tor_missing
"
;
}
else
if
(
!
torrcFile
)
{
detailsKey
=
"
torrc_missing
"
;
}
else
if
(
!
this
.
_
dataDir
)
{
}
else
if
(
!
this
.
#
dataDir
)
{
detailsKey
=
"
datadir_missing
"
;
}
else
if
(
!
onionAuthDir
)
{
detailsKey
=
"
onionauthdir_missing
"
;
...
...
@@ -258,26 +258,26 @@ export class TorProcess {
const
geoip6File
=
torrcDefaultsFile
.
clone
();
geoip6File
.
leafName
=
"
geoip6
"
;
this
.
_
args
=
[];
this
.
#
args
=
[];
if
(
torrcDefaultsFile
)
{
this
.
_
args
.
push
(
"
--defaults-torrc
"
);
this
.
_
args
.
push
(
torrcDefaultsFile
.
path
);
}
this
.
_
args
.
push
(
"
-f
"
);
this
.
_
args
.
push
(
torrcFile
.
path
);
this
.
_
args
.
push
(
"
DataDirectory
"
);
this
.
_
args
.
push
(
this
.
_
dataDir
.
path
);
this
.
_
args
.
push
(
"
ClientOnionAuthDir
"
);
this
.
_
args
.
push
(
onionAuthDir
.
path
);
this
.
_
args
.
push
(
"
GeoIPFile
"
);
this
.
_
args
.
push
(
geoipFile
.
path
);
this
.
_
args
.
push
(
"
GeoIPv6File
"
);
this
.
_
args
.
push
(
geoip6File
.
path
);
this
.
_
args
.
push
(
"
HashedControlPassword
"
);
this
.
_
args
.
push
(
hashedPassword
);
}
_
addControlPortArg
()
{
this
.
#
args
.
push
(
"
--defaults-torrc
"
);
this
.
#
args
.
push
(
torrcDefaultsFile
.
path
);
}
this
.
#
args
.
push
(
"
-f
"
);
this
.
#
args
.
push
(
torrcFile
.
path
);
this
.
#
args
.
push
(
"
DataDirectory
"
);
this
.
#
args
.
push
(
this
.
#
dataDir
.
path
);
this
.
#
args
.
push
(
"
ClientOnionAuthDir
"
);
this
.
#
args
.
push
(
onionAuthDir
.
path
);
this
.
#
args
.
push
(
"
GeoIPFile
"
);
this
.
#
args
.
push
(
geoipFile
.
path
);
this
.
#
args
.
push
(
"
GeoIPv6File
"
);
this
.
#
args
.
push
(
geoip6File
.
path
);
this
.
#
args
.
push
(
"
HashedControlPassword
"
);
this
.
#
args
.
push
(
hashedPassword
);
}
#
addControlPortArg
()
{
// Include a ControlPort argument to support switching between
// a TCP port and an IPC port (e.g., a Unix domain socket). We
// include a "+__" prefix so that (1) this control port is added
...
...
@@ -287,17 +287,17 @@ export class TorProcess {
const
controlIPCFile
=
lazy
.
TorProtocolService
.
torGetControlIPCFile
();
const
controlPort
=
lazy
.
TorProtocolService
.
torGetControlPort
();
if
(
controlIPCFile
)
{
controlPortArg
=
this
.
_
ipcPortArg
(
controlIPCFile
);
controlPortArg
=
this
.
#
ipcPortArg
(
controlIPCFile
);
}
else
if
(
controlPort
)
{
controlPortArg
=
""
+
controlPort
;
}
if
(
controlPortArg
)
{
this
.
_
args
.
push
(
"
+__ControlPort
"
);
this
.
_
args
.
push
(
controlPortArg
);
this
.
#
args
.
push
(
"
+__ControlPort
"
);
this
.
#
args
.
push
(
controlPortArg
);
}
}
_
addSocksPortArg
()
{
#
addSocksPortArg
()
{
// Include a SocksPort argument to support switching between
// a TCP port and an IPC port (e.g., a Unix domain socket). We
// include a "+__" prefix so that (1) this SOCKS port is added
...
...
@@ -307,7 +307,7 @@ export class TorProcess {
if
(
socksPortInfo
)
{
let
socksPortArg
;
if
(
socksPortInfo
.
ipcFile
)
{
socksPortArg
=
this
.
_
ipcPortArg
(
socksPortInfo
.
ipcFile
);
socksPortArg
=
this
.
#
ipcPortArg
(
socksPortInfo
.
ipcFile
);
}
else
if
(
socksPortInfo
.
host
&&
socksPortInfo
.
port
!=
0
)
{
socksPortArg
=
socksPortInfo
.
host
+
"
:
"
+
socksPortInfo
.
port
;
}
...
...
@@ -319,8 +319,8 @@ export class TorProcess {
if
(
socksPortFlags
)
{
socksPortArg
+=
"
"
+
socksPortFlags
;
}
this
.
_
args
.
push
(
"
+__SocksPort
"
);
this
.
_
args
.
push
(
socksPortArg
);
this
.
#
args
.
push
(
"
+__SocksPort
"
);
this
.
#
args
.
push
(
socksPortArg
);
}
}
}
...
...
@@ -328,7 +328,7 @@ export class TorProcess {
// Return a ControlPort or SocksPort argument for aIPCFile (an nsIFile).
// The result is unix:/path or unix:"/path with spaces" with appropriate
// C-style escaping within the path portion.
_
ipcPortArg
(
aIPCFile
)
{
#
ipcPortArg
(
aIPCFile
)
{
return
"
unix:
"
+
TorParsers
.
escapeString
(
aIPCFile
.
path
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment