Whonix Support

This commit is contained in:
Sarah Jamie Lewis 2023-08-14 12:42:47 -07:00
parent a68c0fd160
commit b353f78908
1 changed files with 14 additions and 2 deletions

View File

@ -126,8 +126,20 @@ func (t *Tor) Listen(ctx context.Context, conf *ListenConf) (*OnionService, erro
// Create the local listener if necessary
svc.LocalListener = conf.LocalListener
if svc.LocalListener == nil {
if svc.LocalListener, err = net.Listen("tcp", "127.0.0.1:"+strconv.Itoa(conf.LocalPort)); err != nil {
return nil, err
// To support whonix, and other systems that require external port binding:
// If BINE_WHONIX is explictly enabled AND the given directory exists, then bind to an
// external port.
// See: https://www.whonix.org/wiki/Dev/Project_friendly_applications_best_practices#Listening_Port
if bineWhonix := os.Getenv("BINE_WHONIX"); strings.ToLower(bineWhonix) == "true" {
if _, err := os.Stat("/usr/share/anon-ws-base-files/workstation"); !os.IsNotExist(err) {
if svc.LocalListener, err = net.Listen("tcp", "0.0.0.0:"+strconv.Itoa(conf.LocalPort)); err != nil {
return nil, err
}
}
} else {
if svc.LocalListener, err = net.Listen("tcp", "127.0.0.1:"+strconv.Itoa(conf.LocalPort)); err != nil {
return nil, err
}
}
}