Skip to content

Commit

Permalink
Added obfs4 unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
oxtoacart committed Mar 22, 2016
1 parent b91d79f commit 88d6b89
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 33 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ http-proxy.raw
test/data/http-proxy.raw

loader
obfs4_bridgeline.txt
obfs4_state.json

30 changes: 2 additions & 28 deletions http_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"net"
"net/http"
_ "net/http/pprof"
"os"
"strings"
"time"

Expand All @@ -31,8 +30,6 @@ import (
"github.com/getlantern/http-proxy-lantern/profilter"
"github.com/getlantern/http-proxy-lantern/redis"
"github.com/getlantern/http-proxy-lantern/tokenfilter"

"git.torproject.org/pluggable-transports/obfs4.git/common/drbg"
)

var (
Expand All @@ -59,11 +56,7 @@ var (
token = flag.String("token", "", "Lantern token")
tunnelPorts = flag.String("tunnelports", "", "Comma seperated list of ports allowed for HTTP CONNECT tunnel. Allow all ports if empty.")
obfs4Addr = flag.String("obfs4.addr", "", "Provide an address here in order to listen with obfs4")
obfs4NodeID = flag.String("obfs4.nodeid", "", "The obfs4 node ID, required if obfs4-addr is set")
obfs4PrivateKey = flag.String("obfs4.private-key", "", "The obfs4 privatey key, required if obfs4-addr is set")
obfs4PublicKey = flag.String("obfs4.public-key", "", "The obfs4 public key, required if obfs4-addr is set")
obfs4DRBGSeed = flag.String("obfs4.drbg-seed", "", "The obfs4 drbg-seed, defaults to a random value")
obfs4IATMode = flag.String("obfs4.iat-mode", "0", "The obfs4 IAT mode, defaults to 0")
obfs4Dir = flag.String("obfs4.dir", ".", "Directory where obfs4 can store its files")
)

func main() {
Expand Down Expand Up @@ -201,26 +194,7 @@ func main() {
}

if *obfs4Addr != "" {
if *obfs4NodeID == "" || *obfs4PrivateKey == "" || *obfs4PublicKey == "" {
flag.Usage()
os.Exit(1)
}
drbgSeed := *obfs4DRBGSeed
if drbgSeed == "" {
log.Debug("No DRBG seed provided, randomly generating one")
seed, err := drbg.NewSeed()
if err != nil {
log.Fatalf("Unable to generate random DRBG seed: %v", err)
}
drbgSeed = seed.Hex()
}
l, err := obfs4listener.NewListener(*obfs4Addr, "/tmp/obfs4", map[string][]string{
"node-id": []string{*obfs4NodeID},
"private-key": []string{*obfs4PrivateKey},
"public-key": []string{*obfs4PublicKey},
"drbg-seed": []string{drbgSeed},
"iat-mode": []string{*obfs4IATMode},
})
l, err := obfs4listener.NewListener(*obfs4Addr, *obfs4Dir)
if err != nil {
log.Fatalf("Unable to listen with obfs4: %v", err)
}
Expand Down
5 changes: 2 additions & 3 deletions obfs4listener/obfs4listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ import (
"git.torproject.org/pluggable-transports/obfs4.git/transports/base"
)

func NewListener(addr string, stateDir string, settings map[string][]string) (net.Listener, error) {
func NewListener(addr string, stateDir string) (net.Listener, error) {
err := os.MkdirAll(stateDir, 0700)
if err != nil {
return nil, fmt.Errorf("Unable to make statedir at %v: %v", stateDir, err)
}

tr := &obfs4.Transport{}
ptargs := pt.Args(settings)
sf, err := tr.ServerFactory(stateDir, &ptargs)
sf, err := tr.ServerFactory(stateDir, &pt.Args{})
if err != nil {
return nil, fmt.Errorf("Unable to create obfs4 server factory: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions obfs4listener/obfs4listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestRoundTrip(t *testing.T) {
}
defer os.RemoveAll(tmpDir)

l, err := NewListener("localhost:0", tmpDir, make(map[string][]string))
l, err := NewListener("localhost:0", tmpDir)
if !assert.NoError(t, err, "Unable to create listener") {
return
}
Expand All @@ -37,7 +37,7 @@ func TestRoundTrip(t *testing.T) {
b := []byte("Hi There")

tr := &obfs4.Transport{}
cf, err := tr.ClientFactory(tmpDir)
cf, err := tr.ClientFactory("")
if !assert.NoError(t, err, "Unable to create client factory") {
return
}
Expand Down

0 comments on commit 88d6b89

Please sign in to comment.