Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Obfs4 stateDir handling #157

Merged
merged 2 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions application/transports/wrapping/obfs4/obfs4.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"net"
"os"

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

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

factory, err := t.ServerFactory(stateDir, &args)
factory, err := t.ServerFactory("", &args)
if err != nil {
return nil, nil, fmt.Errorf("failed to create server factory: %w", err)
}
Expand Down
42 changes: 40 additions & 2 deletions application/transports/wrapping/obfs4/obfs4_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"math/rand"
"net"
"os"
"path"
"testing"
"time"

Expand All @@ -18,6 +19,8 @@ import (

pt "git.torproject.org/pluggable-transports/goptlib.git"
"github.com/stretchr/testify/require"
"gitlab.com/yawning/obfs4.git/common/drbg"
"gitlab.com/yawning/obfs4.git/common/ntor"
"gitlab.com/yawning/obfs4.git/transports/obfs4"
)

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

wrappedc2p := make(chan net.Conn)
stateDir := t.TempDir()
stateDir := ""
go wrapConnection(c2p, reg.Keys.Obfs4Keys.NodeID.Hex(), reg.Keys.Obfs4Keys.PublicKey.Hex(), wrappedc2p, stateDir)

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

wrappedc2p := make(chan net.Conn)
stateDir := t.TempDir()
stateDir := ""
go wrapConnection(c2p, reg.Keys.Obfs4Keys.NodeID.Hex(), reg.Keys.Obfs4Keys.PublicKey.Hex(), wrappedc2p, stateDir)

var buf [4096]byte
Expand Down Expand Up @@ -239,3 +242,38 @@ func TestTryAgain(t *testing.T) {
t.Fatalf("expected ErrNotTransport, got %v", err)
}
}

func TestObfs4StateDir(t *testing.T) {
nodeID, _ := ntor.NewNodeID([]byte("\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13"))
serverKeypair, err := ntor.NewKeypair(true)
if err != nil {
t.Fatalf("server: ntor.NewKeypair failed: %s", err)
}

// We found the mark in the client handshake! We found our registration!
args := pt.Args{}
args.Add("node-id", nodeID.Hex())
args.Add("private-key", serverKeypair.Private().Hex())
seed, err := drbg.NewSeed()
require.Nil(t, err, "failed to create DRBG seed" )

args.Add("drbg-seed", seed.Hex())

obfs4Transport := &obfs4.Transport{}
server, err := obfs4Transport.ServerFactory("", &args)
require.Nil(t, err, "server factory failed")
require.NotNil(t, server)

require.NoFileExists(t, "./obfs4_state.json")
require.NoFileExists(t, "./obfs4_bridgeline.txt")


stateDir, err := os.MkdirTemp("", "")
require.Nil(t, err)
server, err = obfs4Transport.ServerFactory(stateDir, &args)
require.Nil(t, err, "server factory failed")
require.NotNil(t, server)

require.FileExists(t, path.Join(stateDir, "./obfs4_state.json"))
require.FileExists(t, path.Join(stateDir, "./obfs4_bridgeline.txt"))
}
7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@ require (
github.com/dchest/siphash v1.2.3 // indirect
github.com/go-redis/redis/v8 v8.11.4
github.com/gorilla/mux v1.8.0
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/golang-lru v0.5.4
github.com/mroth/weightedrand v0.4.1
github.com/pebbe/zmq4 v1.2.7
github.com/pelletier/go-toml v1.9.4
github.com/refraction-networking/gotapdance v1.3.1
github.com/refraction-networking/utls v1.1.0
github.com/sirupsen/logrus v1.9.0
github.com/stretchr/testify v1.7.1
gitlab.com/yawning/obfs4.git v0.0.0-20220204003609-77af0cba934d
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d
google.golang.org/grpc v1.41.0
google.golang.org/protobuf v1.28.0
)

// replace gitlab.com/yawning/obfs4.git => github.com/jmwample/obfs4.git v0.0.0-20230113193642-07b111e6b208

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