From b353f78908e8a2e98cdc2e1274ebf7e657d07421 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Mon, 14 Aug 2023 12:42:47 -0700 Subject: [PATCH] Whonix Support --- tor/listen.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tor/listen.go b/tor/listen.go index 2d01131..b829a3d 100644 --- a/tor/listen.go +++ b/tor/listen.go @@ -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 + } } }