Skip to content

Commit 2d04ea1

Browse files
authored
obfs4 statedir fix with go.mod replace to fork for now (#157)
1 parent 5b4859a commit 2d04ea1

File tree

4 files changed

+48
-14
lines changed

4 files changed

+48
-14
lines changed

application/transports/wrapping/obfs4/obfs4.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"fmt"
66
"net"
7-
"os"
87

98
pt "git.torproject.org/pluggable-transports/goptlib.git"
109
dd "github.com/refraction-networking/conjure/application/lib"
@@ -49,12 +48,8 @@ func (Transport) WrapConnection(data *bytes.Buffer, c net.Conn, phantom net.IP,
4948
args.Add("drbg-seed", seed.Hex())
5049

5150
t := &obfs4.Transport{}
52-
stateDir, err := os.MkdirTemp("", "")
53-
if err != nil {
54-
return nil, nil, fmt.Errorf("failed to create tmp-dir for WrapConn")
55-
}
5651

57-
factory, err := t.ServerFactory(stateDir, &args)
52+
factory, err := t.ServerFactory("", &args)
5853
if err != nil {
5954
return nil, nil, fmt.Errorf("failed to create server factory: %w", err)
6055
}

application/transports/wrapping/obfs4/obfs4_test.go

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"math/rand"
99
"net"
1010
"os"
11+
"path"
1112
"testing"
1213
"time"
1314

@@ -18,6 +19,8 @@ import (
1819

1920
pt "git.torproject.org/pluggable-transports/goptlib.git"
2021
"github.com/stretchr/testify/require"
22+
"gitlab.com/yawning/obfs4.git/common/drbg"
23+
"gitlab.com/yawning/obfs4.git/common/ntor"
2124
"gitlab.com/yawning/obfs4.git/transports/obfs4"
2225
)
2326

@@ -62,7 +65,7 @@ func TestSuccessfulWrap(t *testing.T) {
6265
defer sfp.Close()
6366

6467
wrappedc2p := make(chan net.Conn)
65-
stateDir := t.TempDir()
68+
stateDir := ""
6669
go wrapConnection(c2p, reg.Keys.Obfs4Keys.NodeID.Hex(), reg.Keys.Obfs4Keys.PublicKey.Hex(), wrappedc2p, stateDir)
6770

6871
var buf [4096]byte
@@ -140,7 +143,7 @@ func TestSuccessfulWrapMulti(t *testing.T) {
140143
defer sfp.Close()
141144

142145
wrappedc2p := make(chan net.Conn)
143-
stateDir := t.TempDir()
146+
stateDir := ""
144147
go wrapConnection(c2p, reg.Keys.Obfs4Keys.NodeID.Hex(), reg.Keys.Obfs4Keys.PublicKey.Hex(), wrappedc2p, stateDir)
145148

146149
var buf [4096]byte
@@ -239,3 +242,38 @@ func TestTryAgain(t *testing.T) {
239242
t.Fatalf("expected ErrNotTransport, got %v", err)
240243
}
241244
}
245+
246+
func TestObfs4StateDir(t *testing.T) {
247+
nodeID, _ := ntor.NewNodeID([]byte("\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13"))
248+
serverKeypair, err := ntor.NewKeypair(true)
249+
if err != nil {
250+
t.Fatalf("server: ntor.NewKeypair failed: %s", err)
251+
}
252+
253+
// We found the mark in the client handshake! We found our registration!
254+
args := pt.Args{}
255+
args.Add("node-id", nodeID.Hex())
256+
args.Add("private-key", serverKeypair.Private().Hex())
257+
seed, err := drbg.NewSeed()
258+
require.Nil(t, err, "failed to create DRBG seed" )
259+
260+
args.Add("drbg-seed", seed.Hex())
261+
262+
obfs4Transport := &obfs4.Transport{}
263+
server, err := obfs4Transport.ServerFactory("", &args)
264+
require.Nil(t, err, "server factory failed")
265+
require.NotNil(t, server)
266+
267+
require.NoFileExists(t, "./obfs4_state.json")
268+
require.NoFileExists(t, "./obfs4_bridgeline.txt")
269+
270+
271+
stateDir, err := os.MkdirTemp("", "")
272+
require.Nil(t, err)
273+
server, err = obfs4Transport.ServerFactory(stateDir, &args)
274+
require.Nil(t, err, "server factory failed")
275+
require.NotNil(t, server)
276+
277+
require.FileExists(t, path.Join(stateDir, "./obfs4_state.json"))
278+
require.FileExists(t, path.Join(stateDir, "./obfs4_bridgeline.txt"))
279+
}

go.mod

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,19 @@ require (
99
github.com/dchest/siphash v1.2.3 // indirect
1010
github.com/go-redis/redis/v8 v8.11.4
1111
github.com/gorilla/mux v1.8.0
12-
github.com/hashicorp/golang-lru v0.5.4 // indirect
12+
github.com/hashicorp/golang-lru v0.5.4
1313
github.com/mroth/weightedrand v0.4.1
1414
github.com/pebbe/zmq4 v1.2.7
1515
github.com/pelletier/go-toml v1.9.4
1616
github.com/refraction-networking/gotapdance v1.3.1
17-
github.com/refraction-networking/utls v1.1.0
1817
github.com/sirupsen/logrus v1.9.0
1918
github.com/stretchr/testify v1.7.1
2019
gitlab.com/yawning/obfs4.git v0.0.0-20220204003609-77af0cba934d
2120
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d
2221
google.golang.org/grpc v1.41.0
2322
google.golang.org/protobuf v1.28.0
2423
)
24+
25+
// replace gitlab.com/yawning/obfs4.git => github.com/jmwample/obfs4.git v0.0.0-20230113193642-07b111e6b208
26+
27+
replace gitlab.com/yawning/obfs4.git => github.com/jmwample/obfs4 v0.0.0-20230113193642-07b111e6b208

go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+l
7575
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
7676
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
7777
github.com/jinzhu/copier v0.3.5/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg=
78+
github.com/jmwample/obfs4 v0.0.0-20230113193642-07b111e6b208 h1:6nxlCjgsYnjYafKVqvElKbFL+95Kgg5YWT/GuXUNoD8=
79+
github.com/jmwample/obfs4 v0.0.0-20230113193642-07b111e6b208/go.mod h1:9GcM8QNU9/wXtEEH2q8bVOnPI7FtIF6VVLzZ1l6Hgf8=
7880
github.com/keltia/proxy v0.9.3/go.mod h1:fLU4DmBPG0oh0md9fWggE2oG2m7Lchv3eim+GiO3pZY=
7981
github.com/keltia/ripe-atlas v0.0.0-20211221125000-f6eb808d5dc6/go.mod h1:zYa+dM8811qRhclezc/AKX9imyQwPjjSk2cH0xTgTag=
8082
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
@@ -112,8 +114,6 @@ github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:
112114
github.com/refraction-networking/gotapdance v1.3.1 h1:nccj5T6e10xdixUtuMGzkGhtbkcuHnNpJO12zenzeXo=
113115
github.com/refraction-networking/gotapdance v1.3.1/go.mod h1:8IRTeIDGY+2JbwCOB4IOpQA5LifvuI/dUKippcvhtYw=
114116
github.com/refraction-networking/utls v1.0.0/go.mod h1:tz9gX959MEFfFN5whTIocCLUG57WiILqtdVxI8c6Wj0=
115-
github.com/refraction-networking/utls v1.1.0 h1:dKXJwSqni/t5csYJ+aQcEgqB7AMWYi6EUc9u3bEmjX0=
116-
github.com/refraction-networking/utls v1.1.0/go.mod h1:tz9gX959MEFfFN5whTIocCLUG57WiILqtdVxI8c6Wj0=
117117
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
118118
github.com/sergeyfrolov/bsbuffer v0.0.0-20180903213811-94e85abb8507/go.mod h1:DbI1gxrXI2jRGw7XGEUZQOOMd6PsnKzRrCKabvvMrwM=
119119
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
@@ -129,8 +129,6 @@ github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijb
129129
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
130130
gitlab.com/yawning/edwards25519-extra.git v0.0.0-20211229043746-2f91fcc9fbdb h1:qRSZHsODmAP5qDvb3YsO7Qnf3TRiVbGxNG/WYnlM4/o=
131131
gitlab.com/yawning/edwards25519-extra.git v0.0.0-20211229043746-2f91fcc9fbdb/go.mod h1:gvdJuZuO/tPZyhEV8K3Hmoxv/DWud5L4qEQxfYjEUTo=
132-
gitlab.com/yawning/obfs4.git v0.0.0-20220204003609-77af0cba934d h1:tJ8F7ABaQ3p3wjxwXiWSktVDgjZEXkvaRawd2rIq5ws=
133-
gitlab.com/yawning/obfs4.git v0.0.0-20220204003609-77af0cba934d/go.mod h1:9GcM8QNU9/wXtEEH2q8bVOnPI7FtIF6VVLzZ1l6Hgf8=
134132
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
135133
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
136134
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=

0 commit comments

Comments
 (0)