From e0f4ef87d6a6ef5518a40468c868164708788170 Mon Sep 17 00:00:00 2001 From: Bluesaxorcist Date: Mon, 16 Sep 2019 18:58:22 -0500 Subject: fixed transports to use configs --- Examples/OptimizerConfig.json | 21 ++++ Examples/obfs4Config.json | 4 + Examples/shadowConfig.json | 4 + modes/transparent_tcp/transparent_tcp.go | 9 +- transports/transports.go | 164 +++++++++++++++++++++++++++---- 5 files changed, 182 insertions(+), 20 deletions(-) create mode 100644 Examples/OptimizerConfig.json create mode 100644 Examples/obfs4Config.json create mode 100644 Examples/shadowConfig.json diff --git a/Examples/OptimizerConfig.json b/Examples/OptimizerConfig.json new file mode 100644 index 0000000..2634491 --- /dev/null +++ b/Examples/OptimizerConfig.json @@ -0,0 +1,21 @@ +{ + "strategy": "first", + "transports": [ + { + "name": "shadow", + "address": "127.0.0.1:1234", + "config": { + "password": "orange", + "cipherName": "aes-128-ctr" + } + }, + { + "name": "obfs4", + "address": "77.81.104.251:443", + "config": { + "cert": "a1cc6eI5H+1kTzXhbuwMR9w3ZkLeZuReniier8DYSlAg4ed9yTbnyDiWc1vF1WFWKFRYHQ", + "iatMode": "0" + } + } + ] +} \ No newline at end of file diff --git a/Examples/obfs4Config.json b/Examples/obfs4Config.json new file mode 100644 index 0000000..4138172 --- /dev/null +++ b/Examples/obfs4Config.json @@ -0,0 +1,4 @@ +{ + "cert": "a1cc6eI5H+1kTzXhbuwMR9w3ZkLeZuReniier8DYSlAg4ed9yTbnyDiWc1vF1WFWKFRYHQ", + "iatMode": "0" +} \ No newline at end of file diff --git a/Examples/shadowConfig.json b/Examples/shadowConfig.json new file mode 100644 index 0000000..9a9862b --- /dev/null +++ b/Examples/shadowConfig.json @@ -0,0 +1,4 @@ +{ + "password": "orange", + "cipherName": "aes-128-ctr" +} \ No newline at end of file diff --git a/modes/transparent_tcp/transparent_tcp.go b/modes/transparent_tcp/transparent_tcp.go index 5535bd6..33534e7 100644 --- a/modes/transparent_tcp/transparent_tcp.go +++ b/modes/transparent_tcp/transparent_tcp.go @@ -33,6 +33,7 @@ import ( "fmt" options2 "github.com/OperatorFoundation/shapeshifter-dispatcher/common" "github.com/OperatorFoundation/shapeshifter-dispatcher/common/pt_extras" + "github.com/OperatorFoundation/shapeshifter-dispatcher/transports" "github.com/OperatorFoundation/shapeshifter-transports/transports/Dust" replicant "github.com/OperatorFoundation/shapeshifter-transports/transports/Replicant" "github.com/OperatorFoundation/shapeshifter-transports/transports/meeklite" @@ -174,11 +175,15 @@ func ServerSetup(termMon *termmon.TermMonitor, bindaddrString string, ptServerIn return false, nil } - _, ok := shargs.Get("config") + configString, ok := shargs.Get("config") if !ok { return false, nil } - transport := replicant.New(replicant.Config{}) + config, err := transports.ParseReplicantConfig(configString) + if err != nil { + return false, nil + } + transport := replicant.New(config) listen = transport.Listen case "Dust": shargs, aok := args["Dust"] diff --git a/transports/transports.go b/transports/transports.go index 14576f2..0d0f923 100644 --- a/transports/transports.go +++ b/transports/transports.go @@ -65,7 +65,7 @@ func ParseArgsObfs4(args map[string]interface{}, target string) (*obfs4.Transpor return nil, icerr } default: - return nil, errors.New("Unsupported type for obfs4 cert option") + return nil, errors.New("unsupported type for obfs4 cert option") } untypedIatMode, ok2 := args["iatMode"] @@ -89,7 +89,7 @@ func ParseArgsObfs4(args map[string]interface{}, target string) (*obfs4.Transpor case 1: iatMode = iatModeInt default: - return nil, errors.New("Unsupported value for obfs4 iatMode option") + return nil, errors.New("unsupported value for obfs4 iatMode option") } case float64: iatModeFloat, icerr := interconv.ParseFloat64(untypedIatMode) @@ -103,7 +103,7 @@ func ParseArgsObfs4(args map[string]interface{}, target string) (*obfs4.Transpor case 1: iatMode = iatModeInt default: - return nil, errors.New("Unsupported value for obfs4 iatMode option") + return nil, errors.New("unsupported value for obfs4 iatMode option") } case int: iatModeInt, icerr := interconv.ParseInt(untypedIatMode) @@ -116,7 +116,7 @@ func ParseArgsObfs4(args map[string]interface{}, target string) (*obfs4.Transpor case 1: iatMode = iatModeInt default: - return nil, errors.New("Unsupported value for obfs4 iatMode option") + return nil, errors.New("unsupported value for obfs4 iatMode option") } case bool: iatModeBool, icerr := interconv.ParseBoolean(untypedCert) @@ -130,7 +130,7 @@ func ParseArgsObfs4(args map[string]interface{}, target string) (*obfs4.Transpor iatMode = 0 } default: - return nil, errors.New("Unsupported type for obfs4 iatMode option") + return nil, errors.New("unsupported type for obfs4 iatMode option") } transport := obfs4.Transport{ @@ -252,12 +252,18 @@ func ParseArgsMeeklite(args map[string]interface{}, target string) (*meeklite.Tr } switch untypedUrl.(type) { - case gourl.URL: - var icerr error - url, icerr = interconv.ParseString(untypedUrl) + case string: + + urlString, icerr := interconv.ParseString(untypedUrl) if icerr != nil { return nil, icerr } + var parseErr error + url, parseErr = gourl.Parse(urlString) + if parseErr != nil { + return nil, errors.New("could not parse URL") + } + default: return nil, errors.New("unsupported type for meeklite url option") } @@ -287,9 +293,9 @@ func ParseArgsMeeklite(args map[string]interface{}, target string) (*meeklite.Tr return &transport, nil } -func ParseArgsOptimizer(args map[string]interface{}, target string) (*Optimizer.OptimizerTransport, error) { - var transports string - var strategy string +func ParseArgsOptimizer(args map[string]interface{}) (*Optimizer.OptimizerTransport, error) { + var transports []Optimizer.Transport + var strategy *Optimizer.Strategy untypedTransports, ok := args["transports"] if !ok { @@ -297,11 +303,13 @@ func ParseArgsOptimizer(args map[string]interface{}, target string) (*Optimizer. } switch untypedTransports.(type) { - case string: - var icerr error - transports, icerr = interconv.ParseString(untypedTransports) - if icerr != nil { - return nil, icerr + case []map[string]interface{}: + otcs := untypedTransports.([]map[string]interface{}) + + var parseErr error + transports, parseErr = parseTransports(otcs) + if parseErr != nil { + return nil, errors.New("could not parse transports") } default: return nil, errors.New("unsupported type for Optimizer transports option") @@ -314,11 +322,15 @@ func ParseArgsOptimizer(args map[string]interface{}, target string) (*Optimizer. switch untypedStrategy.(type) { case string: - var icerr error - strategy, icerr = interconv.ParseString(untypedStrategy) + strategyString, icerr := interconv.ParseString(untypedStrategy) if icerr != nil { return nil, icerr } + var parseErr error + strategy, parseErr = parseStrategy(strategyString, transports) + if parseErr != nil { + return nil, errors.New("could not parse strategy") + } default: return nil, errors.New("unsupported type for optimizer strategy option") } @@ -330,3 +342,119 @@ func ParseArgsOptimizer(args map[string]interface{}, target string) (*Optimizer. return &transport, nil } + +func parseStrategy(strategyString string, transports []Optimizer.Transport) (*Optimizer.Strategy, error) { + switch strategyString { + case "first": + strategy := Optimizer.NewFirstStrategy(transports) + return &strategy, nil + case "random": + strategy := Optimizer.NewRandomStrategy(transports) + return &strategy, nil + case "rotate": + strategy := Optimizer.NewRotateStrategy(transports) + return &strategy, nil + case "track": + return Optimizer.NewTrackStrategy(transports), nil + case "minimizeDialDuration": + return Optimizer.NewMinimizeDialDuration(transports), nil + + default: + return nil, errors.New("invalid strategy") + } +} + +func parseTransports(otcs []map[string]interface{}) ([]Optimizer.Transport, error) { + transports := make([]Optimizer.Transport, len(otcs)) + for index, otc := range otcs { + transport, err := parsedTransport(otc) + if err != nil { + return nil, errors.New("transport could not parse config") + //this error sucks and is uninformative + } + transports[index] = transport + } + return transports, nil +} + +func parsedTransport(otc map[string]interface{}) (Optimizer.Transport, error) { + var address string + var name string + var config map[string]interface{} +//start by parsing the address + untypedAddress, ok := otc["address"] + if !ok { + return nil, errors.New("missing address in transport parser") + } + + switch untypedAddress.(type) { + + case string: + var icerr error + address, icerr = interconv.ParseString(untypedAddress) + if icerr != nil { + return nil, icerr + } + + default: + return nil, errors.New("unsupported type for optimizer address option") + } + //now to parse the name + untypedName, ok2 := otc["name"] + if !ok2 { + return nil, errors.New("missing name in transport parser") + } + + switch untypedName.(type) { + + case string: + var icerr error + name, icerr = interconv.ParseString(untypedName) + if icerr != nil { + return nil, icerr + } + + default: + return nil, errors.New("unsupported type for optimizer name option") + } + //on to parsing the config + untypedConfig, ok3 := otc["config"] + if !ok3 { + return nil, errors.New("missing config in transport parser") + } + + switch untypedConfig.(type) { + + case map[string]interface{}: + config = untypedConfig.(map[string]interface{}) + + default: + return nil, errors.New("unsupported type for optimizer config option") + } + + switch name { + case "shadow": + shadowTransport, parseErr := ParseArgsShadow(config, address) + if parseErr!= nil { + return nil, errors.New("could not parse shadow Args") + } + return shadowTransport, nil + case "obfs4": + break + case "meeklite": + break + case "Dust": + break + case "replicant": + break + default: + return nil, errors.New("unsupported transport name") + } + + return nil, errors.New("unsupported transport name") +} + +func ParseReplicantConfig(config string) (replicant.Config, error) { + return replicant.Config{}, errors.New("function not implemented") + +} \ No newline at end of file -- cgit v1.2.3