Fix Tails/OnionGrater Quoted Response Issue

This commit is contained in:
Sarah Jamie Lewis 2023-04-04 15:06:18 -07:00
parent 5996d426c1
commit a68c0fd160
4 changed files with 23 additions and 8 deletions

View File

@ -1,9 +1,8 @@
package control
import (
"strings"
"git.openprivacy.ca/openprivacy/bine/torutil"
"strings"
)
// Signal invokes SIGNAL.

1
go.mod
View File

@ -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

View File

@ -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"

View File

@ -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,