diff --git a/go.mod b/go.mod index 0c7787e9..9af4eee9 100644 --- a/go.mod +++ b/go.mod @@ -11,8 +11,7 @@ require ( github.com/cznic/mathutil v0.0.0-20181122101859-297441e03548 // indirect github.com/cznic/strutil v0.0.0-20181122101858-275e90344537 // indirect github.com/dsnet/compress v0.0.1 - github.com/eyedeekay/goSam v0.32.28 - github.com/eyedeekay/sam3 v0.32.3 // indirect + github.com/eyedeekay/goSam v0.32.29 github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51 // indirect github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 // indirect github.com/facebookgo/subset v0.0.0-20150612182917-8dac2c3c4870 // indirect diff --git a/go.sum b/go.sum index 34983e1b..42c6afac 100644 --- a/go.sum +++ b/go.sum @@ -144,10 +144,14 @@ github.com/eyedeekay/goSam v0.32.27 h1:yYdL384sLPge4K0vK7l7v4vBakrK/kf6qW9hQ7uyW github.com/eyedeekay/goSam v0.32.27/go.mod h1:YIklxqKiJ3I5JNRgb5pM7VCQOSNDGnVulHnrKBbbECM= github.com/eyedeekay/goSam v0.32.28 h1:8O9aDGr45EIS82TRm4x0xAnGnz6ZHW0/8oyqziYiN9U= github.com/eyedeekay/goSam v0.32.28/go.mod h1:YIklxqKiJ3I5JNRgb5pM7VCQOSNDGnVulHnrKBbbECM= +github.com/eyedeekay/goSam v0.32.29 h1:LHDYz0rBCKk7hwmsu17xBLJmauwThzvU9/9WZ6lQDDQ= +github.com/eyedeekay/goSam v0.32.29/go.mod h1:PNJAmTMvSmH10S0aEspgOovzGFph8qXBwjH/HgO2oJI= github.com/eyedeekay/ramp v0.0.0-20190429201811-305b382042ab/go.mod h1:h7mvUAMgZ/rtRDUOkvKTK+8LnDMeUhJSoa5EPdB51fc= github.com/eyedeekay/sam3 v0.32.2/go.mod h1:Y3igFVzN4ybqkkpfUWULGhw7WRp8lieq0ORXbLBbcZM= github.com/eyedeekay/sam3 v0.32.3 h1:PW1vQoo2H7c3Q4l2DngJqpSdsdJprMCk9NOkUHtcdmM= github.com/eyedeekay/sam3 v0.32.3/go.mod h1:qRA9KIIVxbrHlkj+ZB+OoxFGFgdKeGp1vSgPw26eOVU= +github.com/eyedeekay/sam3 v0.32.32-0.20201122050855-f464873c9350 h1:8R4zcaWsgANiZ4MKKBPUf9Isct2M1IFVUVZdAMqPCmU= +github.com/eyedeekay/sam3 v0.32.32-0.20201122050855-f464873c9350/go.mod h1:qRA9KIIVxbrHlkj+ZB+OoxFGFgdKeGp1vSgPw26eOVU= github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64= github.com/facebookgo/stack v0.0.0-20160209184415-751773369052/go.mod h1:UbMTZqLaRiH3MsBH8va0n7s1pQYcu3uTb8G4tygF4Zg= github.com/facebookgo/subset v0.0.0-20150612182917-8dac2c3c4870/go.mod h1:5tD+neXqOorC30/tWg0LCSkrqj/AR6gu8yY8/fpw1q0= @@ -156,6 +160,14 @@ github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= +github.com/getlantern/context v0.0.0-20190109183933-c447772a6520/go.mod h1:L+mq6/vvYHKjCX2oez0CgEAJmbq1fbb/oNJIWQkBybY= +github.com/getlantern/errors v1.0.1/go.mod h1:l+xpFBrCtDLpK9qNjxs+cHU6+BAdlBaxHqikB6Lku3A= +github.com/getlantern/go-socks5 v0.0.0-20171114193258-79d4dd3e2db5/go.mod h1:kGHRXch95rnGLHjER/GhhFiHvfnqNz7KqWD9kGfATHY= +github.com/getlantern/golog v0.0.0-20201105130739-9586b8bde3a9/go.mod h1:ZyIjgH/1wTCl+B+7yH1DqrWp6MPJqESmwmEQ89ZfhvA= +github.com/getlantern/hex v0.0.0-20190417191902-c6586a6fe0b7/go.mod h1:dD3CgOrwlzca8ed61CsZouQS5h5jIzkK9ZWrTcf0s+o= +github.com/getlantern/hidden v0.0.0-20190325191715-f02dbb02be55/go.mod h1:6mmzY2kW1TOOrVy+r41Za2MxXM+hhqTtY3oBKd2AgFA= +github.com/getlantern/netx v0.0.0-20190110220209-9912de6f94fd/go.mod h1:wKdY0ikOgzrWSeB9UyBVKPRhjXQ+vTb+BPeJuypUuNE= +github.com/getlantern/ops v0.0.0-20190325191751-d70cb0d6f85f/go.mod h1:D5ao98qkA6pxftxoqzibIBBrLSUli+kYnJqrgBf9cIA= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/glycerine/go-unsnap-stream v0.0.0-20181221182339-f9677308dec2/go.mod h1:/20jfyN9Y5QPEAprSgKAUr+glWDY39ZiUEAYOEv5dsE= github.com/glycerine/go-unsnap-stream v0.0.0-20190901134440-81cf024a9e0a h1:FQqoVvjbiUioBBFUL5up+h+GdCa/AnJsL/1bIs/veSI= @@ -350,6 +362,7 @@ github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1Cpa github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw= github.com/oracle/oci-go-sdk v7.0.0+incompatible/go.mod h1:VQb79nF8Z2cwLkLS35ukwStZIg5F66tcBccjip/j888= github.com/ovh/go-ovh v0.0.0-20181109152953-ba5adb4cf014/go.mod h1:joRatxRJaZBsY3JAOEMcoOp05CnZzsx4scTxi95DHyQ= +github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pelletier/go-toml v1.8.0 h1:Keo9qb7iRJs2voHvunFtuuYFsbWeOBh8/P9v/kVMFtw= diff --git a/vendor/github.com/eyedeekay/goSam/.gitignore b/vendor/github.com/eyedeekay/goSam/.gitignore index b0e54296..3751227e 100644 --- a/vendor/github.com/eyedeekay/goSam/.gitignore +++ b/vendor/github.com/eyedeekay/goSam/.gitignore @@ -23,3 +23,4 @@ _testmain.go itp-golang-github-eyedeekay-gosam.txt .pc deb/ +samsocks/samsocks diff --git a/vendor/github.com/eyedeekay/goSam/Makefile b/vendor/github.com/eyedeekay/goSam/Makefile index c73825aa..38ce64bb 100644 --- a/vendor/github.com/eyedeekay/goSam/Makefile +++ b/vendor/github.com/eyedeekay/goSam/Makefile @@ -1,6 +1,6 @@ USER_GH=eyedeekay -VERSION=0.32.28 +VERSION=0.32.29 packagename=gosam echo: fmt diff --git a/vendor/github.com/eyedeekay/goSam/README.md b/vendor/github.com/eyedeekay/goSam/README.md index d39e25d3..2cdca043 100644 --- a/vendor/github.com/eyedeekay/goSam/README.md +++ b/vendor/github.com/eyedeekay/goSam/README.md @@ -3,10 +3,10 @@ goSam A go library for using the [I2P](https://geti2p.net/en/) Simple Anonymous Messaging ([SAM version 3.0](https://geti2p.net/en/docs/api/samv3)) bridge. It -has support for SAM version 3.1 signature types. +has support for all streaming features SAM version 3.2. -This is in an **early development stage**. I would love to hear about any -issues or ideas for improvement. +This is widely used and easy to use, but thusfar, mostly by me. It sees a lot of +testing and no breaking changes to the API are expected. ## Installation ``` @@ -15,7 +15,7 @@ go get github.com/eyedeekay/goSam ## Using it for HTTP Transport -I implemented `Client.Dial` like `net.Dial` so you can use go's library packages like http. +`Client.Dial` implements `net.Dial` so you can use go's library packages like http. ```go package main @@ -70,6 +70,52 @@ func checkErr(err error) { } ``` +## Using it as a SOCKS proxy + +`client` also implements a resolver compatible with +[`getlantern/go-socks5`](https://github.com/getlantern/go-socks5), +making it very easy to implement a SOCKS5 server. + +```go +package main + +import ( + "flag" + + "github.com/eyedeekay/goSam" + "github.com/getlantern/go-socks5" + "log" +) + +var ( + samaddr = flag.String("sam", "127.0.0.1:7656", "SAM API address to use") + socksaddr = flag.String("socks", "127.0.0.1:7675", "SOCKS address to use") +) + +func main() { + sam, err := goSam.NewClient(*samaddr) + if err != nil { + panic(err) + } + log.Println("Client Created") + + // create a transport that uses SAM to dial TCP Connections + conf := &socks5.Config{ + Dial: sam.DialContext, + Resolver: sam, + } + server, err := socks5.New(conf) + if err != nil { + panic(err) + } + + // Create SOCKS5 proxy on localhost port 8000 + if err := server.ListenAndServe("tcp", *socksaddr); err != nil { + panic(err) + } +} +``` + ### .deb package A package for installing this on Debian is buildable, and a version for Ubuntu diff --git a/vendor/github.com/eyedeekay/goSam/client.go b/vendor/github.com/eyedeekay/goSam/client.go index cafd1958..1798bbdb 100644 --- a/vendor/github.com/eyedeekay/goSam/client.go +++ b/vendor/github.com/eyedeekay/goSam/client.go @@ -55,6 +55,7 @@ type Client struct { lastaddr string id int32 ml sync.Mutex + oml sync.Mutex } var SAMsigTypes = []string{ diff --git a/vendor/github.com/eyedeekay/goSam/dial.go b/vendor/github.com/eyedeekay/goSam/dial.go index 50b426c0..c820ce1c 100644 --- a/vendor/github.com/eyedeekay/goSam/dial.go +++ b/vendor/github.com/eyedeekay/goSam/dial.go @@ -9,6 +9,8 @@ import ( // DialContext implements the net.DialContext function and can be used for http.Transport func (c *Client) DialContext(ctx context.Context, network, addr string) (net.Conn, error) { + c.oml.Lock() + defer c.oml.Unlock() errCh := make(chan error, 1) connCh := make(chan net.Conn, 1) go func() { @@ -26,7 +28,9 @@ func (c *Client) DialContext(ctx context.Context, network, addr string) (net.Con }() select { case err := <-errCh: - return nil, err + // var err error + c, err = c.NewClient() + return c.SamConn, err case conn := <-connCh: return conn, nil case <-ctx.Done(): @@ -40,7 +44,6 @@ func (c *Client) dialCheck(addr string) (int32, bool) { return c.NewID(), true } else if c.lastaddr != addr { fmt.Println("Preparing to dial next new address.") - return c.NewID(), true } return c.id, false } diff --git a/vendor/github.com/eyedeekay/goSam/go.mod b/vendor/github.com/eyedeekay/goSam/go.mod index 159bc0aa..cd436349 100644 --- a/vendor/github.com/eyedeekay/goSam/go.mod +++ b/vendor/github.com/eyedeekay/goSam/go.mod @@ -1,6 +1,11 @@ module github.com/eyedeekay/goSam -require github.com/eyedeekay/sam3 v0.32.2 +require ( + github.com/eyedeekay/sam3 v0.32.32-0.20201122050855-f464873c9350 + github.com/getlantern/go-socks5 v0.0.0-20171114193258-79d4dd3e2db5 + github.com/getlantern/golog v0.0.0-20201105130739-9586b8bde3a9 // indirect + github.com/getlantern/netx v0.0.0-20190110220209-9912de6f94fd // indirect +) //replace github.com/eyedeekay/gosam v0.1.1-0.20190814195658-27e786578944 => github.com/eyedeekay/goSam ./ diff --git a/vendor/github.com/eyedeekay/goSam/go.sum b/vendor/github.com/eyedeekay/goSam/go.sum index 30187b66..effd6167 100644 --- a/vendor/github.com/eyedeekay/goSam/go.sum +++ b/vendor/github.com/eyedeekay/goSam/go.sum @@ -1,4 +1,31 @@ +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/eyedeekay/ramp v0.0.0-20190429201811-305b382042ab h1:EfTRHxGSbiaEyxNzvKRBWVIDw3mD8xXGxj4gvwFzY7Q= github.com/eyedeekay/ramp v0.0.0-20190429201811-305b382042ab/go.mod h1:h7mvUAMgZ/rtRDUOkvKTK+8LnDMeUhJSoa5EPdB51fc= github.com/eyedeekay/sam3 v0.32.2 h1:xODDY5nBVg0oK7KaYk7ofkXFoHPsmI1umhSv1TZlS7s= github.com/eyedeekay/sam3 v0.32.2/go.mod h1:Y3igFVzN4ybqkkpfUWULGhw7WRp8lieq0ORXbLBbcZM= +github.com/eyedeekay/sam3 v0.32.31 h1:0fdDAupEQZSETHcyVQAsnFgpYArGJzU+lC2qN6f0GDk= +github.com/eyedeekay/sam3 v0.32.32-0.20201122050855-f464873c9350 h1:8R4zcaWsgANiZ4MKKBPUf9Isct2M1IFVUVZdAMqPCmU= +github.com/eyedeekay/sam3 v0.32.32-0.20201122050855-f464873c9350/go.mod h1:qRA9KIIVxbrHlkj+ZB+OoxFGFgdKeGp1vSgPw26eOVU= +github.com/getlantern/context v0.0.0-20190109183933-c447772a6520 h1:NRUJuo3v3WGC/g5YiyF790gut6oQr5f3FBI88Wv0dx4= +github.com/getlantern/context v0.0.0-20190109183933-c447772a6520/go.mod h1:L+mq6/vvYHKjCX2oez0CgEAJmbq1fbb/oNJIWQkBybY= +github.com/getlantern/errors v1.0.1 h1:XukU2whlh7OdpxnkXhNH9VTLVz0EVPGKDV5K0oWhvzw= +github.com/getlantern/errors v1.0.1/go.mod h1:l+xpFBrCtDLpK9qNjxs+cHU6+BAdlBaxHqikB6Lku3A= +github.com/getlantern/go-socks5 v0.0.0-20171114193258-79d4dd3e2db5 h1:RBKofGGMt2k6eGBwX8mky9qunjL+KnAp9JdzXjiRkRw= +github.com/getlantern/go-socks5 v0.0.0-20171114193258-79d4dd3e2db5/go.mod h1:kGHRXch95rnGLHjER/GhhFiHvfnqNz7KqWD9kGfATHY= +github.com/getlantern/golog v0.0.0-20201105130739-9586b8bde3a9 h1:8MYJU90rB1bsavemKSAuDKBjtAKo5xq95bEPOnzV7CE= +github.com/getlantern/golog v0.0.0-20201105130739-9586b8bde3a9/go.mod h1:ZyIjgH/1wTCl+B+7yH1DqrWp6MPJqESmwmEQ89ZfhvA= +github.com/getlantern/hex v0.0.0-20190417191902-c6586a6fe0b7 h1:micT5vkcr9tOVk1FiH8SWKID8ultN44Z+yzd2y/Vyb0= +github.com/getlantern/hex v0.0.0-20190417191902-c6586a6fe0b7/go.mod h1:dD3CgOrwlzca8ed61CsZouQS5h5jIzkK9ZWrTcf0s+o= +github.com/getlantern/hidden v0.0.0-20190325191715-f02dbb02be55 h1:XYzSdCbkzOC0FDNrgJqGRo8PCMFOBFL9py72DRs7bmc= +github.com/getlantern/hidden v0.0.0-20190325191715-f02dbb02be55/go.mod h1:6mmzY2kW1TOOrVy+r41Za2MxXM+hhqTtY3oBKd2AgFA= +github.com/getlantern/netx v0.0.0-20190110220209-9912de6f94fd h1:mn98vs69Kqw56iKhR82mjk16Q1q5aDFFW0E89/QbXkQ= +github.com/getlantern/netx v0.0.0-20190110220209-9912de6f94fd/go.mod h1:wKdY0ikOgzrWSeB9UyBVKPRhjXQ+vTb+BPeJuypUuNE= +github.com/getlantern/ops v0.0.0-20190325191751-d70cb0d6f85f h1:wrYrQttPS8FHIRSlsrcuKazukx/xqO/PpLZzZXsF+EA= +github.com/getlantern/ops v0.0.0-20190325191751-d70cb0d6f85f/go.mod h1:D5ao98qkA6pxftxoqzibIBBrLSUli+kYnJqrgBf9cIA= +github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw= +github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= diff --git a/vendor/github.com/eyedeekay/goSam/replyParser.go b/vendor/github.com/eyedeekay/goSam/replyParser.go index 4abffa7e..bc5b1332 100644 --- a/vendor/github.com/eyedeekay/goSam/replyParser.go +++ b/vendor/github.com/eyedeekay/goSam/replyParser.go @@ -63,7 +63,8 @@ func parseReply(line string) (*Reply, error) { } else { kvPair := strings.SplitN(v, "=", 2) if kvPair != nil { - if len(kvPair) != 2 { + if len(kvPair) == 1 { + } else if len(kvPair) != 2 { return nil, fmt.Errorf("Malformed key-value-pair.\n%s\n", kvPair) } } diff --git a/vendor/github.com/eyedeekay/sam3/i2pkeys/I2PAddr.go b/vendor/github.com/eyedeekay/sam3/i2pkeys/I2PAddr.go index 37ed2f53..e9f3bb48 100644 --- a/vendor/github.com/eyedeekay/sam3/i2pkeys/I2PAddr.go +++ b/vendor/github.com/eyedeekay/sam3/i2pkeys/I2PAddr.go @@ -7,6 +7,7 @@ import ( "encoding/base64" "errors" "io" + "os" "strings" ) @@ -31,6 +32,18 @@ func NewKeys(addr I2PAddr, both string) I2PKeys { return I2PKeys{addr, both} } +// fileExists checks if a file exists and is not a directory before we +// try using it to prevent further errors. +func fileExists(filename string) (bool, error) { + info, err := os.Stat(filename) + if os.IsNotExist(err) { + return false, nil + } else if err != nil { + return false, err + } + return !info.IsDir(), nil +} + // load keys from non standard format func LoadKeysIncompat(r io.Reader) (k I2PKeys, err error) { var buff bytes.Buffer @@ -42,12 +55,40 @@ func LoadKeysIncompat(r io.Reader) (k I2PKeys, err error) { return } +// load keys from non-standard format by specifying a text file. +// If the file does not exist, generate keys, otherwise, fail +// closed. +func LoadKeys(r string) (I2PKeys, error) { + exists, err := fileExists(r) + if err != nil { + return I2PKeys{}, err + } + if exists { + fi, err := os.Open(r) + if err != nil { + return I2PKeys{}, err + } + defer fi.Close() + return LoadKeysIncompat(fi) + } + return I2PKeys{}, err +} + // store keys in non standard format func StoreKeysIncompat(k I2PKeys, w io.Writer) (err error) { _, err = io.WriteString(w, k.Address.Base64()+"\n"+k.Both) return } +func StoreKeys(k I2PKeys, r string) error { + fi, err := os.Open(r) + if err != nil { + return err + } + defer fi.Close() + return StoreKeysIncompat(k, fi) +} + // Returns the public keys of the I2PKeys. func (k I2PKeys) Addr() I2PAddr { return k.Address @@ -160,11 +201,7 @@ func NewI2PAddrFromBytes(addr []byte) (I2PAddr, error) { // Turns an I2P address to a byte array. The inverse of NewI2PAddrFromBytes(). func (addr I2PAddr) ToBytes() ([]byte, error) { - buf := make([]byte, i2pB64enc.DecodedLen(len(addr))) - if _, err := i2pB64enc.Decode(buf, []byte(addr)); err != nil { - return buf, errors.New("Address is not base64-encoded") - } - return buf, nil + return i2pB64enc.DecodeString(string(addr)) } func (addr I2PAddr) Bytes() []byte { diff --git a/vendor/modules.txt b/vendor/modules.txt index 5880207b..3487ae6a 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -81,11 +81,10 @@ github.com/davecgh/go-spew/spew github.com/dsnet/compress/brotli github.com/dsnet/compress/internal github.com/dsnet/compress/internal/errors -# github.com/eyedeekay/goSam v0.32.28 +# github.com/eyedeekay/goSam v0.32.29 ## explicit github.com/eyedeekay/goSam -# github.com/eyedeekay/sam3 v0.32.3 -## explicit +# github.com/eyedeekay/sam3 v0.32.32-0.20201122050855-f464873c9350 github.com/eyedeekay/sam3/i2pkeys # github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51 ## explicit