From a68c0fd1605cc4d693ddc338a7ab1f93b16012ed Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Tue, 4 Apr 2023 15:06:18 -0700 Subject: [PATCH] Fix Tails/OnionGrater Quoted Response Issue --- control/cmd_misc.go | 3 +-- go.mod | 1 + tor/dialer.go | 21 ++++++++++++++++----- torutil/string.go | 6 +++++- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/control/cmd_misc.go b/control/cmd_misc.go index fe2742d..dd8dab8 100644 --- a/control/cmd_misc.go +++ b/control/cmd_misc.go @@ -1,9 +1,8 @@ package control import ( - "strings" - "git.openprivacy.ca/openprivacy/bine/torutil" + "strings" ) // Signal invokes SIGNAL. diff --git a/go.mod b/go.mod index b14cab6..2594883 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module git.openprivacy.ca/openprivacy/bine go 1.14 require ( + git.openprivacy.ca/openprivacy/log v1.0.3 github.com/stretchr/testify v1.6.1 golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee golang.org/x/net v0.0.0-20201010224723-4f7140c49acb diff --git a/tor/dialer.go b/tor/dialer.go index 522955b..2cb61d5 100644 --- a/tor/dialer.go +++ b/tor/dialer.go @@ -78,12 +78,23 @@ func (t *Tor) Dialer(ctx context.Context, conf *DialConf) (*Dialer, error) { if len(info) != 1 || info[0].Key != "net/listeners/socks" { return nil, fmt.Errorf("Unable to get socks proxy address") } - proxyAddress = info[0].Val - if strings.HasPrefix(proxyAddress, "unix:") { - proxyAddress = proxyAddress[5:] - proxyNetwork = "unix" - } else { + + if strings.HasPrefix(info[0].Val, "\"") { + options := strings.Split(info[0].Val, " ") + // we get this kind of response from Tails / OnionGrater, multiple potential listeners + // formatted. Simply choose the first one. + // NOTE: This logic is probably not the best... + proxyAddress = options[0][1 : len(options[0])-1] proxyNetwork = "tcp" + } else { + + proxyAddress = info[0].Val + if strings.HasPrefix(proxyAddress, "unix:") { + proxyAddress = proxyAddress[5:] + proxyNetwork = "unix" + } else { + proxyNetwork = "tcp" + } } } else if proxyNetwork == "" { proxyNetwork = "tcp" diff --git a/torutil/string.go b/torutil/string.go index 86cee96..d594283 100644 --- a/torutil/string.go +++ b/torutil/string.go @@ -70,7 +70,11 @@ func UnescapeSimpleQuotedString(str string) (string, error) { if len(str) < 2 || str[0] != '"' || str[len(str)-1] != '"' { return "", fmt.Errorf("Missing quotes") } - return UnescapeSimpleQuotedStringContents(str[1 : len(str)-1]) + if str, err := UnescapeSimpleQuotedStringContents(str[1 : len(str)-1]); err == nil { + return str, nil + } + // Assume this wasn't quoted + return str, nil } // UnescapeSimpleQuotedStringContents unescapes backslashes, double quotes,