diff options
Diffstat (limited to 'modes')
-rw-r--r-- | modes/pt_socks5/pt_socks5.go | 59 | ||||
-rw-r--r-- | modes/stun_udp/stun_udp.go | 56 | ||||
-rw-r--r-- | modes/transparent_tcp/transparent_tcp.go | 62 | ||||
-rw-r--r-- | modes/transparent_udp/transparent_udp.go | 52 |
4 files changed, 75 insertions, 154 deletions
diff --git a/modes/pt_socks5/pt_socks5.go b/modes/pt_socks5/pt_socks5.go index 0a82971..067a036 100644 --- a/modes/pt_socks5/pt_socks5.go +++ b/modes/pt_socks5/pt_socks5.go @@ -40,8 +40,6 @@ import ( "github.com/OperatorFoundation/shapeshifter-dispatcher/common/socks5" "github.com/OperatorFoundation/shapeshifter-dispatcher/common/termmon" "github.com/OperatorFoundation/shapeshifter-ipc" - "github.com/OperatorFoundation/shapeshifter-transports/transports/base" - "github.com/OperatorFoundation/shapeshifter-transports/transports/meeklite" "github.com/OperatorFoundation/shapeshifter-transports/transports/obfs2" "github.com/OperatorFoundation/shapeshifter-transports/transports/obfs4" ) @@ -109,30 +107,20 @@ func clientHandler(target string, termMon *termmon.TermMonitor, name string, con } } - var transport base.Transport + var dialer func(address string) net.Conn // Deal with arguments. switch name { case "obfs2": - transport = obfs2.NewObfs2Transport() - case "meeklite": - if url, ok := args.Get("url"); ok { - if front, ok2 := args.Get("front"); ok2 { - transport = meeklite.NewMeekTransportWithFront(url, front) - } else { - transport = meeklite.NewMeekTransport(url) - } - } else { - log.Errorf("meeklite transport missing URL argument: %s", args) - socksReq.Reply(socks5.ReplyGeneralFailure) - return - } + transport := obfs2.NewObfs2Transport() + dialer = transport.Dial case "obfs4": if cert, ok := args.Get("cert"); ok { if iatModeStr, ok2 := args.Get("iatMode"); ok2 { iatMode, err := strconv.Atoi(iatModeStr) if err != nil { - transport = obfs4.NewObfs4Client(cert, iatMode) + transport := obfs4.NewObfs4Client(cert, iatMode) + dialer = transport.Dial } else { log.Errorf("obfs4 transport bad iatMode value: %s", iatModeStr) socksReq.Reply(socks5.ReplyGeneralFailure) @@ -170,7 +158,7 @@ func clientHandler(target string, termMon *termmon.TermMonitor, name string, con // // fmt.Println("Got dialer", dialFn, proxyURI, proxy.Direct) - f := transport.Dial + f := dialer remote := f(socksReq.Target) if err != nil { @@ -194,11 +182,11 @@ func clientHandler(target string, termMon *termmon.TermMonitor, name string, con return } -func ServerSetup(termMon *termmon.TermMonitor, bindaddrString string, ptServerInfo pt.ServerInfo, options string) (launched bool, listeners []base.TransportListener) { +func ServerSetup(termMon *termmon.TermMonitor, bindaddrString string, ptServerInfo pt.ServerInfo, options string) (launched bool, listeners []net.Listener) { for _, bindaddr := range ptServerInfo.Bindaddrs { name := bindaddr.MethodName - var transport base.Transport + var listen func(address string) net.Listener args, argsErr := pt.ParsePT2ClientParameters(options) if argsErr != nil { @@ -209,24 +197,15 @@ func ServerSetup(termMon *termmon.TermMonitor, bindaddrString string, ptServerIn // Deal with arguments. switch name { case "obfs2": - transport = obfs2.NewObfs2Transport() - case "meeklite": - if url, ok := args["url"]; ok { - if front, ok2 := args["front"]; ok2 { - transport = meeklite.NewMeekTransportWithFront(url[0], front[0]) - } else { - transport = meeklite.NewMeekTransport(url[0]) - } - } else { - log.Errorf("meeklite transport missing URL argument: %s", args) - return - } + transport := obfs2.NewObfs2Transport() + listen = transport.Listen case "obfs4": if cert, ok := args["cert"]; ok { if iatModeStr, ok2 := args["iatMode"]; ok2 { iatMode, err := strconv.Atoi(iatModeStr[0]) if err != nil { - transport = obfs4.NewObfs4Client(cert[0], iatMode) + transport := obfs4.NewObfs4Client(cert[0], iatMode) + listen = transport.Listen } else { log.Errorf("obfs4 transport bad iatMode value: %s", iatModeStr) return @@ -244,7 +223,7 @@ func ServerSetup(termMon *termmon.TermMonitor, bindaddrString string, ptServerIn return } - f := transport.Listen + f := listen transportLn := f(bindaddr.Addr.String()) @@ -266,10 +245,10 @@ func ServerSetup(termMon *termmon.TermMonitor, bindaddrString string, ptServerIn return } -func serverAcceptLoop(termMon *termmon.TermMonitor, name string, ln base.TransportListener, info *pt.ServerInfo) error { +func serverAcceptLoop(termMon *termmon.TermMonitor, name string, ln net.Listener, info *pt.ServerInfo) error { defer ln.Close() for { - conn, err := ln.TransportAccept() + conn, err := ln.Accept() if err != nil { if e, ok := err.(net.Error); ok && !e.Temporary() { return err @@ -280,16 +259,16 @@ func serverAcceptLoop(termMon *termmon.TermMonitor, name string, ln base.Transpo } } -func serverHandler(termMon *termmon.TermMonitor, name string, remote base.TransportConn, info *pt.ServerInfo) { - defer remote.NetworkConn().Close() +func serverHandler(termMon *termmon.TermMonitor, name string, remote net.Conn, info *pt.ServerInfo) { + defer remote.Close() termMon.OnHandlerStart() defer termMon.OnHandlerFinish() - addrStr := log.ElideAddr(remote.NetworkConn().RemoteAddr().String()) + addrStr := log.ElideAddr(remote.RemoteAddr().String()) log.Infof("%s(%s) - new connection", name, addrStr) // Connect to the orport. - orConn, err := pt.DialOr(info, remote.NetworkConn().RemoteAddr().String(), name) + orConn, err := pt.DialOr(info, remote.RemoteAddr().String(), name) if err != nil { log.Errorf("%s(%s) - failed to connect to ORPort: %s", name, addrStr, log.ElideError(err)) return diff --git a/modes/stun_udp/stun_udp.go b/modes/stun_udp/stun_udp.go index 535e9b9..e80526b 100644 --- a/modes/stun_udp/stun_udp.go +++ b/modes/stun_udp/stun_udp.go @@ -45,8 +45,6 @@ import ( "github.com/OperatorFoundation/shapeshifter-dispatcher/common/log" "github.com/OperatorFoundation/shapeshifter-dispatcher/common/termmon" "github.com/OperatorFoundation/shapeshifter-ipc" - "github.com/OperatorFoundation/shapeshifter-transports/transports/base" - "github.com/OperatorFoundation/shapeshifter-transports/transports/meeklite" "github.com/OperatorFoundation/shapeshifter-transports/transports/obfs2" "github.com/OperatorFoundation/shapeshifter-transports/transports/obfs4" ) @@ -164,35 +162,26 @@ func dialConn(tracker *ConnTracker, addr string, target string, name string, opt fmt.Println("Dialing....") - var transport base.Transport - args, argsErr := pt.ParsePT2ClientParameters(options) if argsErr != nil { log.Errorf("Error parsing transport options: %s", options) return } + var f func(address string) net.Conn + // Deal with arguments. switch name { case "obfs2": - transport = obfs2.NewObfs2Transport() - case "meeklite": - if url, ok := args["url"]; ok { - if front, ok2 := args["front"]; ok2 { - transport = meeklite.NewMeekTransportWithFront(url[0], front[0]) - } else { - transport = meeklite.NewMeekTransport(url[0]) - } - } else { - log.Errorf("meeklite transport missing URL argument: %s", args) - return - } + transport := obfs2.NewObfs2Transport() + f = transport.Dial case "obfs4": if cert, ok := args["cert"]; ok { if iatModeStr, ok2 := args["iatMode"]; ok2 { iatMode, err := strconv.Atoi(iatModeStr[0]) if err != nil { - transport = obfs4.NewObfs4Client(cert[0], iatMode) + transport := obfs4.NewObfs4Client(cert[0], iatMode) + f = transport.Dial } else { log.Errorf("obfs4 transport bad iatMode value: %s", iatModeStr) return @@ -210,8 +199,6 @@ func dialConn(tracker *ConnTracker, addr string, target string, name string, opt return } - f := transport.Dial - fmt.Println("Dialing ", target) remote := f(target) // if err != nil { @@ -227,7 +214,7 @@ func dialConn(tracker *ConnTracker, addr string, target string, name string, opt (*tracker)[addr] = ConnState{remote, false} } -func ServerSetup(termMon *termmon.TermMonitor, bindaddrString string, ptServerInfo pt.ServerInfo, options string) (launched bool, listeners []base.TransportListener) { +func ServerSetup(termMon *termmon.TermMonitor, bindaddrString string, ptServerInfo pt.ServerInfo, options string) (launched bool, listeners []net.Listener) { fmt.Println("ServerSetup") // Launch each of the server listeners. @@ -235,7 +222,7 @@ func ServerSetup(termMon *termmon.TermMonitor, bindaddrString string, ptServerIn name := bindaddr.MethodName fmt.Println("bindaddr", bindaddr) - var transport base.Transport + var listen func(address string) net.Listener args, argsErr := pt.ParsePT2ClientParameters(options) if argsErr != nil { @@ -246,24 +233,15 @@ func ServerSetup(termMon *termmon.TermMonitor, bindaddrString string, ptServerIn // Deal with arguments. switch name { case "obfs2": - transport = obfs2.NewObfs2Transport() - case "meeklite": - if url, ok := args["url"]; ok { - if front, ok2 := args["front"]; ok2 { - transport = meeklite.NewMeekTransportWithFront(url[0], front[0]) - } else { - transport = meeklite.NewMeekTransport(url[0]) - } - } else { - log.Errorf("meeklite transport missing URL argument: %s", args) - return - } + transport := obfs2.NewObfs2Transport() + listen=transport.Listen case "obfs4": if cert, ok := args["cert"]; ok { if iatModeStr, ok2 := args["iatMode"]; ok2 { iatMode, err := strconv.Atoi(iatModeStr[0]) if err != nil { - transport = obfs4.NewObfs4Client(cert[0], iatMode) + transport := obfs4.NewObfs4Client(cert[0], iatMode) + listen=transport.Listen } else { log.Errorf("obfs4 transport bad iatMode value: %s", iatModeStr) return @@ -281,9 +259,7 @@ func ServerSetup(termMon *termmon.TermMonitor, bindaddrString string, ptServerIn return } - f := transport.Listen - - transportLn := f(bindaddr.Addr.String()) + transportLn := listen(bindaddr.Addr.String()) go serverAcceptLoop(termMon, name, transportLn, &ptServerInfo) @@ -362,10 +338,10 @@ func parsePort(portStr string) (int, error) { return int(port), err } -func serverAcceptLoop(termMon *termmon.TermMonitor, name string, ln base.TransportListener, info *pt.ServerInfo) error { +func serverAcceptLoop(termMon *termmon.TermMonitor, name string, ln net.Listener, info *pt.ServerInfo) error { defer ln.Close() for { - conn, err := ln.TransportAccept() + conn, err := ln.Accept() fmt.Println("accepted") if err != nil { if e, ok := err.(net.Error); ok && !e.Temporary() { @@ -377,7 +353,7 @@ func serverAcceptLoop(termMon *termmon.TermMonitor, name string, ln base.Transpo } } -func serverHandler(termMon *termmon.TermMonitor, name string, remote base.TransportConn, info *pt.ServerInfo) { +func serverHandler(termMon *termmon.TermMonitor, name string, remote net.Conn, info *pt.ServerInfo) { var header *common.Message defer remote.Close() diff --git a/modes/transparent_tcp/transparent_tcp.go b/modes/transparent_tcp/transparent_tcp.go index 0e06869..f96f8d5 100644 --- a/modes/transparent_tcp/transparent_tcp.go +++ b/modes/transparent_tcp/transparent_tcp.go @@ -41,8 +41,6 @@ import ( "github.com/OperatorFoundation/shapeshifter-dispatcher/common/log" "github.com/OperatorFoundation/shapeshifter-dispatcher/common/termmon" "github.com/OperatorFoundation/shapeshifter-ipc" - "github.com/OperatorFoundation/shapeshifter-transports/transports/base" - "github.com/OperatorFoundation/shapeshifter-transports/transports/meeklite" "github.com/OperatorFoundation/shapeshifter-transports/transports/obfs2" "github.com/OperatorFoundation/shapeshifter-transports/transports/obfs4" "github.com/OperatorFoundation/shapeshifter-transports/transports/shadow" @@ -89,7 +87,7 @@ func clientHandler(target string, termMon *termmon.TermMonitor, name string, opt termMon.OnHandlerStart() defer termMon.OnHandlerFinish() - var transport base.Transport + var dialer func(address string) net.Conn args, argsErr := pt.ParsePT2ClientParameters(options) if argsErr != nil { @@ -100,24 +98,15 @@ func clientHandler(target string, termMon *termmon.TermMonitor, name string, opt // Deal with arguments. switch name { case "obfs2": - transport = obfs2.NewObfs2Transport() - case "meeklite": - if url, ok := args["url"]; ok { - if front, ok2 := args["front"]; ok2 { - transport = meeklite.NewMeekTransportWithFront(url[0], front[0]) - } else { - transport = meeklite.NewMeekTransport(url[0]) - } - } else { - log.Errorf("meeklite transport missing URL argument: %s", args) - return - } + transport := obfs2.NewObfs2Transport() + dialer = transport.Dial case "obfs4": if cert, ok := args["cert"]; ok { if iatModeStr, ok2 := args["iatMode"]; ok2 { iatMode, err := strconv.Atoi(iatModeStr[0]) if err == nil { - transport = obfs4.NewObfs4Client(cert[0], iatMode) + transport := obfs4.NewObfs4Client(cert[0], iatMode) + dialer = transport.Dial } else { log.Errorf("obfs4 transport bad iatMode value: %s %s", iatModeStr[0], err) return @@ -133,7 +122,8 @@ func clientHandler(target string, termMon *termmon.TermMonitor, name string, opt case "shadow": if password, ok := args["password"]; ok { if cipher, ok2 := args["cipherName"]; ok2 { - transport = shadow.NewShadowClient(password[0], cipher[0]) + transport := shadow.NewShadowClient(password[0], cipher[0]) + dialer = transport.Dial } else { log.Errorf("shadow transport missing cipher argument: %s", args) return @@ -147,7 +137,7 @@ func clientHandler(target string, termMon *termmon.TermMonitor, name string, opt return } - f := transport.Dial + f := dialer // Obtain the proxy dialer if any, and create the outgoing TCP connection. // dialFn := proxy.Direct.Dial @@ -184,12 +174,12 @@ func clientHandler(target string, termMon *termmon.TermMonitor, name string, opt return } -func ServerSetup(termMon *termmon.TermMonitor, bindaddrString string, ptServerInfo pt.ServerInfo, statedir string, options string) (launched bool, listeners []base.TransportListener) { +func ServerSetup(termMon *termmon.TermMonitor, bindaddrString string, ptServerInfo pt.ServerInfo, statedir string, options string) (launched bool, listeners []net.Listener) { // Launch each of the server listeners. for _, bindaddr := range ptServerInfo.Bindaddrs { name := bindaddr.MethodName - var transport base.Transport + var listen func(address string) net.Listener args, argsErr := pt.ParsePT2ServerParameters(options) if argsErr != nil { @@ -200,12 +190,11 @@ func ServerSetup(termMon *termmon.TermMonitor, bindaddrString string, ptServerIn // Deal with arguments. switch name { case "obfs2": - transport = obfs2.NewObfs2Transport() - case "meeklite": - log.Errorf("meeklite transport not supported on server") - return + transport := obfs2.NewObfs2Transport() + listen = transport.Listen case "obfs4": - transport = obfs4.NewObfs4Server(statedir) + transport := obfs4.NewObfs4Server(statedir) + listen = transport.Listen case "shadow": shargs, aok := args["shadow"] if !aok { @@ -222,13 +211,14 @@ func ServerSetup(termMon *termmon.TermMonitor, bindaddrString string, ptServerIn return false, nil } - transport = shadow.NewShadowServer(password, cipherName) + transport := shadow.NewShadowServer(password, cipherName) + listen = transport.Listen default: log.Errorf("Unknown transport: %s", name) return false, nil } - f := transport.Listen + f := listen transportLn := f(bindaddr.Addr.String()) @@ -268,10 +258,10 @@ func getServerBindaddrs(serverBindaddr string) ([]pt.Bindaddr, error) { return result, nil } -func serverAcceptLoop(termMon *termmon.TermMonitor, name string, ln base.TransportListener, info *pt.ServerInfo) error { +func serverAcceptLoop(termMon *termmon.TermMonitor, name string, ln net.Listener, info *pt.ServerInfo) error { defer ln.Close() for { - conn, err := ln.TransportAccept() + conn, err := ln.Accept() if err != nil { if e, ok := err.(net.Error); ok && !e.Temporary() { return err @@ -282,26 +272,22 @@ func serverAcceptLoop(termMon *termmon.TermMonitor, name string, ln base.Transpo } } -func serverHandler(termMon *termmon.TermMonitor, name string, remote base.TransportConn, info *pt.ServerInfo) { - defer remote.NetworkConn().Close() +func serverHandler(termMon *termmon.TermMonitor, name string, remote net.Conn, info *pt.ServerInfo) { termMon.OnHandlerStart() defer termMon.OnHandlerFinish() - addrStr := log.ElideAddr(remote.NetworkConn().RemoteAddr().String()) - log.Infof("%s(%s) - new connection", name, addrStr) - // Connect to the orport. - orConn, err := pt.DialOr(info, remote.NetworkConn().RemoteAddr().String(), name) + orConn, err := pt.DialOr(info, remote.RemoteAddr().String(), name) if err != nil { - log.Errorf("%s(%s) - failed to connect to ORPort: %s", name, addrStr, log.ElideError(err)) + log.Errorf("%s - failed to connect to ORPort: %s", name, log.ElideError(err)) return } defer orConn.Close() if err = copyLoop(orConn, remote); err != nil { - log.Warnf("%s(%s) - closed connection: %s", name, addrStr, log.ElideError(err)) + log.Warnf("%s - closed connection: %s", name, log.ElideError(err)) } else { - log.Infof("%s(%s) - closed connection", name, addrStr) + log.Infof("%s - closed connection", name) } return diff --git a/modes/transparent_udp/transparent_udp.go b/modes/transparent_udp/transparent_udp.go index 4be013a..9cceb82 100644 --- a/modes/transparent_udp/transparent_udp.go +++ b/modes/transparent_udp/transparent_udp.go @@ -43,8 +43,6 @@ import ( "github.com/OperatorFoundation/shapeshifter-dispatcher/common/log" "github.com/OperatorFoundation/shapeshifter-dispatcher/common/termmon" "github.com/OperatorFoundation/shapeshifter-ipc" - "github.com/OperatorFoundation/shapeshifter-transports/transports/base" - "github.com/OperatorFoundation/shapeshifter-transports/transports/meeklite" "github.com/OperatorFoundation/shapeshifter-transports/transports/obfs2" "github.com/OperatorFoundation/shapeshifter-transports/transports/obfs4" ) @@ -175,7 +173,7 @@ func dialConn(tracker *ConnTracker, addr string, target string, name string, opt fmt.Println("Dialing....") - var transport base.Transport + var dialer func(address string) net.Conn args, argsErr := pt.ParsePT2ClientParameters(options) if argsErr != nil { @@ -186,24 +184,15 @@ func dialConn(tracker *ConnTracker, addr string, target string, name string, opt // Deal with arguments. switch name { case "obfs2": - transport = obfs2.NewObfs2Transport() - case "meeklite": - if url, ok := args["url"]; ok { - if front, ok2 := args["front"]; ok2 { - transport = meeklite.NewMeekTransportWithFront(url[0], front[0]) - } else { - transport = meeklite.NewMeekTransport(url[0]) - } - } else { - log.Errorf("meeklite transport missing URL argument: %s", args) - return - } + transport := obfs2.NewObfs2Transport() + dialer = transport.Dial case "obfs4": if cert, ok := args["cert"]; ok { if iatModeStr, ok2 := args["iatMode"]; ok2 { iatMode, err := strconv.Atoi(iatModeStr[0]) if err != nil { - transport = obfs4.NewObfs4Client(cert[0], iatMode) + transport := obfs4.NewObfs4Client(cert[0], iatMode) + dialer = transport.Dial } else { log.Errorf("obfs4 transport bad iatMode value: %s", iatModeStr) return @@ -221,7 +210,7 @@ func dialConn(tracker *ConnTracker, addr string, target string, name string, opt return } - f := transport.Dial + f := dialer fmt.Println("Dialing ", target) remote := f(target) // if err != nil { @@ -237,7 +226,7 @@ func dialConn(tracker *ConnTracker, addr string, target string, name string, opt (*tracker)[addr] = ConnState{remote, false} } -func ServerSetup(termMon *termmon.TermMonitor, bindaddrString string, ptServerInfo pt.ServerInfo, options string) (launched bool, listeners []base.TransportListener) { +func ServerSetup(termMon *termmon.TermMonitor, bindaddrString string, ptServerInfo pt.ServerInfo, options string) (launched bool, listeners []net.Listener) { fmt.Println("ServerSetup") // Launch each of the server listeners. @@ -245,7 +234,7 @@ func ServerSetup(termMon *termmon.TermMonitor, bindaddrString string, ptServerIn name := bindaddr.MethodName fmt.Println("bindaddr", bindaddr) - var transport base.Transport + var listen func(address string) net.Listener args, argsErr := pt.ParsePT2ClientParameters(options) if argsErr != nil { @@ -256,24 +245,15 @@ func ServerSetup(termMon *termmon.TermMonitor, bindaddrString string, ptServerIn // Deal with arguments. switch name { case "obfs2": - transport = obfs2.NewObfs2Transport() - case "meeklite": - if url, ok := args["url"]; ok { - if front, ok2 := args["front"]; ok2 { - transport = meeklite.NewMeekTransportWithFront(url[0], front[0]) - } else { - transport = meeklite.NewMeekTransport(url[0]) - } - } else { - log.Errorf("meeklite transport missing URL argument: %s", args) - return - } + transport := obfs2.NewObfs2Transport() + listen = transport.Listen case "obfs4": if cert, ok := args["cert"]; ok { if iatModeStr, ok2 := args["iatMode"]; ok2 { iatMode, err := strconv.Atoi(iatModeStr[0]) if err != nil { - transport = obfs4.NewObfs4Client(cert[0], iatMode) + transport := obfs4.NewObfs4Client(cert[0], iatMode) + listen = transport.Listen } else { log.Errorf("obfs4 transport bad iatMode value: %s", iatModeStr) return @@ -291,7 +271,7 @@ func ServerSetup(termMon *termmon.TermMonitor, bindaddrString string, ptServerIn return } - f := transport.Listen + f := listen transportLn := f(bindaddr.Addr.String()) @@ -372,10 +352,10 @@ func parsePort(portStr string) (int, error) { return int(port), err } -func serverAcceptLoop(termMon *termmon.TermMonitor, name string, ln base.TransportListener, info *pt.ServerInfo) error { +func serverAcceptLoop(termMon *termmon.TermMonitor, name string, ln net.Listener, info *pt.ServerInfo) error { defer ln.Close() for { - conn, err := ln.TransportAccept() + conn, err := ln.Accept() fmt.Println("accepted") if err != nil { if e, ok := err.(net.Error); ok && !e.Temporary() { @@ -387,7 +367,7 @@ func serverAcceptLoop(termMon *termmon.TermMonitor, name string, ln base.Transpo } } -func serverHandler(termMon *termmon.TermMonitor, name string, remote base.TransportConn, info *pt.ServerInfo) { +func serverHandler(termMon *termmon.TermMonitor, name string, remote net.Conn, info *pt.ServerInfo) { var length16 uint16 defer remote.Close() |