Compare commits
4 Commits
Author | SHA1 | Date |
---|---|---|
Sarah Jamie Lewis | e2dda25e37 | |
Sarah Jamie Lewis | a68c0fd160 | |
Dan Ballard | 5996d426c1 | |
Sarah Jamie Lewis | e353e4c70d |
|
@ -1,9 +1,8 @@
|
|||
package control
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"git.openprivacy.ca/openprivacy/bine/torutil"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Signal invokes SIGNAL.
|
||||
|
|
1
go.mod
1
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
|
||||
|
|
|
@ -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"
|
||||
|
|
18
tor/tor.go
18
tor/tor.go
|
@ -173,11 +173,25 @@ func Start(ctx context.Context, conf *StartConf) (*Tor, error) {
|
|||
if err == nil {
|
||||
err = tor.startProcess(ctx, conf)
|
||||
}
|
||||
time.Sleep(time.Second)
|
||||
|
||||
|
||||
// Connect the controller
|
||||
if err == nil {
|
||||
err = tor.connectController(ctx, conf)
|
||||
for attempts := 0; attempts < 10; attempts++ {
|
||||
err = tor.connectController(ctx, conf)
|
||||
if err == nil {
|
||||
break
|
||||
} else {
|
||||
// backoff and retry
|
||||
// max is 1 + 2 + 3 + 4 + 5...+10 = ~55 seconds
|
||||
// After which point there is probably something else very wrong
|
||||
// TODO: It might be worth breaking out the error here so that we can distinguish a
|
||||
// slow socket (on e.g. Android) with a failed setup.
|
||||
time.Sleep(time.Duration(int(time.Second) * attempts))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Attempt eager auth w/ no password
|
||||
if err == nil && !conf.DisableEagerAuth {
|
||||
err = tor.Control.Authenticate("")
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue