Skip to content

Commit

Permalink
implemented more v3 proposals
Browse files Browse the repository at this point in the history
  • Loading branch information
CryptoSax committed Jul 31, 2020
1 parent e523d48 commit 8d839fd
Show file tree
Hide file tree
Showing 25 changed files with 172 additions and 126 deletions.
21 changes: 14 additions & 7 deletions transports/Dust/v3/Dust.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,39 @@ import (
"github.com/kataras/golog"
"golang.org/x/net/proxy"
"net"
"os"
"time"

"github.com/OperatorFoundation/shapeshifter-ipc/v2"
"github.com/blanu/Dust/go/v2/interface"
)

func MakeLog() {
golog.SetLevel("debug")
golog.SetOutput(os.Stderr)
}

type dustClient struct {
serverPubkey *Dust.ServerPublic
dialer proxy.Dialer
Address string `json:"address"`
}

type dustServer struct {
serverPrivkey *Dust.ServerPrivate
dialer proxy.Dialer
}

func NewDustClient(serverPublic string, dialer proxy.Dialer) *dustClient {
func NewDustClient(serverPublic string, dialer proxy.Dialer, address string) *dustClient {
unparsed := make(map[string]string)
unparsed["p"]=serverPublic
unparsed["p"] = serverPublic

spub, err := Dust.ParseServerPublic(unparsed)
if err != nil {
return nil
}

return &dustClient{serverPubkey: spub, dialer: dialer}
return &dustClient{serverPubkey: spub, dialer: dialer, Address: address}
}

type dustTransportListener struct {
Expand All @@ -68,25 +75,24 @@ type Transport struct {
Address string
Dialer proxy.Dialer
ServerConfig *dustServer
Log *golog.Logger
}

type Config struct {
ServerPublic string `json:"server-public"`
Address string `json:"address"`
}

func New(serverPublic string, address string, dialer proxy.Dialer, serverConfig *dustServer, log *golog.Logger) Transport {
func New(serverPublic string, address string, dialer proxy.Dialer, serverConfig *dustServer) Transport {
return Transport{
ServerPublic: serverPublic,
Address: address,
Dialer: dialer,
ServerConfig: serverConfig,
Log: log,
}
}

func (transport Transport) Dial() (net.Conn, error) {
dustTransport := NewDustClient(transport.ServerPublic, transport.Dialer)
dustTransport := NewDustClient(transport.ServerPublic, transport.Dialer, transport.Address)
conn, err := dustTransport.Dial(transport.Address)
if err != nil {
return nil, err
Expand All @@ -110,6 +116,7 @@ func (transport Transport) Listen() (net.Listener, error) {

return newDustTransportListener(ln, transport.ServerConfig), nil
}

//end optimizer code

func newDustTransportListener(listener *net.TCPListener, transport *dustServer) *dustTransportListener {
Expand Down
11 changes: 7 additions & 4 deletions transports/Dust/v3/Dust_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@ package Dust

// Package Dust provides a PT 2.1 Go API wrapper around the Dust transport


import (
"github.com/kataras/golog"
"golang.org/x/net/proxy"
"testing"
)

const data = "test"

func TestDust(t *testing.T) {

MakeLog()
//create a server
serverConfig := dustServer{
serverPrivkey: nil,
dialer: nil,
}

clientConfig := dustClient{
serverPubkey: nil,
dialer: nil,
Expand Down Expand Up @@ -86,14 +87,16 @@ func TestDust(t *testing.T) {
}

func TestDustV3(t *testing.T) {

MakeLog()

//create a server
var log = golog.MustGetLogger("dust")
serverConfig := dustServer{
serverPrivkey: nil,
dialer: nil,
}

transport := New("", "127.0.0.1:1234", proxy.Direct, &serverConfig, log)
transport := New("", "127.0.0.1:1234", proxy.Direct, &serverConfig)
//call listen on the server
serverListener, listenErr := transport.Listen()
if listenErr != nil {
Expand Down
15 changes: 7 additions & 8 deletions transports/Optimizer/v3/Optimizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"github.com/OperatorFoundation/shapeshifter-transports/transports/obfs2/v3"
"github.com/OperatorFoundation/shapeshifter-transports/transports/obfs4/v3"
"github.com/OperatorFoundation/shapeshifter-transports/transports/shadow/v3"
"github.com/kataras/golog"
"golang.org/x/net/proxy"
"io/ioutil"
"net"
Expand Down Expand Up @@ -82,7 +81,7 @@ func TestShadowDial(t *testing.T) {
}

func TestOptimizerShadowDial(t *testing.T) {
shadowTransport := shadow.NewTransport("1234", "CHACHA20-IETF-POLY1305", "127.0.0.1:1235", &golog.Logger{})
shadowTransport := shadow.NewTransport("1234", "CHACHA20-IETF-POLY1305", "127.0.0.1:1235")
transports := []TransportDialer{&shadowTransport}
strategy := NewFirstStrategy(transports)
optimizerTransport := NewOptimizerClient(transports, strategy)
Expand All @@ -93,7 +92,7 @@ func TestOptimizerShadowDial(t *testing.T) {
}

func TestOptimizerObfs2Dial(t *testing.T) {
obfs2Transport := obfs2.New("127.0.0.1:1237", proxy.Direct, &golog.Logger{})
obfs2Transport := obfs2.New("127.0.0.1:1237", proxy.Direct)
transports := []TransportDialer{obfs2Transport}
strategy := NewFirstStrategy(transports)
optimizerTransport := NewOptimizerClient(transports, strategy)
Expand Down Expand Up @@ -148,7 +147,7 @@ func TestOptimizerTransportFirstDial(t *testing.T) {
IatMode: 0,
Address: "127.0.0.1:1234",
Dialer: dialer}
shadowTransport := shadow.NewTransport("1234", "CHACHA20-IETF-POLY1305", "127.0.0.1:1235", &golog.Logger{})
shadowTransport := shadow.NewTransport("1234", "CHACHA20-IETF-POLY1305", "127.0.0.1:1235")
transports := []TransportDialer{obfs4Transport, &shadowTransport}
strategy := NewFirstStrategy(transports)
optimizerTransport := NewOptimizerClient(transports, strategy)
Expand All @@ -173,7 +172,7 @@ func TestOptimizerTransportRandomDial(t *testing.T) {
Address: "127.0.0.1:1234",
Dialer: dialer,
}
shadowTransport := shadow.NewTransport("1234", "CHACHA20-IETF-POLY1305", "127.0.0.1:1235", &golog.Logger{})
shadowTransport := shadow.NewTransport("1234", "CHACHA20-IETF-POLY1305", "127.0.0.1:1235")
transports := []TransportDialer{obfs4Transport, &shadowTransport}
strategy := NewRandomStrategy(transports)
optimizerTransport := NewOptimizerClient(transports, strategy)
Expand All @@ -199,7 +198,7 @@ func TestOptimizerTransportRotateDial(t *testing.T) {
Address: "127.0.0.1:1234",
Dialer: dialer,
}
shadowTransport := shadow.NewTransport("1234", "CHACHA20-IETF-POLY1305", "127.0.0.1:1235", &golog.Logger{})
shadowTransport := shadow.NewTransport("1234", "CHACHA20-IETF-POLY1305", "127.0.0.1:1235")
transports := []TransportDialer{obfs4Transport, &shadowTransport}
strategy := NewRotateStrategy(transports)
optimizerTransport := NewOptimizerClient(transports, strategy)
Expand All @@ -225,7 +224,7 @@ func TestOptimizerTransportTrackDial(t *testing.T) {
Address: "127.0.0.1:1234",
Dialer: dialer,
}
shadowTransport := shadow.NewTransport("1234", "CHACHA20-IETF-POLY1305", "127.0.0.1:1235", &golog.Logger{})
shadowTransport := shadow.NewTransport("1234", "CHACHA20-IETF-POLY1305", "127.0.0.1:1235")
transports := []TransportDialer{obfs4Transport, &shadowTransport}
strategy := NewTrackStrategy(transports)
optimizerTransport := NewOptimizerClient(transports, strategy)
Expand All @@ -251,7 +250,7 @@ func TestOptimizerTransportMinimizeDialDurationDial(t *testing.T) {
Address: "127.0.0.1:1234",
Dialer: dialer,
}
shadowTransport := shadow.NewTransport("1234", "CHACHA20-IETF-POLY1305", "127.0.0.1:1235", &golog.Logger{})
shadowTransport := shadow.NewTransport("1234", "CHACHA20-IETF-POLY1305", "127.0.0.1:1235")
transports := []TransportDialer{obfs4Transport, &shadowTransport}
strategy := NewMinimizeDialDuration(transports)
optimizerTransport := NewOptimizerClient(transports, strategy)
Expand Down
1 change: 0 additions & 1 deletion transports/Replicant/v3/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ type ServerConfig struct {

type ClientJSONConfig struct {
Config string `json:"config"`
Address string `json:"address"`
}

type ServerJSONInnerConfig struct {
Expand Down
7 changes: 7 additions & 0 deletions transports/Replicant/v3/pt21.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,17 @@ package replicant

import (
pt "github.com/OperatorFoundation/shapeshifter-ipc/v2"
"github.com/kataras/golog"
"net"
"os"
"time"
)

func MakeLog() {
golog.SetLevel("debug")
golog.SetOutput(os.Stderr)
}

// Create outgoing transport connection
func (config ClientConfig) Dial(address string) (net.Conn, error) {
conn, dialErr := net.Dial("tcp", address)
Expand Down
11 changes: 5 additions & 6 deletions transports/Replicant/v3/replicant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"github.com/OperatorFoundation/monolith-go/monolith"
"github.com/OperatorFoundation/shapeshifter-transports/transports/Replicant/v3/polish"
"github.com/OperatorFoundation/shapeshifter-transports/transports/Replicant/v3/toneburst"
"github.com/kataras/golog"
"golang.org/x/net/proxy"
"io/ioutil"
"math/rand"
Expand Down Expand Up @@ -184,7 +183,7 @@ func runReplicantServer() {
}

func runReplicantFactoryServer() {
var log = golog.MustGetLogger("replicant")
MakeLog()
serverStarted := make(chan bool)
addr := "127.0.0.1:3001"

Expand All @@ -193,7 +192,7 @@ func runReplicantFactoryServer() {
Polish: nil,
}

server := NewServer(serverConfig, addr, proxy.Direct, log)
server := NewServer(serverConfig, addr, proxy.Direct)

go func() {
listener, listenError := server.Listen()
Expand Down Expand Up @@ -304,7 +303,7 @@ func replicantConnection(clientConfig ClientConfig, serverConfig ServerConfig, t

func replicantFactoryConnection(clientConfig ClientConfig, serverConfig ServerConfig, t *testing.T) {
serverStarted := make(chan bool)
var log = golog.MustGetLogger("replicant")
MakeLog()
// Get a random port
rand.Seed(time.Now().UnixNano())
min := 1025
Expand All @@ -315,7 +314,7 @@ func replicantFactoryConnection(clientConfig ClientConfig, serverConfig ServerCo
addr += portString

go func() {
server := NewServer(serverConfig, addr, proxy.Direct, log)
server := NewServer(serverConfig, addr, proxy.Direct)
listener, listenError := server.Listen()
if listenError != nil {
return
Expand Down Expand Up @@ -350,7 +349,7 @@ func replicantFactoryConnection(clientConfig ClientConfig, serverConfig ServerCo
t.Fail()
return
}
client := NewClient(clientConfig, addr, proxy.Direct, log)
client := NewClient(clientConfig, proxy.Direct)
cConn, connErr := client.Dial()
if connErr != nil {
t.Fail()
Expand Down
2 changes: 1 addition & 1 deletion transports/meeklite/v3/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module github.com/OperatorFoundation/shapeshifter-transports/transports/meeklite
go 1.12

require (

github.com/kataras/golog v0.0.18
golang.org/x/net v0.0.0-20200202094626-16171245cfb2
)
7 changes: 5 additions & 2 deletions transports/meeklite/v3/go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
h1:lDH9UUVJtmYCjyT0CI4q8xvlXPxeZ0gYCVvWbmPlp88=
/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk=
github.com/kataras/golog v0.0.18 h1:Td7hcKN25yzqB/0SO5iohOsMk5Mq5V9kDtM5apaJLY0=
github.com/kataras/golog v0.0.18/go.mod h1:jRYl7dFYqP8aQj9VkwdBUXYZSfUktm+YYg1arJILfyw=
github.com/kataras/pio v0.0.8 h1:6pX6nHJk7DAV3x1dEimibQF2CmJLlo0jWVmM9yE9KY8=
github.com/kataras/pio v0.0.8/go.mod h1:NFfMp2kVP1rmV4N6gH6qgWpuoDKlrOeYi3VrAIWCGsE=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2 h1:CCH4IOTTfewWjGOlSp+zGcjutRKlBEZQ6wTn8ozI/nI=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
58 changes: 32 additions & 26 deletions transports/meeklite/v3/meeklite.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import (
"net"
"net/http"
gourl "net/url"
"os"
"runtime"
"sync"
"time"
Expand All @@ -70,6 +71,11 @@ var (
loopbackAddr = net.IPv4(127, 0, 0, 1)
)

func MakeLog() {
golog.SetLevel("debug")
golog.SetOutput(os.Stderr)
}

// MeekTransport that uses domain fronting to shapeshift the application network traffic
type MeekTransport struct {
dialer proxy.Dialer
Expand Down Expand Up @@ -124,22 +130,22 @@ func (ca *meekClientArgs) Network() string {

//Transport contains parameters used in Optimizer
type Transport struct {
URL *gourl.URL `json:"url"`
Front string `json:"front"`
Address string
Dialer proxy.Dialer
log *golog.Logger
URL *gourl.URL
Front string
Dialer proxy.Dialer
}

//Config puts the parameters in a json compatible format
type Config struct {
URL *gourl.URL `json:"url"`
Front string `json:"front"`
URL *gourl.URL `json:"url"`
Front string `json:"front"`
Address string `json:"address"`
}

func NewMeekFactoryTransportWithFront(url *gourl.URL, front string, address string, dialer proxy.Dialer, log *golog.Logger) *Transport {
return &Transport{url, front, address,dialer, log}
func NewMeekFactoryTransportWithFront(url *gourl.URL, front string, dialer proxy.Dialer) *Transport {
return &Transport{url, front, dialer}
}

// Dial creates outgoing transport connection
func (transport Transport) Dial() (net.Conn, error) {
meekTransport := NewMeekTransportWithFront(transport.URL.String(), transport.Front, transport.Dialer)
Expand Down Expand Up @@ -239,23 +245,23 @@ func (transportConn *meekConn) Read(p []byte) (n int, err error) {
return
}
select {
case <-time.After(20*time.Second):
return 0, nil
// Wait for the worker to enqueue more incoming data.
case b, ok := <-transportConn.workerRdChan:
if !ok {
// Close() was called and the worker's shutting down.
return 0, io.ErrClosedPipe
}
case <-time.After(20 * time.Second):
return 0, nil
// Wait for the worker to enqueue more incoming data.
case b, ok := <-transportConn.workerRdChan:
if !ok {
// Close() was called and the worker's shutting down.
return 0, io.ErrClosedPipe
}

// Ew, an extra copy, but who am I kidding, it's meek.
buf := bytes.NewBuffer(b)
n, err = buf.Read(p)
if buf.Len() > 0 {
// If there's data pending, stash the buffer so the next
// Read() call will use it to fulfill the Read().
transportConn.rdBuf = buf
}
// Ew, an extra copy, but who am I kidding, it's meek.
buf := bytes.NewBuffer(b)
n, err = buf.Read(p)
if buf.Len() > 0 {
// If there's data pending, stash the buffer so the next
// Read() call will use it to fulfill the Read().
transportConn.rdBuf = buf
}
}
return
}
Expand Down Expand Up @@ -365,7 +371,7 @@ func (transportConn *meekConn) roundTrip(sndBuf []byte) (recvBuf []byte, err err
if resp.StatusCode == http.StatusInternalServerError {
return
}
time.Sleep(retryDelay)
time.Sleep(retryDelay)

} else {
_ = resp.Body.Close()
Expand Down
Loading

0 comments on commit 8d839fd

Please sign in to comment.